index.js 1.4 KB

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