index.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143
  1. module.exports = (function() {
  2. var __MODS__ = {};
  3. var __DEFINE__ = function(modId, func, req) { var m = { exports: {}, _tempexports: {} }; __MODS__[modId] = { status: 0, func: func, req: req, m: m }; };
  4. var __REQUIRE__ = function(modId, source) { if(!__MODS__[modId]) return require(source); if(!__MODS__[modId].status) { var m = __MODS__[modId].m; m._exports = m._tempexports; var desp = Object.getOwnPropertyDescriptor(m, "exports"); if (desp && desp.configurable) Object.defineProperty(m, "exports", { set: function (val) { if(typeof val === "object" && val !== m._exports) { m._exports.__proto__ = val.__proto__; Object.keys(val).forEach(function (k) { m._exports[k] = val[k]; }); } m._tempexports = val }, get: function () { return m._tempexports; } }); __MODS__[modId].status = 1; __MODS__[modId].func(__MODS__[modId].req, m, m.exports); } return __MODS__[modId].m.exports; };
  5. var __REQUIRE_WILDCARD__ = function(obj) { if(obj && obj.__esModule) { return obj; } else { var newObj = {}; if(obj != null) { for(var k in obj) { if (Object.prototype.hasOwnProperty.call(obj, k)) newObj[k] = obj[k]; } } newObj.default = obj; return newObj; } };
  6. var __REQUIRE_DEFAULT__ = function(obj) { return obj && obj.__esModule ? obj.default : obj; };
  7. __DEFINE__(1658993502530, function(require, module, exports) {
  8. (function webpackUniversalModuleDefinition(root, factory) {
  9. if(typeof exports === 'object' && typeof module === 'object')
  10. module.exports = factory();
  11. else if(typeof define === 'function' && define.amd)
  12. define([], factory);
  13. else if(typeof exports === 'object')
  14. exports["adjust"] = factory();
  15. else
  16. root["adjust"] = factory();
  17. })(typeof self !== 'undefined' ? self : this, function() {
  18. return /******/ (function(modules) { // webpackBootstrap
  19. /******/ // The module cache
  20. /******/ var installedModules = {};
  21. /******/
  22. /******/ // The require function
  23. /******/ function __webpack_require__(moduleId) {
  24. /******/
  25. /******/ // Check if module is in cache
  26. /******/ if(installedModules[moduleId]) {
  27. /******/ return installedModules[moduleId].exports;
  28. /******/ }
  29. /******/ // Create a new module (and put it into the cache)
  30. /******/ var module = installedModules[moduleId] = {
  31. /******/ i: moduleId,
  32. /******/ l: false,
  33. /******/ exports: {}
  34. /******/ };
  35. /******/
  36. /******/ // Execute the module function
  37. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  38. /******/
  39. /******/ // Flag the module as loaded
  40. /******/ module.l = true;
  41. /******/
  42. /******/ // Return the exports of the module
  43. /******/ return module.exports;
  44. /******/ }
  45. /******/
  46. /******/
  47. /******/ // expose the modules object (__webpack_modules__)
  48. /******/ __webpack_require__.m = modules;
  49. /******/
  50. /******/ // expose the module cache
  51. /******/ __webpack_require__.c = installedModules;
  52. /******/
  53. /******/ // define getter function for harmony exports
  54. /******/ __webpack_require__.d = function(exports, name, getter) {
  55. /******/ if(!__webpack_require__.o(exports, name)) {
  56. /******/ Object.defineProperty(exports, name, {
  57. /******/ configurable: false,
  58. /******/ enumerable: true,
  59. /******/ get: getter
  60. /******/ });
  61. /******/ }
  62. /******/ };
  63. /******/
  64. /******/ // getDefaultExport function for compatibility with non-harmony modules
  65. /******/ __webpack_require__.n = function(module) {
  66. /******/ var getter = module && module.__esModule ?
  67. /******/ function getDefault() { return module['default']; } :
  68. /******/ function getModuleExports() { return module; };
  69. /******/ __webpack_require__.d(getter, 'a', getter);
  70. /******/ return getter;
  71. /******/ };
  72. /******/
  73. /******/ // Object.prototype.hasOwnProperty.call
  74. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  75. /******/
  76. /******/ // __webpack_public_path__
  77. /******/ __webpack_require__.p = "";
  78. /******/
  79. /******/ // Load entry module and return exports
  80. /******/ return __webpack_require__(__webpack_require__.s = 10);
  81. /******/ })
  82. /************************************************************************/
  83. /******/ ([
  84. /* 0 */
  85. /***/ (function(module, exports, __webpack_require__) {
  86. var isObject = __webpack_require__(12);
  87. var isArray = __webpack_require__(1);
  88. var each = function each(elements, func) {
  89. if (!elements) {
  90. return;
  91. }
  92. var rst = void 0;
  93. if (isArray(elements)) {
  94. for (var i = 0, len = elements.length; i < len; i++) {
  95. rst = func(elements[i], i);
  96. if (rst === false) {
  97. break;
  98. }
  99. }
  100. } else if (isObject(elements)) {
  101. for (var k in elements) {
  102. if (elements.hasOwnProperty(k)) {
  103. rst = func(elements[k], k);
  104. if (rst === false) {
  105. break;
  106. }
  107. }
  108. }
  109. }
  110. };
  111. module.exports = each;
  112. /***/ }),
  113. /* 1 */
  114. /***/ (function(module, exports, __webpack_require__) {
  115. var isType = __webpack_require__(5);
  116. var isArray = Array.isArray ? Array.isArray : function (value) {
  117. return isType(value, 'Array');
  118. };
  119. module.exports = isArray;
  120. /***/ }),
  121. /* 2 */
  122. /***/ (function(module, exports, __webpack_require__) {
  123. var mix = __webpack_require__(3);
  124. var Adjust =
  125. /*#__PURE__*/
  126. function () {
  127. var _proto = Adjust.prototype;
  128. _proto._initDefaultCfg = function _initDefaultCfg() {
  129. this.adjustNames = ['x', 'y']; // 调整的维度,默认,x,y都做调整
  130. };
  131. function Adjust(cfg) {
  132. this._initDefaultCfg();
  133. mix(this, cfg);
  134. }
  135. /**
  136. * @override
  137. */
  138. _proto.processAdjust = function processAdjust()
  139. /* dataArray */
  140. {};
  141. return Adjust;
  142. }();
  143. module.exports = Adjust;
  144. /***/ }),
  145. /* 3 */
  146. /***/ (function(module, exports) {
  147. function _mix(dist, obj) {
  148. for (var key in obj) {
  149. if (obj.hasOwnProperty(key) && key !== 'constructor' && obj[key] !== undefined) {
  150. dist[key] = obj[key];
  151. }
  152. }
  153. }
  154. var mix = function mix(dist, src1, src2, src3) {
  155. if (src1) _mix(dist, src1);
  156. if (src2) _mix(dist, src2);
  157. if (src3) _mix(dist, src3);
  158. return dist;
  159. };
  160. module.exports = mix;
  161. /***/ }),
  162. /* 4 */
  163. /***/ (function(module, exports) {
  164. var merge = function merge(dataArray) {
  165. var rst = [];
  166. for (var i = 0; i < dataArray.length; i++) {
  167. rst = rst.concat(dataArray[i]);
  168. }
  169. return rst;
  170. };
  171. module.exports = merge;
  172. /***/ }),
  173. /* 5 */
  174. /***/ (function(module, exports) {
  175. var toString = {}.toString;
  176. var isType = function isType(value, type) {
  177. return toString.call(value) === '[object ' + type + ']';
  178. };
  179. module.exports = isType;
  180. /***/ }),
  181. /* 6 */
  182. /***/ (function(module, exports) {
  183. // isFinite,
  184. var isNil = function isNil(value) {
  185. /**
  186. * isNil(null) => true
  187. * isNil() => true
  188. */
  189. return value === null || value === undefined;
  190. };
  191. module.exports = isNil;
  192. /***/ }),
  193. /* 7 */
  194. /***/ (function(module, exports, __webpack_require__) {
  195. var DEFAULT_Y = 0; // 默认的y的值
  196. var each = __webpack_require__(0);
  197. var ArrayUtil = {
  198. values: __webpack_require__(8)
  199. };
  200. module.exports = {
  201. /**
  202. * 对应的维度是否可以调整
  203. * @protected
  204. * @param {String} dimName 可以调整的维度 x,y
  205. * @return {Boolean} 是否可以调整
  206. */
  207. isAdjust: function isAdjust(dimName) {
  208. return this.adjustNames.indexOf(dimName) >= 0;
  209. },
  210. /**
  211. * @protected
  212. * 获取可调整度量对应的值
  213. * @param {Frame} mergeData 数据
  214. * @return {Object} 值的映射
  215. */
  216. _getDimValues: function _getDimValues(mergeData) {
  217. var self = this;
  218. var valuesMap = {};
  219. var dims = [];
  220. if (self.xField && self.isAdjust('x')) {
  221. dims.push(self.xField);
  222. }
  223. if (self.yField && self.isAdjust('y')) {
  224. dims.push(self.yField);
  225. }
  226. each(dims, function (dim) {
  227. var values = ArrayUtil.values(mergeData, dim);
  228. values.sort(function (v1, v2) {
  229. return v1 - v2;
  230. });
  231. valuesMap[dim] = values;
  232. });
  233. if (!self.yField && self.isAdjust('y')) {
  234. // 只有一维的情况下,同时调整y
  235. var dim = 'y';
  236. var values = [DEFAULT_Y, 1]; // 默认分布在y轴的 0.1 与 0.2 之间
  237. valuesMap[dim] = values;
  238. }
  239. return valuesMap;
  240. },
  241. adjustData: function adjustData(dataArray, mergeData) {
  242. var self = this;
  243. var valuesMap = self._getDimValues(mergeData);
  244. each(dataArray, function (data, index) {
  245. // 遍历所有数据集合
  246. each(valuesMap, function (values, dim) {
  247. // 根据不同的度量分别调整位置
  248. self.adjustDim(dim, values, data, dataArray.length, index);
  249. });
  250. });
  251. },
  252. getAdjustRange: function getAdjustRange(dim, key, values) {
  253. var self = this;
  254. var index = values.indexOf(key);
  255. var length = values.length;
  256. var pre;
  257. var next;
  258. if (!self.yField && self.isAdjust('y')) {
  259. pre = 0;
  260. next = 1;
  261. } else if (length > 1) {
  262. pre = index === 0 ? values[0] : values[index - 1];
  263. next = index === length - 1 ? values[length - 1] : values[index + 1];
  264. if (index !== 0) {
  265. pre += (key - pre) / 2;
  266. } else {
  267. pre -= (next - key) / 2;
  268. }
  269. if (index !== length - 1) {
  270. next -= (next - key) / 2;
  271. } else {
  272. next += (key - values[length - 2]) / 2;
  273. }
  274. } else {
  275. pre = key === 0 ? 0 : key - 0.5;
  276. next = key === 0 ? 1 : key + 0.5;
  277. }
  278. return {
  279. pre: pre,
  280. next: next
  281. };
  282. },
  283. /**
  284. * 对数据进行分组
  285. * @param {Array} data 数据
  286. * @param {String} dim 分组的字段
  287. * @return {Object} 分组的键值对映射
  288. */
  289. groupData: function groupData(data, dim) {
  290. var groups = {};
  291. each(data, function (record) {
  292. var value = record[dim];
  293. if (value === undefined) {
  294. value = record[dim] = DEFAULT_Y;
  295. }
  296. if (!groups[value]) {
  297. groups[value] = [];
  298. }
  299. groups[value].push(record);
  300. });
  301. return groups;
  302. }
  303. };
  304. /***/ }),
  305. /* 8 */
  306. /***/ (function(module, exports, __webpack_require__) {
  307. var isNil = __webpack_require__(6);
  308. var isArray = __webpack_require__(1);
  309. var each = __webpack_require__(0);
  310. module.exports = function valuesOfKey(data, name) {
  311. var rst = [];
  312. var tmpMap = {};
  313. for (var i = 0; i < data.length; i++) {
  314. var obj = data[i];
  315. var value = obj[name];
  316. if (!isNil(value)) {
  317. if (!isArray(value)) {
  318. value = [value];
  319. }
  320. each(value, function (val) {
  321. if (!tmpMap[val]) {
  322. rst.push(val);
  323. tmpMap[val] = true;
  324. }
  325. });
  326. }
  327. }
  328. return rst;
  329. };
  330. /***/ }),
  331. /* 9 */
  332. /***/ (function(module, exports, __webpack_require__) {
  333. /**
  334. * 是否为函数
  335. * @param {*} fn 对象
  336. * @return {Boolean} 是否函数
  337. */
  338. var isType = __webpack_require__(5);
  339. var isFunction = function isFunction(value) {
  340. return isType(value, 'Function');
  341. };
  342. module.exports = isFunction;
  343. /***/ }),
  344. /* 10 */
  345. /***/ (function(module, exports, __webpack_require__) {
  346. // 完整版下使用支持按照某个字段进行分组的 dodge
  347. var mix = __webpack_require__(3);
  348. var Adjust = __webpack_require__(2);
  349. var Dodge = __webpack_require__(11);
  350. var Stack = __webpack_require__(13);
  351. var AdjustMixin = __webpack_require__(7);
  352. var DodgeMixin = __webpack_require__(14);
  353. var StackMixin = __webpack_require__(18);
  354. mix(Adjust.prototype, AdjustMixin);
  355. mix(Dodge.prototype, AdjustMixin, DodgeMixin);
  356. mix(Stack.prototype, StackMixin);
  357. Adjust.Jitter = __webpack_require__(19);
  358. Adjust.Symmetric = __webpack_require__(20);
  359. Adjust.Dodge = Dodge;
  360. Adjust.Stack = Stack;
  361. module.exports = Adjust;
  362. /***/ }),
  363. /* 11 */
  364. /***/ (function(module, exports, __webpack_require__) {
  365. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  366. var Adjust = __webpack_require__(2);
  367. var each = __webpack_require__(0);
  368. var MARGIN_RATIO = 1 / 2;
  369. var DODGE_RATIO = 1 / 2;
  370. var Dodge =
  371. /*#__PURE__*/
  372. function (_Adjust) {
  373. _inheritsLoose(Dodge, _Adjust);
  374. function Dodge() {
  375. return _Adjust.apply(this, arguments) || this;
  376. }
  377. var _proto = Dodge.prototype;
  378. _proto._initDefaultCfg = function _initDefaultCfg() {
  379. /**
  380. * 调整过程中,2个数据的间距
  381. * @type {Number}
  382. */
  383. this.marginRatio = MARGIN_RATIO;
  384. /**
  385. * 调整占单位宽度的比例,例如:占2个分类间距的 1/2
  386. * @type {Number}
  387. */
  388. this.dodgeRatio = DODGE_RATIO;
  389. this.adjustNames = ['x', 'y']; // 调整的维度,默认,x,y都做调整
  390. };
  391. _proto.getDodgeOffset = function getDodgeOffset(range, index, count) {
  392. var self = this;
  393. var pre = range.pre;
  394. var next = range.next;
  395. var tickLength = next - pre;
  396. var width = tickLength * self.dodgeRatio / count;
  397. var margin = self.marginRatio * width;
  398. var offset = 1 / 2 * (tickLength - count * width - (count - 1) * margin) + ((index + 1) * width + index * margin) - 1 / 2 * width - 1 / 2 * tickLength;
  399. return (pre + next) / 2 + offset;
  400. };
  401. _proto.processAdjust = function processAdjust(dataArray) {
  402. var self = this;
  403. var count = dataArray.length;
  404. var xField = self.xField;
  405. each(dataArray, function (data, index) {
  406. for (var i = 0, len = data.length; i < len; i++) {
  407. var obj = data[i];
  408. var value = obj[xField];
  409. var range = {
  410. pre: len === 1 ? value - 1 : value - 0.5,
  411. next: len === 1 ? value + 1 : value + 0.5
  412. };
  413. var dodgeValue = self.getDodgeOffset(range, index, count);
  414. obj[xField] = dodgeValue;
  415. }
  416. });
  417. };
  418. return Dodge;
  419. }(Adjust);
  420. Adjust.Dodge = Dodge;
  421. module.exports = Dodge;
  422. /***/ }),
  423. /* 12 */
  424. /***/ (function(module, exports) {
  425. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
  426. return typeof obj;
  427. } : function (obj) {
  428. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  429. };
  430. var isObject = function isObject(value) {
  431. /**
  432. * isObject({}) => true
  433. * isObject([1, 2, 3]) => true
  434. * isObject(Function) => true
  435. * isObject(null) => false
  436. */
  437. var type = typeof value === 'undefined' ? 'undefined' : _typeof(value);
  438. return value !== null && type === 'object' || type === 'function';
  439. };
  440. module.exports = isObject;
  441. /***/ }),
  442. /* 13 */
  443. /***/ (function(module, exports, __webpack_require__) {
  444. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  445. var isArray = __webpack_require__(1);
  446. var isNil = __webpack_require__(6);
  447. var Adjust = __webpack_require__(2);
  448. var Stack =
  449. /*#__PURE__*/
  450. function (_Adjust) {
  451. _inheritsLoose(Stack, _Adjust);
  452. function Stack() {
  453. return _Adjust.apply(this, arguments) || this;
  454. }
  455. var _proto = Stack.prototype;
  456. _proto._initDefaultCfg = function _initDefaultCfg() {
  457. this.xField = null; // 调整对应的 x 方向对应的字段名称
  458. this.yField = null; // 调整对应的 y 方向对应的字段名称
  459. };
  460. _proto.processAdjust = function processAdjust(dataArray) {
  461. this.processStack(dataArray);
  462. };
  463. _proto.processStack = function processStack(dataArray) {
  464. var self = this;
  465. var xField = self.xField;
  466. var yField = self.yField;
  467. var count = dataArray.length;
  468. var stackCache = {
  469. positive: {},
  470. negative: {}
  471. }; // 层叠顺序翻转
  472. if (self.reverseOrder) {
  473. dataArray = dataArray.slice(0).reverse();
  474. }
  475. for (var i = 0; i < count; i++) {
  476. var data = dataArray[i];
  477. for (var j = 0, len = data.length; j < len; j++) {
  478. var item = data[j];
  479. var x = item[xField] || 0;
  480. var y = item[yField];
  481. var xkey = x.toString();
  482. y = isArray(y) ? y[1] : y;
  483. if (!isNil(y)) {
  484. var direction = y >= 0 ? 'positive' : 'negative';
  485. if (!stackCache[direction][xkey]) {
  486. stackCache[direction][xkey] = 0;
  487. }
  488. item[yField] = [stackCache[direction][xkey], y + stackCache[direction][xkey]];
  489. stackCache[direction][xkey] += y;
  490. }
  491. }
  492. }
  493. };
  494. return Stack;
  495. }(Adjust);
  496. Adjust.Stack = Stack;
  497. module.exports = Stack;
  498. /***/ }),
  499. /* 14 */
  500. /***/ (function(module, exports, __webpack_require__) {
  501. var ArrayUtil = {
  502. merge: __webpack_require__(4),
  503. values: __webpack_require__(8)
  504. };
  505. var group = __webpack_require__(15);
  506. var each = __webpack_require__(0);
  507. module.exports = {
  508. /**
  509. * @protected
  510. * @override
  511. */
  512. processAdjust: function processAdjust(dataArray) {
  513. var self = this;
  514. var mergeData = ArrayUtil.merge(dataArray);
  515. var dodgeDim = self.dodgeBy;
  516. var adjDataArray = dataArray;
  517. if (dodgeDim) {
  518. // 如果指定了分组dim的字段
  519. adjDataArray = group(mergeData, dodgeDim);
  520. }
  521. self.cacheMap = {};
  522. self.adjDataArray = adjDataArray;
  523. self.mergeData = mergeData;
  524. self.adjustData(adjDataArray, mergeData);
  525. self.adjDataArray = null;
  526. self.mergeData = null;
  527. },
  528. getDistribution: function getDistribution(dim) {
  529. var self = this;
  530. var dataArray = self.adjDataArray;
  531. var cacheMap = self.cacheMap;
  532. var map = cacheMap[dim];
  533. if (!map) {
  534. map = {};
  535. each(dataArray, function (data, index) {
  536. var values = ArrayUtil.values(data, dim);
  537. if (!values.length) {
  538. values.push(0);
  539. }
  540. each(values, function (val) {
  541. if (!map[val]) {
  542. map[val] = [];
  543. }
  544. map[val].push(index);
  545. });
  546. });
  547. cacheMap[dim] = map;
  548. }
  549. return map;
  550. },
  551. adjustDim: function adjustDim(dim, values, data, frameCount, frameIndex) {
  552. var self = this;
  553. var map = self.getDistribution(dim);
  554. var groupData = self.groupData(data, dim); // 根据值分组
  555. each(groupData, function (group, key) {
  556. key = parseFloat(key);
  557. var range;
  558. if (values.length === 1) {
  559. range = {
  560. pre: values[0] - 1,
  561. next: values[0] + 1
  562. };
  563. } else {
  564. range = self.getAdjustRange(dim, key, values);
  565. }
  566. each(group, function (record) {
  567. var value = record[dim];
  568. var valueArr = map[value];
  569. var valIndex = valueArr.indexOf(frameIndex);
  570. record[dim] = self.getDodgeOffset(range, valIndex, valueArr.length);
  571. });
  572. });
  573. }
  574. };
  575. /***/ }),
  576. /* 15 */
  577. /***/ (function(module, exports, __webpack_require__) {
  578. var groupToMap = __webpack_require__(16);
  579. var group = function group(data, condition) {
  580. if (!condition) {
  581. return [data];
  582. }
  583. var groups = groupToMap(data, condition);
  584. var array = [];
  585. for (var i in groups) {
  586. array.push(groups[i]);
  587. }
  588. return array;
  589. };
  590. module.exports = group;
  591. /***/ }),
  592. /* 16 */
  593. /***/ (function(module, exports, __webpack_require__) {
  594. var isFunction = __webpack_require__(9);
  595. var isArray = __webpack_require__(1);
  596. var groupBy = __webpack_require__(17);
  597. var groupToMap = function groupToMap(data, condition) {
  598. if (!condition) {
  599. return {
  600. 0: data
  601. };
  602. }
  603. if (!isFunction(condition)) {
  604. var paramsCondition = isArray(condition) ? condition : condition.replace(/\s+/g, '').split('*');
  605. condition = function condition(row) {
  606. var unique = '_'; // 避免出现数字作为Key的情况,会进行按照数字的排序
  607. for (var i = 0, l = paramsCondition.length; i < l; i++) {
  608. unique += row[paramsCondition[i]] && row[paramsCondition[i]].toString();
  609. }
  610. return unique;
  611. };
  612. }
  613. var groups = groupBy(data, condition);
  614. return groups;
  615. };
  616. module.exports = groupToMap;
  617. /***/ }),
  618. /* 17 */
  619. /***/ (function(module, exports, __webpack_require__) {
  620. var each = __webpack_require__(0);
  621. var isArray = __webpack_require__(1);
  622. var hasOwnProperty = Object.prototype.hasOwnProperty;
  623. var groupBy = function groupBy(data, condition) {
  624. if (!condition || !isArray(data)) {
  625. return data;
  626. }
  627. var result = {};
  628. var key = null;
  629. each(data, function (item) {
  630. key = condition(item);
  631. if (hasOwnProperty.call(result, key)) {
  632. result[key].push(item);
  633. } else {
  634. result[key] = [item];
  635. }
  636. });
  637. return result;
  638. };
  639. module.exports = groupBy;
  640. /***/ }),
  641. /* 18 */
  642. /***/ (function(module, exports) {
  643. module.exports = {
  644. _initDefaultCfg: function _initDefaultCfg() {
  645. this.xField = null; // 调整对应的 x 方向对应的字段名称
  646. this.yField = null; // 调整对应的 y 方向对应的字段名称
  647. this.height = null; // 仅有一个维度调整时,总的高度
  648. this.size = 10; // 单个点的大小
  649. this.reverseOrder = false; // 是否反序进行层叠
  650. this.adjustNames = ['y']; // Only support stack y
  651. },
  652. processOneDimStack: function processOneDimStack(dataArray) {
  653. var self = this;
  654. var xField = self.xField;
  655. var yField = self.yField || 'y';
  656. var height = self.height;
  657. var stackY = {}; // 如果层叠的顺序翻转
  658. if (self.reverseOrder) {
  659. dataArray = dataArray.slice(0).reverse();
  660. }
  661. for (var i = 0, len = dataArray.length; i < len; i++) {
  662. var data = dataArray[i]; // cates
  663. for (var j = 0, dataLen = data.length; j < dataLen; j++) {
  664. var item = data[j];
  665. var size = item.size || self.size;
  666. var stackHeight = size * 2 / height;
  667. var x = item[xField];
  668. if (!stackY[x]) {
  669. stackY[x] = stackHeight / 2;
  670. }
  671. item[yField] = stackY[x];
  672. stackY[x] += stackHeight;
  673. }
  674. }
  675. },
  676. processAdjust: function processAdjust(dataArray) {
  677. if (this.yField) {
  678. this.processStack(dataArray);
  679. } else {
  680. this.processOneDimStack(dataArray);
  681. }
  682. }
  683. };
  684. /***/ }),
  685. /* 19 */
  686. /***/ (function(module, exports, __webpack_require__) {
  687. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  688. var each = __webpack_require__(0);
  689. var mix = __webpack_require__(3);
  690. var ArrayUtil = {
  691. merge: __webpack_require__(4)
  692. };
  693. var Adjust = __webpack_require__(2);
  694. var AdjustMixin = __webpack_require__(7);
  695. var Jitter =
  696. /*#__PURE__*/
  697. function (_Adjust) {
  698. _inheritsLoose(Jitter, _Adjust);
  699. function Jitter() {
  700. return _Adjust.apply(this, arguments) || this;
  701. }
  702. var _proto = Jitter.prototype;
  703. _proto._initDefaultCfg = function _initDefaultCfg() {
  704. this.xField = null; // 调整对应的 x 方向对应的字段名称
  705. this.yField = null; // 调整对应的 y 方向对应的字段名称
  706. this.adjustNames = ['x', 'y']; // 指x,y
  707. this.groupFields = null; // 参与分组的数据维度
  708. };
  709. _proto.processAdjust = function processAdjust(dataArray) {
  710. var self = this;
  711. var mergeData = ArrayUtil.merge(dataArray);
  712. self.adjDataArray = dataArray;
  713. self.mergeData = mergeData;
  714. self.adjustData(dataArray, mergeData);
  715. self.adjFrames = null;
  716. self.mergeData = null;
  717. };
  718. _proto.getAdjustOffset = function getAdjustOffset(pre, next) {
  719. var r = Math.random(); // 随机位置,均匀分布
  720. var avg = next - pre; // * length
  721. var append = avg * 0.05;
  722. return pre + append + avg * 0.9 * r;
  723. }; // adjust group data
  724. _proto._adjustGroup = function _adjustGroup(group, dim, key, values) {
  725. var self = this;
  726. var range = self.getAdjustRange(dim, key, values);
  727. each(group, function (record) {
  728. record[dim] = self.getAdjustOffset(range.pre, range.next); // 获取调整的位置
  729. });
  730. };
  731. _proto.adjustDim = function adjustDim(dim, values, data) {
  732. var self = this;
  733. var groupData = self.groupData(data, dim);
  734. each(groupData, function (group, key) {
  735. key = parseFloat(key);
  736. self._adjustGroup(group, dim, key, values);
  737. });
  738. };
  739. return Jitter;
  740. }(Adjust);
  741. mix(Jitter.prototype, AdjustMixin);
  742. Adjust.Jitter = Jitter;
  743. module.exports = Jitter;
  744. /***/ }),
  745. /* 20 */
  746. /***/ (function(module, exports, __webpack_require__) {
  747. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  748. var each = __webpack_require__(0);
  749. var maxBy = __webpack_require__(21);
  750. var isArray = __webpack_require__(1);
  751. var ArrayUtil = {
  752. merge: __webpack_require__(4)
  753. };
  754. var Adjust = __webpack_require__(2);
  755. var Symmetric =
  756. /*#__PURE__*/
  757. function (_Adjust) {
  758. _inheritsLoose(Symmetric, _Adjust);
  759. function Symmetric() {
  760. return _Adjust.apply(this, arguments) || this;
  761. }
  762. var _proto = Symmetric.prototype;
  763. _proto._initDefaultCfg = function _initDefaultCfg() {
  764. this.xField = null; // 调整对应的 x 方向对应的字段名称
  765. this.yField = null; // 调整对应的 y 方向对应的字段名称
  766. this.cacheMax = null; // 缓存的最大值
  767. this.adjustNames = ['y']; // Only support stack y
  768. this.groupFields = null; // 参与分组的数据维度
  769. }; // 获取最大的y值
  770. _proto._getMax = function _getMax(dim) {
  771. var self = this;
  772. var mergeData = self.mergeData;
  773. var maxRecord = maxBy(mergeData, function (obj) {
  774. var value = obj[dim];
  775. if (isArray(value)) {
  776. return Math.max.apply(null, value);
  777. }
  778. return value;
  779. });
  780. var maxValue = maxRecord[dim];
  781. var max = isArray(maxValue) ? Math.max.apply(null, maxValue) : maxValue;
  782. return max;
  783. }; // 获取每个字段最大的值
  784. _proto._getXValuesMax = function _getXValuesMax() {
  785. var self = this;
  786. var yField = self.yField;
  787. var xField = self.xField;
  788. var cache = {};
  789. var mergeData = self.mergeData;
  790. each(mergeData, function (obj) {
  791. var xValue = obj[xField];
  792. var yValue = obj[yField];
  793. var max = isArray(yValue) ? Math.max.apply(null, yValue) : yValue;
  794. cache[xValue] = cache[xValue] || 0;
  795. if (cache[xValue] < max) {
  796. cache[xValue] = max;
  797. }
  798. });
  799. return cache;
  800. }; // 入口函数
  801. _proto.processAdjust = function processAdjust(dataArray) {
  802. var self = this;
  803. var mergeData = ArrayUtil.merge(dataArray);
  804. self.mergeData = mergeData;
  805. self._processSymmetric(dataArray);
  806. self.mergeData = null;
  807. }; // 处理对称
  808. _proto._processSymmetric = function _processSymmetric(dataArray) {
  809. var self = this;
  810. var xField = self.xField;
  811. var yField = self.yField;
  812. var max = self._getMax(yField);
  813. var first = dataArray[0][0];
  814. var cache;
  815. if (first && isArray(first[yField])) {
  816. cache = self._getXValuesMax();
  817. }
  818. each(dataArray, function (data) {
  819. each(data, function (obj) {
  820. var value = obj[yField];
  821. var offset;
  822. if (isArray(value)) {
  823. var xValue = obj[xField];
  824. var valueMax = cache[xValue];
  825. offset = (max - valueMax) / 2;
  826. var tmp = [];
  827. /* eslint-disable no-loop-func */
  828. each(value, function (subVal) {
  829. // 多个字段
  830. tmp.push(offset + subVal);
  831. });
  832. /* eslint-enable no-loop-func */
  833. obj[yField] = tmp;
  834. } else {
  835. offset = (max - value) / 2;
  836. obj[yField] = [offset, value + offset];
  837. }
  838. });
  839. });
  840. };
  841. return Symmetric;
  842. }(Adjust);
  843. Adjust.Symmetric = Symmetric;
  844. module.exports = Symmetric;
  845. /***/ }),
  846. /* 21 */
  847. /***/ (function(module, exports, __webpack_require__) {
  848. var isArray = __webpack_require__(1);
  849. var isFunction = __webpack_require__(9);
  850. var each = __webpack_require__(0);
  851. /**
  852. * @param {Array} arr The array to iterate over.
  853. * @param {Function} [fn] The iteratee invoked per element.
  854. * @return {*} Returns the maximum value.
  855. * @example
  856. *
  857. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  858. *
  859. * maxBy(objects, function(o) { return o.n; });
  860. * // => { 'n': 2 }
  861. *
  862. * maxBy(objects, 'n');
  863. * // => { 'n': 2 }
  864. */
  865. var maxBy = function maxBy(arr, fn) {
  866. if (!isArray(arr)) {
  867. return undefined;
  868. }
  869. var max = arr[0];
  870. var maxData = void 0;
  871. if (isFunction(fn)) {
  872. maxData = fn(arr[0]);
  873. } else {
  874. maxData = arr[0][fn];
  875. }
  876. var data = void 0;
  877. each(arr, function (val) {
  878. if (isFunction(fn)) {
  879. data = fn(val);
  880. } else {
  881. data = val[fn];
  882. }
  883. if (data > maxData) {
  884. max = val;
  885. maxData = data;
  886. }
  887. });
  888. return max;
  889. };
  890. module.exports = maxBy;
  891. /***/ })
  892. /******/ ]);
  893. });
  894. //# sourceMappingURL=adjust.js.map
  895. }, function(modId) {var map = {}; return __REQUIRE__(map[modId], modId); })
  896. return __REQUIRE__(1658993502530);
  897. })()
  898. //miniprogram-npm-outsideDeps=[]
  899. //# sourceMappingURL=index.js.map