UNPKG

2.53 kBJavaScriptView Raw
1import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3import _createClass from "@babel/runtime/helpers/esm/createClass";
4import _get from "@babel/runtime/helpers/esm/get";
5import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
6import _inherits from "@babel/runtime/helpers/esm/inherits";
7import _createSuper from "@babel/runtime/helpers/esm/createSuper";
8import { Linear as LinearScale } from '@antv/scale';
9import { isArray } from '@antv/util';
10import { interpolate } from '../deps/d3-interpolate/src';
11import Base from './base';
12
13var Linear = /*#__PURE__*/function (_Base) {
14 _inherits(Linear, _Base);
15
16 var _super = _createSuper(Linear);
17
18 function Linear(options) {
19 var _this;
20
21 _classCallCheck(this, Linear);
22
23 _this = _super.call(this, options);
24
25 _this._updateInterpolate();
26
27 return _this;
28 }
29
30 _createClass(Linear, [{
31 key: "createScale",
32 value: function createScale(scaleConfig) {
33 return new LinearScale(scaleConfig);
34 }
35 }, {
36 key: "_updateInterpolate",
37 value: function _updateInterpolate() {
38 var _this$range = _slicedToArray(this.range, 2),
39 min = _this$range[0],
40 max = _this$range[1];
41
42 this.interpolate = interpolate(min, max);
43 }
44 }, {
45 key: "update",
46 value: function update(options) {
47 _get(_getPrototypeOf(Linear.prototype), "update", this).call(this, options);
48
49 this._updateInterpolate();
50 }
51 }, {
52 key: "_mapping",
53 value: function _mapping(value) {
54 var scale = this.scale,
55 interpolate = this.interpolate;
56
57 if (isArray(value)) {
58 return value.map(function (v) {
59 return interpolate(scale.scale(v));
60 });
61 }
62
63 return interpolate(scale.scale(value));
64 }
65 }, {
66 key: "normalize",
67 value: function normalize(value) {
68 var scale = this.scale;
69
70 if (isArray(value)) {
71 return value.map(function (v) {
72 return scale.scale(v);
73 });
74 }
75
76 return scale.scale(value);
77 }
78 }, {
79 key: "convert",
80 value: function convert(value) {
81 var range = this.range;
82
83 var _range = _slicedToArray(range, 2),
84 min = _range[0],
85 max = _range[1];
86
87 if (isArray(value)) {
88 return value.map(function (v) {
89 return min + (max - min) * v;
90 });
91 }
92
93 return min + (max - min) * value;
94 }
95 }]);
96
97 return Linear;
98}(Base);
99
100export default Linear;
\No newline at end of file