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

902 lines
20 KiB
Java

(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["attr"] = factory();
else
root["attr"] = factory();
})(typeof self !== 'undefined' ? self : this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 7);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
/**
* @fileOverview the Attribute base class
*/
var isString = __webpack_require__(4);
var isArray = __webpack_require__(1);
var isNil = __webpack_require__(5);
var mix = __webpack_require__(10);
var each = __webpack_require__(3);
function toScaleString(scale, value) {
if (isString(value)) {
return value;
}
return scale.invert(scale.scale(value));
}
/**
* 所有视觉通道属性的基类
* @class Attr
*/
var AttributeBase =
/*#__PURE__*/
function () {
function AttributeBase(cfg) {
var _this = this;
/**
* 属性的类型
* @type {String}
*/
this.type = 'base';
/**
* 属性的名称
* @type {String}
*/
this.name = null;
/**
* 回调函数
* @type {Function}
*/
this.method = null;
/**
* 备选的值数组
* @type {Array}
*/
this.values = [];
/**
* 属性内部的度量
* @type {Array}
*/
this.scales = [];
/**
* 是否通过线性取值, 如果未指定,则根据数值的类型判定
* @type {Boolean}
*/
this.linear = null;
/**
* 当用户设置的 callback 返回 null 时, 应该返回默认 callback 中的值
*/
var mixedCallback = null;
var defaultCallback = this.callback;
if (cfg.callback) {
var userCallback = cfg.callback;
mixedCallback = function mixedCallback() {
for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
params[_key] = arguments[_key];
}
var ret = userCallback.apply(void 0, params);
if (isNil(ret)) {
ret = defaultCallback.apply(_this, params);
}
return ret;
};
}
mix(this, cfg);
if (mixedCallback) {
mix(this, {
callback: mixedCallback
});
}
} // 获取属性值,将值映射到视觉通道
var _proto = AttributeBase.prototype;
_proto._getAttrValue = function _getAttrValue(scale, value) {
var values = this.values;
if (scale.isCategory && !this.linear) {
var index = scale.translate(value);
return values[index % values.length];
}
var percent = scale.scale(value);
return this.getLinearValue(percent);
};
/**
* 如果进行线性映射,返回对应的映射值
* @protected
* @param {Number} percent 百分比
* @return {*} 颜色值、形状、大小等
*/
_proto.getLinearValue = function getLinearValue(percent) {
var values = this.values;
var steps = values.length - 1;
var step = Math.floor(steps * percent);
var leftPercent = steps * percent - step;
var start = values[step];
var end = step === steps ? start : values[step + 1];
var rstValue = start + (end - start) * leftPercent;
return rstValue;
};
/**
* 默认的回调函数
* @param {*} value 回调函数的值
* @type {Function}
* @return {Array} 返回映射后的值
*/
_proto.callback = function callback(value) {
var self = this;
var scale = self.scales[0];
var rstValue = null;
if (scale.type === 'identity') {
rstValue = scale.value;
} else {
rstValue = self._getAttrValue(scale, value);
}
return rstValue;
};
/**
* 根据度量获取属性名
* @return {Array} dims of this Attribute
*/
_proto.getNames = function getNames() {
var scales = this.scales;
var names = this.names;
var length = Math.min(scales.length, names.length);
var rst = [];
for (var i = 0; i < length; i++) {
rst.push(names[i]);
}
return rst;
};
/**
* 根据度量获取维度名
* @return {Array} dims of this Attribute
*/
_proto.getFields = function getFields() {
var scales = this.scales;
var rst = [];
each(scales, function (scale) {
rst.push(scale.field);
});
return rst;
};
/**
* 根据名称获取度量
* @param {String} name the name of scale
* @return {Scale} scale
*/
_proto.getScale = function getScale(name) {
var scales = this.scales;
var names = this.names;
var index = names.indexOf(name);
return scales[index];
};
/**
* 映射数据
* @param {*} param1...paramn 多个数值
* @return {Array} 映射的值组成的数组
*/
_proto.mapping = function mapping() {
var scales = this.scales;
var callback = this.callback;
for (var _len2 = arguments.length, params = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
params[_key2] = arguments[_key2];
}
var values = params;
if (callback) {
for (var i = 0, len = params.length; i < len; i++) {
params[i] = this._toOriginParam(params[i], scales[i]);
}
values = callback.apply(this, params);
}
values = [].concat(values);
return values;
}; // 原始的参数
_proto._toOriginParam = function _toOriginParam(param, scale) {
var rst = param;
if (!scale.isLinear) {
if (isArray(param)) {
rst = [];
for (var i = 0, len = param.length; i < len; i++) {
rst.push(toScaleString(scale, param[i]));
}
} else {
rst = toScaleString(scale, param);
}
}
return rst;
};
return AttributeBase;
}();
module.exports = AttributeBase;
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
var isType = __webpack_require__(2);
var isArray = Array.isArray ? Array.isArray : function (value) {
return isType(value, 'Array');
};
module.exports = isArray;
/***/ }),
/* 2 */
/***/ (function(module, exports) {
var toString = {}.toString;
var isType = function isType(value, type) {
return toString.call(value) === '[object ' + type + ']';
};
module.exports = isType;
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
var isObject = __webpack_require__(9);
var isArray = __webpack_require__(1);
var each = function each(elements, func) {
if (!elements) {
return;
}
var rst = void 0;
if (isArray(elements)) {
for (var i = 0, len = elements.length; i < len; i++) {
rst = func(elements[i], i);
if (rst === false) {
break;
}
}
} else if (isObject(elements)) {
for (var k in elements) {
if (elements.hasOwnProperty(k)) {
rst = func(elements[k], k);
if (rst === false) {
break;
}
}
}
}
};
module.exports = each;
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
var isType = __webpack_require__(2);
var isString = function isString(str) {
return isType(str, 'String');
};
module.exports = isString;
/***/ }),
/* 5 */
/***/ (function(module, exports) {
// isFinite,
var isNil = function isNil(value) {
/**
* isNil(null) => true
* isNil() => true
*/
return value === null || value === undefined;
};
module.exports = isNil;
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
/**
* @fileOverview 颜色计算的辅助方法
* @author dxq613@gmail.com
*/
var isNumber = __webpack_require__(12);
var isString = __webpack_require__(4);
var each = __webpack_require__(3); // const RGB_REG = /rgb\((\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/;
var RGB_REG = /rgba?\(([\s.,0-9]+)\)/; // 创建辅助 tag 取颜色
function createTmp() {
var i = document.createElement('i');
i.title = 'Web Colour Picker';
i.style.display = 'none';
document.body.appendChild(i);
return i;
} // 获取颜色之间的插值
function getValue(start, end, percent, index) {
var value = start[index] + (end[index] - start[index]) * percent;
return value;
} // 数组转换成颜色
function arr2rgb(arr) {
return '#' + toHex(arr[0]) + toHex(arr[1]) + toHex(arr[2]);
} // 将数值从 0-255 转换成16进制字符串
function toHex(value) {
value = Math.round(value);
value = value.toString(16);
if (value.length === 1) {
value = '0' + value;
}
return value;
}
function calColor(colors, percent) {
if (isNaN(percent) || !isNumber(percent) || percent < 0) {
percent = 0;
}
if (percent > 1) {
percent = 1;
}
var steps = colors.length - 1;
var step = Math.floor(steps * percent);
var left = steps * percent - step;
var start = colors[step];
var end = step === steps ? start : colors[step + 1];
var rgb = arr2rgb([getValue(start, end, left, 0), getValue(start, end, left, 1), getValue(start, end, left, 2)]);
return rgb;
} // rgb 颜色转换成数组
function rgb2arr(str) {
var arr = [];
arr.push(parseInt(str.substr(1, 2), 16));
arr.push(parseInt(str.substr(3, 2), 16));
arr.push(parseInt(str.substr(5, 2), 16));
return arr;
}
var colorCache = {};
var iEl = null;
var ColorUtil = {
/**
* 将颜色转换到 rgb 的格式
* @param {String} color 颜色
* @return {String} 将颜色转换到 '#ffffff' 的格式
*/
toRGB: function toRGB(color) {
// 如果已经是 rgb的格式
if (color[0] === '#' && color.length === 7) {
return color;
}
if (!iEl) {
// 防止防止在页头报错
iEl = createTmp();
}
var rst;
if (colorCache[color]) {
rst = colorCache[color];
} else {
iEl.style.color = color;
rst = document.defaultView.getComputedStyle(iEl, '').getPropertyValue('color');
var matchs = RGB_REG.exec(rst);
var cArray = matchs[1].split(/\s*,\s*/);
rst = arr2rgb(cArray);
colorCache[color] = rst;
}
return rst;
},
rgb2arr: rgb2arr,
/**
* 获取渐变函数
* @param {Array} colors 多个颜色
* @return {String} 颜色值
*/
gradient: function gradient(colors) {
var points = [];
if (isString(colors)) {
colors = colors.split('-');
}
each(colors, function (color) {
if (color.indexOf('#') === -1) {
color = ColorUtil.toRGB(color);
}
points.push(rgb2arr(color));
});
return function (percent) {
return calColor(points, percent);
};
}
};
module.exports = ColorUtil;
/***/ }),
/* 7 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = {
Position: __webpack_require__(8),
Color: __webpack_require__(11),
Shape: __webpack_require__(13),
Size: __webpack_require__(14),
Opacity: __webpack_require__(15),
ColorUtil: __webpack_require__(6)
};
/***/ }),
/* 8 */
/***/ (function(module, exports, __webpack_require__) {
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
var isNil = __webpack_require__(5);
var isArray = __webpack_require__(1);
var each = __webpack_require__(3);
var Base = __webpack_require__(0);
var Position =
/*#__PURE__*/
function (_Base) {
_inheritsLoose(Position, _Base);
function Position(cfg) {
var _this;
_this = _Base.call(this, cfg) || this;
_this.names = ['x', 'y'];
_this.type = 'position';
return _this;
}
var _proto = Position.prototype;
_proto.mapping = function mapping(x, y) {
var scales = this.scales;
var coord = this.coord;
var scaleX = scales[0];
var scaleY = scales[1];
var rstX;
var rstY;
var obj;
if (isNil(x) || isNil(y)) {
return [];
}
if (isArray(y) && isArray(x)) {
rstX = [];
rstY = [];
for (var i = 0, j = 0, xLen = x.length, yLen = y.length; i < xLen && j < yLen; i++, j++) {
obj = coord.convertPoint({
x: scaleX.scale(x[i]),
y: scaleY.scale(y[j])
});
rstX.push(obj.x);
rstY.push(obj.y);
}
} else if (isArray(y)) {
x = scaleX.scale(x);
rstY = [];
each(y, function (yVal) {
yVal = scaleY.scale(yVal);
obj = coord.convertPoint({
x: x,
y: yVal
});
if (rstX && rstX !== obj.x) {
if (!isArray(rstX)) {
rstX = [rstX];
}
rstX.push(obj.x);
} else {
rstX = obj.x;
}
rstY.push(obj.y);
});
} else if (isArray(x)) {
y = scaleY.scale(y);
rstX = [];
each(x, function (xVal) {
xVal = scaleX.scale(xVal);
obj = coord.convertPoint({
x: xVal,
y: y
});
if (rstY && rstY !== obj.y) {
if (!isArray(rstY)) {
rstY = [rstY];
}
rstY.push(obj.y);
} else {
rstY = obj.y;
}
rstX.push(obj.x);
});
} else {
x = scaleX.scale(x);
y = scaleY.scale(y);
var point = coord.convertPoint({
x: x,
y: y
});
rstX = point.x;
rstY = point.y;
}
return [rstX, rstY];
};
return Position;
}(Base);
module.exports = Position;
/***/ }),
/* 9 */
/***/ (function(module, exports) {
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
var isObject = function isObject(value) {
/**
* isObject({}) => true
* isObject([1, 2, 3]) => true
* isObject(Function) => true
* isObject(null) => false
*/
var type = typeof value === 'undefined' ? 'undefined' : _typeof(value);
return value !== null && type === 'object' || type === 'function';
};
module.exports = isObject;
/***/ }),
/* 10 */
/***/ (function(module, exports) {
function _mix(dist, obj) {
for (var key in obj) {
if (obj.hasOwnProperty(key) && key !== 'constructor' && obj[key] !== undefined) {
dist[key] = obj[key];
}
}
}
var mix = function mix(dist, src1, src2, src3) {
if (src1) _mix(dist, src1);
if (src2) _mix(dist, src2);
if (src3) _mix(dist, src3);
return dist;
};
module.exports = mix;
/***/ }),
/* 11 */
/***/ (function(module, exports, __webpack_require__) {
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
var isString = __webpack_require__(4);
var ColorUtil = __webpack_require__(6);
var Base = __webpack_require__(0);
var Color =
/*#__PURE__*/
function (_Base) {
_inheritsLoose(Color, _Base);
function Color(cfg) {
var _this;
_this = _Base.call(this, cfg) || this;
_this.names = ['color'];
_this.type = 'color';
_this.gradient = null;
if (isString(_this.values)) {
_this.linear = true;
}
return _this;
}
/**
* @override
*/
var _proto = Color.prototype;
_proto.getLinearValue = function getLinearValue(percent) {
var gradient = this.gradient;
if (!gradient) {
var values = this.values;
gradient = ColorUtil.gradient(values);
this.gradient = gradient;
}
return gradient(percent);
};
return Color;
}(Base);
module.exports = Color;
/***/ }),
/* 12 */
/***/ (function(module, exports, __webpack_require__) {
/**
* 判断是否数字
* @return {Boolean} 是否数字
*/
var isType = __webpack_require__(2);
var isNumber = function isNumber(value) {
return isType(value, 'Number');
};
module.exports = isNumber;
/***/ }),
/* 13 */
/***/ (function(module, exports, __webpack_require__) {
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
var Base = __webpack_require__(0);
var Shape =
/*#__PURE__*/
function (_Base) {
_inheritsLoose(Shape, _Base);
function Shape(cfg) {
var _this;
_this = _Base.call(this, cfg) || this;
_this.names = ['shape'];
_this.type = 'shape';
_this.gradient = null;
return _this;
}
/**
* @override
*/
var _proto = Shape.prototype;
_proto.getLinearValue = function getLinearValue(percent) {
var values = this.values;
var index = Math.round((values.length - 1) * percent);
return values[index];
};
return Shape;
}(Base);
module.exports = Shape;
/***/ }),
/* 14 */
/***/ (function(module, exports, __webpack_require__) {
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
var Base = __webpack_require__(0);
var Size =
/*#__PURE__*/
function (_Base) {
_inheritsLoose(Size, _Base);
function Size(cfg) {
var _this;
_this = _Base.call(this, cfg) || this;
_this.names = ['size'];
_this.type = 'size';
_this.gradient = null;
return _this;
}
return Size;
}(Base);
module.exports = Size;
/***/ }),
/* 15 */
/***/ (function(module, exports, __webpack_require__) {
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
var Base = __webpack_require__(0);
var Opacity =
/*#__PURE__*/
function (_Base) {
_inheritsLoose(Opacity, _Base);
function Opacity(cfg) {
var _this;
_this = _Base.call(this, cfg) || this;
_this.names = ['opacity'];
_this.type = 'opacity';
_this.gradient = null;
return _this;
}
return Opacity;
}(Base);
module.exports = Opacity;
/***/ })
/******/ ]);
});
//# sourceMappingURL=attr.js.map