NuclearDispersionSystem/ant-design-vue-jeecg/node_modules/@antv/scale/lib/pow.js
2023-09-14 14:47:11 +08:00

129 lines
2.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
/**
* @fileOverview 使用pow进行度量计算
* @author dxq613@gmail.com
*/
var Base = require('./base');
var Linear = require('./linear'); // 求以a为次幂结果为b的基数如 x^^a = b;求x
function calBase(a, b) {
var e = Math.E;
var value = Math.pow(e, Math.log(b) / a); // 使用换底公式求底
return value;
}
/**
* 度量的Pow计算
* @class Scale.Log
*/
var Pow = /*#__PURE__*/function (_Linear) {
_inheritsLoose(Pow, _Linear);
function Pow() {
return _Linear.apply(this, arguments) || this;
}
var _proto = Pow.prototype;
_proto._initDefaultCfg = function _initDefaultCfg() {
_Linear.prototype._initDefaultCfg.call(this);
this.type = 'pow';
/**
* @override
* pow 的坐标点的个数控制在10个以下
* @type {Number}
*/
this.tickCount = 10;
/**
* 进行pow计算的基数
* @type {Number}
*/
this.exponent = 2;
}
/**
* @override
*/
;
_proto.calculateTicks = function calculateTicks() {
var self = this;
var exponent = self.exponent;
var min;
var max = Math.ceil(calBase(exponent, self.max));
if (self.min >= 0) {
min = Math.floor(calBase(exponent, self.min));
} else {
min = 0;
}
if (min > max) {
var tmp = max;
max = min;
min = tmp;
}
var count = max - min;
var tickCount = self.tickCount;
var avg = Math.ceil(count / tickCount);
var ticks = [];
for (var i = min; i < max + avg; i = i + avg) {
ticks.push(Math.pow(i, exponent));
}
return ticks;
} // 获取度量计算时value占的定义域百分比
;
_proto._getScalePercent = function _getScalePercent(value) {
var max = this.max;
var min = this.min;
if (max === min) {
return 0;
}
var exponent = this.exponent;
var percent = (calBase(exponent, value) - calBase(exponent, min)) / (calBase(exponent, max) - calBase(exponent, min));
return percent;
}
/**
* @override
*/
;
_proto.scale = function scale(value) {
var percent = this._getScalePercent(value);
var rangeMin = this.rangeMin();
var rangeMax = this.rangeMax();
return rangeMin + percent * (rangeMax - rangeMin);
}
/**
* @override
*/
;
_proto.invert = function invert(value) {
var percent = (value - this.rangeMin()) / (this.rangeMax() - this.rangeMin());
var exponent = this.exponent;
var max = calBase(exponent, this.max);
var min = calBase(exponent, this.min);
var tmp = percent * (max - min) + min;
return Math.pow(tmp, exponent);
};
return Pow;
}(Linear);
Base.Pow = Pow;
module.exports = Pow;