UNPKG

1.34 kBJavaScriptView Raw
1import { __extends } from "tslib";
2import { isNumber } from '@antv/util';
3import Base from '../base';
4/**
5 * identity scale原则上是定义域和值域一致,scale/invert方法也是一致的
6 * 参考R的实现:https://github.com/r-lib/scales/blob/master/R/pal-identity.r
7 * 参考d3的实现(做了下转型):https://github.com/d3/d3-scale/blob/master/src/identity.js
8 */
9var Identity = /** @class */ (function (_super) {
10 __extends(Identity, _super);
11 function Identity() {
12 var _this = _super !== null && _super.apply(this, arguments) || this;
13 _this.type = 'identity';
14 _this.isIdentity = true;
15 return _this;
16 }
17 Identity.prototype.calculateTicks = function () {
18 return this.values;
19 };
20 Identity.prototype.scale = function (value) {
21 // 如果传入的值不等于 identity 的值,则直接返回,用于一维图时的 dodge
22 if (this.values[0] !== value && isNumber(value)) {
23 return value;
24 }
25 return this.range[0];
26 };
27 Identity.prototype.invert = function (value) {
28 var range = this.range;
29 if (value < range[0] || value > range[1]) {
30 return NaN;
31 }
32 return this.values[0];
33 };
34 return Identity;
35}(Base));
36export default Identity;
37//# sourceMappingURL=index.js.map
\No newline at end of file