pow.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { __extends } from "tslib";
  2. import { calBase } from '../util/math';
  3. import Continuous from './base';
  4. /**
  5. * Pow 度量,处理非均匀分布
  6. */
  7. var Pow = /** @class */ (function (_super) {
  8. __extends(Pow, _super);
  9. function Pow() {
  10. var _this = _super !== null && _super.apply(this, arguments) || this;
  11. _this.type = 'pow';
  12. return _this;
  13. }
  14. /**
  15. * @override
  16. */
  17. Pow.prototype.invert = function (value) {
  18. var percent = this.getInvertPercent(value);
  19. var exponent = this.exponent;
  20. var max = calBase(exponent, this.max);
  21. var min = calBase(exponent, this.min);
  22. var tmp = percent * (max - min) + min;
  23. var factor = tmp >= 0 ? 1 : -1;
  24. return Math.pow(tmp, exponent) * factor;
  25. };
  26. Pow.prototype.initCfg = function () {
  27. this.tickMethod = 'pow';
  28. this.exponent = 2;
  29. this.tickCount = 5;
  30. this.nice = true;
  31. };
  32. // 获取度量计算时,value占的定义域百分比
  33. Pow.prototype.getScalePercent = function (value) {
  34. var max = this.max;
  35. var min = this.min;
  36. if (max === min) {
  37. return 0;
  38. }
  39. var exponent = this.exponent;
  40. var percent = (calBase(exponent, value) - calBase(exponent, min)) / (calBase(exponent, max) - calBase(exponent, min));
  41. return percent;
  42. };
  43. return Pow;
  44. }(Continuous));
  45. export default Pow;
  46. //# sourceMappingURL=pow.js.map