| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863 |
- (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 = 6);
- /******/ })
- /************************************************************************/
- /******/ ([
- /* 0 */
- /***/ (function(module, exports, __webpack_require__) {
- /**
- * @fileOverview the Attribute base class
- */
- var isString = __webpack_require__(4);
- var isArray = __webpack_require__(1);
- 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) {
- /**
- * 属性的类型
- * @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;
- mix(this, cfg);
- } // 获取属性值,将值映射到视觉通道
- 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 _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
- params[_key] = arguments[_key];
- }
- 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, __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;
- }
- 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;
- /***/ }),
- /* 6 */
- /***/ (function(module, exports, __webpack_require__) {
- module.exports = {
- Position: __webpack_require__(7),
- Color: __webpack_require__(11),
- Shape: __webpack_require__(13),
- Size: __webpack_require__(14),
- Opacity: __webpack_require__(15),
- ColorUtil: __webpack_require__(5)
- };
- /***/ }),
- /* 7 */
- /***/ (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__(8);
- 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;
- /***/ }),
- /* 8 */
- /***/ (function(module, exports) {
- // isFinite,
- var isNil = function isNil(value) {
- /**
- * isNil(null) => true
- * isNil() => true
- */
- return value === null || value === undefined;
- };
- module.exports = isNil;
- /***/ }),
- /* 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__(5);
- 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
|