UNPKG

1.57 kBJavaScriptView Raw
1import { mix, isFunction, isNil, isArray, valuesOfKey } from '@antv/util';
2var Base = /** @class */function () {
3 function Base(options) {
4 mix(this, options);
5 var _a = this,
6 scale = _a.scale,
7 field = _a.field,
8 data = _a.data;
9 if (!scale && data) {
10 var values = valuesOfKey(data, field);
11 this.scale = this.createScale({
12 values: values,
13 field: field
14 });
15 }
16 }
17 Base.prototype.createScale = function (_scaleConfig) {
18 return null;
19 };
20 // 数据映射方法
21 Base.prototype._mapping = function (value) {
22 return value;
23 };
24 Base.prototype.update = function (options) {
25 mix(this, options);
26 };
27 Base.prototype.setRange = function (range) {
28 this.range = range;
29 };
30 // 归一化,参数是原始数据,返回是归一化的数据
31 Base.prototype.normalize = function (value) {
32 var scale = this.scale;
33 if (isArray(value)) {
34 return value.map(function (v) {
35 return scale.scale(v);
36 });
37 }
38 return scale.scale(value);
39 };
40 // convert 参数是归一化的数据,返回定义域的值
41 Base.prototype.convert = function (value) {
42 return value;
43 };
44 // 等于 normalize + convert, 参数是原始数据,返回是定义域的值
45 Base.prototype.mapping = function (value, child) {
46 if (child === void 0) {
47 child = null;
48 }
49 var rst = isFunction(this.callback) ? this.callback(value, child) : null;
50 if (!isNil(rst)) {
51 return rst;
52 }
53 return this._mapping(value);
54 };
55 return Base;
56}();
57export default Base;
\No newline at end of file