@antv/f2
Version:
Charts for mobile visualization.
43 lines (42 loc) • 1.48 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _tslib = require("tslib");
var _util = require("@antv/util");
var _base = _interopRequireDefault(require("../base"));
/**
* identity scale原则上是定义域和值域一致,scale/invert方法也是一致的
* 参考R的实现:https://github.com/r-lib/scales/blob/master/R/pal-identity.r
* 参考d3的实现(做了下转型):https://github.com/d3/d3-scale/blob/master/src/identity.js
*/
var Identity = /** @class */function (_super) {
(0, _tslib.__extends)(Identity, _super);
function Identity() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.type = 'identity';
_this.isIdentity = true;
return _this;
}
Identity.prototype.calculateTicks = function () {
return this.values;
};
Identity.prototype.scale = function (value) {
// 如果传入的值不等于 identity 的值,则直接返回,用于一维图时的 dodge
if (this.values[0] !== value && (0, _util.isNumber)(value)) {
return value;
}
return this.range[0];
};
Identity.prototype.invert = function (value) {
var range = this.range;
if (value < range[0] || value > range[1]) {
return NaN;
}
return this.values[0];
};
return Identity;
}(_base.default);
var _default = exports.default = Identity;
;