@antv/f2
Version:
Charts for mobile visualization.
66 lines • 1.9 kB
JavaScript
import { __extends } from "tslib";
import { Linear as LinearScale } from '../deps/f2-scale/src';
import { isArray, isNumber } from '@antv/util';
import { interpolateNumber, interpolateRgb } from '../deps/d3-interpolate/src';
import Base from './base';
// 只处理 number 和 color
var interpolate = function interpolate(a, b) {
if (isNumber(b)) {
return interpolateNumber(a, b);
}
return interpolateRgb(a, b);
};
var Linear = /** @class */function (_super) {
__extends(Linear, _super);
function Linear(options) {
var _this = _super.call(this, options) || this;
_this._updateInterpolate();
return _this;
}
Linear.prototype.createScale = function (scaleConfig) {
return new LinearScale(scaleConfig);
};
Linear.prototype._updateInterpolate = function () {
var _a = this.range,
min = _a[0],
max = _a[1];
this.interpolate = interpolate(min, max);
};
Linear.prototype.update = function (options) {
_super.prototype.update.call(this, options);
this._updateInterpolate();
};
Linear.prototype._mapping = function (value) {
var _a = this,
scale = _a.scale,
interpolate = _a.interpolate;
if (isArray(value)) {
return value.map(function (v) {
return interpolate(scale.scale(v));
});
}
return interpolate(scale.scale(value));
};
Linear.prototype.normalize = function (value) {
var scale = this.scale;
if (isArray(value)) {
return value.map(function (v) {
return scale.scale(v);
});
}
return scale.scale(value);
};
Linear.prototype.convert = function (value) {
var range = this.range;
var min = range[0],
max = range[1];
if (isArray(value)) {
return value.map(function (v) {
return min + (max - min) * v;
});
}
return min + (max - min) * value;
};
return Linear;
}(Base);
export default Linear;