NuclearDispersionSystem/ant-design-vue-jeecg/node_modules/@antv/scale/lib/base.js

195 lines
3.9 KiB
JavaScript
Raw Normal View History

2023-09-14 14:47:11 +08:00
var mix = require('@antv/util/lib/mix');
var each = require('@antv/util/lib/each');
var isObject = require('@antv/util/lib/type/is-object');
var isNil = require('@antv/util/lib/type/is-nil');
var Scale = /*#__PURE__*/function () {
var _proto = Scale.prototype;
_proto._initDefaultCfg = function _initDefaultCfg() {
this.type = 'base';
/**
* 格式化函数,输出文本或者tick时的格式化函数
* @type {Function}
*/
this.formatter = null;
/**
* 输出的值域
* @type {Array}
*/
this.range = [0, 1];
/**
* 度量的标记
* @type {Array}
*/
this.ticks = null;
/**
* 参与度量计算的值可选项
* @type {Array}
*/
this.values = [];
};
function Scale(cfg) {
this._initDefaultCfg();
mix(this, cfg);
this.init();
}
/**
* 度量初始化
* @protected
*/
_proto.init = function init() {}
/**
* 获取该度量的ticks,返回的是多个对象
* - text: tick 的文本
* - value: 对应的度量转换后的值
* <code>
* [
* {text: 0,value:0}
* {text: 1,value:0.2}
* {text: 2,value:0.4}
* {text: 3,value:0.6}
* {text: 4,value:0.8}
* {text: 5,value:1}
* ]
* </code>
* @param {Number} count 输出tick的个数的近似值默认是 10
* @return {Array} 返回 ticks 数组
*/
;
_proto.getTicks = function getTicks() {
var self = this;
var ticks = self.ticks;
var rst = [];
each(ticks, function (tick) {
var obj;
if (isObject(tick)) {
obj = tick;
} else {
obj = {
text: self.getText(tick),
tickValue: tick,
value: self.scale(tick)
};
}
rst.push(obj);
});
return rst;
}
/**
* 获取格式化后的文本
* @param {*} value 输入的数据
* @param {*} key 字段的 key
* @return {String} 格式化的文本
*/
;
_proto.getText = function getText(value, key) {
var formatter = this.formatter;
value = formatter ? formatter(value, key) : value;
if (isNil(value) || !value.toString) {
value = '';
}
return value.toString();
}
/**
* 输出的值域最小值
* @protected
* @return {Number} 返回最小的值
*/
;
_proto.rangeMin = function rangeMin() {
return this.range[0];
}
/**
* 输出的值域最大值
* @protected
* @return {Number} 返回最大的值
*/
;
_proto.rangeMax = function rangeMax() {
var range = this.range;
return range[range.length - 1];
}
/**
* 度量转换后的结果翻转回输入域
* @param {Number} value 需要翻转的数值
* @return {*} 度量的输入值
*/
;
_proto.invert = function invert(value) {
return value;
}
/**
* 将传入的值从非数值转换成数值格式如分类字符串时间字符串等
* @param {*} value 传入的值
* @return {Number} 转换的值
*/
;
_proto.translate = function translate(value) {
return value;
}
/**
* 进行度量转换
* @param {*} value 输入值
* @return {Number} 输出值在设定的输出值域之间默认[0,1]
*/
;
_proto.scale = function scale(value) {
return value;
}
/**
* 克隆一个新的scale,拥有跟当前scale相同的输入域输出域等
* @return {Scale} 克隆的度量
*/
;
_proto.clone = function clone() {
var self = this;
var constr = self.constructor;
var cfg = {};
each(self, function (v, k) {
cfg[k] = self[k];
});
return new constr(cfg);
}
/**
* 更改度量的属性信息
* @param {Object} info 属性信息
* @chainable
* @return {Scale} 返回自身的引用
*/
;
_proto.change = function change(info) {
this.ticks = null;
mix(this, info);
this.init();
return this;
};
return Scale;
}();
module.exports = Scale;