| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.default = sequentialQuantile;
|
|---|
| 7 | var _index = require("../../../lib-vendor/d3-array/src/index.js");
|
|---|
| 8 | var _continuous = require("./continuous.js");
|
|---|
| 9 | var _init = require("./init.js");
|
|---|
| 10 | function sequentialQuantile() {
|
|---|
| 11 | var domain = [],
|
|---|
| 12 | interpolator = _continuous.identity;
|
|---|
| 13 | function scale(x) {
|
|---|
| 14 | if (x != null && !isNaN(x = +x)) return interpolator(((0, _index.bisect)(domain, x, 1) - 1) / (domain.length - 1));
|
|---|
| 15 | }
|
|---|
| 16 | scale.domain = function (_) {
|
|---|
| 17 | if (!arguments.length) return domain.slice();
|
|---|
| 18 | domain = [];
|
|---|
| 19 | for (let d of _) if (d != null && !isNaN(d = +d)) domain.push(d);
|
|---|
| 20 | domain.sort(_index.ascending);
|
|---|
| 21 | return scale;
|
|---|
| 22 | };
|
|---|
| 23 | scale.interpolator = function (_) {
|
|---|
| 24 | return arguments.length ? (interpolator = _, scale) : interpolator;
|
|---|
| 25 | };
|
|---|
| 26 | scale.range = function () {
|
|---|
| 27 | return domain.map((d, i) => interpolator(i / (domain.length - 1)));
|
|---|
| 28 | };
|
|---|
| 29 | scale.quantiles = function (n) {
|
|---|
| 30 | return Array.from({
|
|---|
| 31 | length: n + 1
|
|---|
| 32 | }, (_, i) => (0, _index.quantile)(domain, i / n));
|
|---|
| 33 | };
|
|---|
| 34 | scale.copy = function () {
|
|---|
| 35 | return sequentialQuantile(interpolator).domain(domain);
|
|---|
| 36 | };
|
|---|
| 37 | return _init.initInterpolator.apply(scale, arguments);
|
|---|
| 38 | } |
|---|