UNPKG

1.46 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.interpolatize = void 0;
4const util_1 = require("@antv/util");
5const compose_1 = require("./compose");
6const createInterpolatorRound = (interpolator) => {
7 return (t) => {
8 // If result is not number, it can't be rounded.
9 const res = interpolator(t);
10 return (0, util_1.isNumber)(res) ? Math.round(res) : res;
11 };
12};
13function interpolatize(rangeOf, normalizeDomain) {
14 return (Scale) => {
15 Scale.prototype.rescale = function () {
16 this.initRange();
17 this.nice();
18 const [transform] = this.chooseTransforms();
19 this.composeOutput(transform, this.chooseClamp(transform));
20 };
21 Scale.prototype.initRange = function () {
22 const { interpolator } = this.options;
23 this.options.range = rangeOf(interpolator);
24 };
25 Scale.prototype.composeOutput = function (transform, clamp) {
26 const { domain, interpolator, round } = this.getOptions();
27 const normalize = normalizeDomain(domain.map(transform));
28 const interpolate = round ? createInterpolatorRound(interpolator) : interpolator;
29 this.output = (0, compose_1.compose)(interpolate, normalize, clamp, transform);
30 };
31 Scale.prototype.invert = undefined;
32 };
33}
34exports.interpolatize = interpolatize;
35//# sourceMappingURL=interpolatize.js.map
\No newline at end of file