dataTool.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. (function (global, factory) {
  20. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('echarts')) :
  21. typeof define === 'function' && define.amd ? define(['exports', 'echarts'], factory) :
  22. (factory((global.dataTool = {}),global.echarts));
  23. }(this, (function (exports,echarts) { 'use strict';
  24. /**
  25. * @module zrender/core/util
  26. */
  27. // 用于处理merge时无法遍历Date等对象的问题
  28. var arrayProto = Array.prototype;
  29. var nativeMap = arrayProto.map;
  30. /**
  31. * Those data types can be cloned:
  32. * Plain object, Array, TypedArray, number, string, null, undefined.
  33. * Those data types will be assgined using the orginal data:
  34. * BUILTIN_OBJECT
  35. * Instance of user defined class will be cloned to a plain object, without
  36. * properties in prototype.
  37. * Other data types is not supported (not sure what will happen).
  38. *
  39. * Caution: do not support clone Date, for performance consideration.
  40. * (There might be a large number of date in `series.data`).
  41. * So date should not be modified in and out of echarts.
  42. *
  43. * @param {*} source
  44. * @return {*} new
  45. */
  46. /**
  47. * @memberOf module:zrender/core/util
  48. * @param {*} target
  49. * @param {*} source
  50. * @param {boolean} [overwrite=false]
  51. */
  52. /**
  53. * @param {Array} targetAndSources The first item is target, and the rests are source.
  54. * @param {boolean} [overwrite=false]
  55. * @return {*} target
  56. */
  57. /**
  58. * @param {*} target
  59. * @param {*} source
  60. * @memberOf module:zrender/core/util
  61. */
  62. /**
  63. * @param {*} target
  64. * @param {*} source
  65. * @param {boolean} [overlay=false]
  66. * @memberOf module:zrender/core/util
  67. */
  68. /**
  69. * 查询数组中元素的index
  70. * @memberOf module:zrender/core/util
  71. */
  72. /**
  73. * 构造类继承关系
  74. *
  75. * @memberOf module:zrender/core/util
  76. * @param {Function} clazz 源类
  77. * @param {Function} baseClazz 基类
  78. */
  79. /**
  80. * @memberOf module:zrender/core/util
  81. * @param {Object|Function} target
  82. * @param {Object|Function} sorce
  83. * @param {boolean} overlay
  84. */
  85. /**
  86. * Consider typed array.
  87. * @param {Array|TypedArray} data
  88. */
  89. /**
  90. * 数组或对象遍历
  91. * @memberOf module:zrender/core/util
  92. * @param {Object|Array} obj
  93. * @param {Function} cb
  94. * @param {*} [context]
  95. */
  96. /**
  97. * 数组映射
  98. * @memberOf module:zrender/core/util
  99. * @param {Array} obj
  100. * @param {Function} cb
  101. * @param {*} [context]
  102. * @return {Array}
  103. */
  104. function map(obj, cb, context) {
  105. if (!(obj && cb)) {
  106. return;
  107. }
  108. if (obj.map && obj.map === nativeMap) {
  109. return obj.map(cb, context);
  110. }
  111. else {
  112. var result = [];
  113. for (var i = 0, len = obj.length; i < len; i++) {
  114. result.push(cb.call(context, obj[i], i, obj));
  115. }
  116. return result;
  117. }
  118. }
  119. /**
  120. * @memberOf module:zrender/core/util
  121. * @param {Array} obj
  122. * @param {Function} cb
  123. * @param {Object} [memo]
  124. * @param {*} [context]
  125. * @return {Array}
  126. */
  127. /**
  128. * 数组过滤
  129. * @memberOf module:zrender/core/util
  130. * @param {Array} obj
  131. * @param {Function} cb
  132. * @param {*} [context]
  133. * @return {Array}
  134. */
  135. /**
  136. * 数组项查找
  137. * @memberOf module:zrender/core/util
  138. * @param {Array} obj
  139. * @param {Function} cb
  140. * @param {*} [context]
  141. * @return {*}
  142. */
  143. /**
  144. * @memberOf module:zrender/core/util
  145. * @param {Function} func
  146. * @param {*} context
  147. * @return {Function}
  148. */
  149. /**
  150. * @memberOf module:zrender/core/util
  151. * @param {Function} func
  152. * @return {Function}
  153. */
  154. /**
  155. * @memberOf module:zrender/core/util
  156. * @param {*} value
  157. * @return {boolean}
  158. */
  159. /**
  160. * @memberOf module:zrender/core/util
  161. * @param {*} value
  162. * @return {boolean}
  163. */
  164. /**
  165. * @memberOf module:zrender/core/util
  166. * @param {*} value
  167. * @return {boolean}
  168. */
  169. /**
  170. * @memberOf module:zrender/core/util
  171. * @param {*} value
  172. * @return {boolean}
  173. */
  174. /**
  175. * @memberOf module:zrender/core/util
  176. * @param {*} value
  177. * @return {boolean}
  178. */
  179. /**
  180. * @memberOf module:zrender/core/util
  181. * @param {*} value
  182. * @return {boolean}
  183. */
  184. /**
  185. * @memberOf module:zrender/core/util
  186. * @param {*} value
  187. * @return {boolean}
  188. */
  189. /**
  190. * Whether is exactly NaN. Notice isNaN('a') returns true.
  191. * @param {*} value
  192. * @return {boolean}
  193. */
  194. /**
  195. * If value1 is not null, then return value1, otherwise judget rest of values.
  196. * Low performance.
  197. * @memberOf module:zrender/core/util
  198. * @return {*} Final value
  199. */
  200. /**
  201. * @memberOf module:zrender/core/util
  202. * @param {Array} arr
  203. * @param {number} startIndex
  204. * @param {number} endIndex
  205. * @return {Array}
  206. */
  207. /**
  208. * Normalize css liked array configuration
  209. * e.g.
  210. * 3 => [3, 3, 3, 3]
  211. * [4, 2] => [4, 2, 4, 2]
  212. * [4, 3, 2] => [4, 3, 2, 3]
  213. * @param {number|Array.<number>} val
  214. * @return {Array.<number>}
  215. */
  216. /**
  217. * @memberOf module:zrender/core/util
  218. * @param {boolean} condition
  219. * @param {string} message
  220. */
  221. /**
  222. * @memberOf module:zrender/core/util
  223. * @param {string} str string to be trimed
  224. * @return {string} trimed string
  225. */
  226. /**
  227. * Set an object as primitive to be ignored traversing children in clone or merge
  228. */
  229. /*
  230. * Licensed to the Apache Software Foundation (ASF) under one
  231. * or more contributor license agreements. See the NOTICE file
  232. * distributed with this work for additional information
  233. * regarding copyright ownership. The ASF licenses this file
  234. * to you under the Apache License, Version 2.0 (the
  235. * "License"); you may not use this file except in compliance
  236. * with the License. You may obtain a copy of the License at
  237. *
  238. * http://www.apache.org/licenses/LICENSE-2.0
  239. *
  240. * Unless required by applicable law or agreed to in writing,
  241. * software distributed under the License is distributed on an
  242. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  243. * KIND, either express or implied. See the License for the
  244. * specific language governing permissions and limitations
  245. * under the License.
  246. */
  247. /**
  248. * This is a parse of GEXF.
  249. *
  250. * The spec of GEXF:
  251. * https://gephi.org/gexf/1.2draft/gexf-12draft-primer.pdf
  252. */
  253. function parse(xml) {
  254. var doc;
  255. if (typeof xml === 'string') {
  256. var parser = new DOMParser();
  257. doc = parser.parseFromString(xml, 'text/xml');
  258. }
  259. else {
  260. doc = xml;
  261. }
  262. if (!doc || doc.getElementsByTagName('parsererror').length) {
  263. return null;
  264. }
  265. var gexfRoot = getChildByTagName(doc, 'gexf');
  266. if (!gexfRoot) {
  267. return null;
  268. }
  269. var graphRoot = getChildByTagName(gexfRoot, 'graph');
  270. var attributes = parseAttributes(getChildByTagName(graphRoot, 'attributes'));
  271. var attributesMap = {};
  272. for (var i = 0; i < attributes.length; i++) {
  273. attributesMap[attributes[i].id] = attributes[i];
  274. }
  275. return {
  276. nodes: parseNodes(getChildByTagName(graphRoot, 'nodes'), attributesMap),
  277. links: parseEdges(getChildByTagName(graphRoot, 'edges'))
  278. };
  279. }
  280. function parseAttributes(parent) {
  281. return parent ? map(getChildrenByTagName(parent, 'attribute'), function (attribDom) {
  282. return {
  283. id: getAttr(attribDom, 'id'),
  284. title: getAttr(attribDom, 'title'),
  285. type: getAttr(attribDom, 'type')
  286. };
  287. }) : [];
  288. }
  289. function parseNodes(parent, attributesMap) {
  290. return parent ? map(getChildrenByTagName(parent, 'node'), function (nodeDom) {
  291. var id = getAttr(nodeDom, 'id');
  292. var label = getAttr(nodeDom, 'label');
  293. var node = {
  294. id: id,
  295. name: label,
  296. itemStyle: {
  297. normal: {}
  298. }
  299. };
  300. var vizSizeDom = getChildByTagName(nodeDom, 'viz:size');
  301. var vizPosDom = getChildByTagName(nodeDom, 'viz:position');
  302. var vizColorDom = getChildByTagName(nodeDom, 'viz:color');
  303. // var vizShapeDom = getChildByTagName(nodeDom, 'viz:shape');
  304. var attvaluesDom = getChildByTagName(nodeDom, 'attvalues');
  305. if (vizSizeDom) {
  306. node.symbolSize = parseFloat(getAttr(vizSizeDom, 'value'));
  307. }
  308. if (vizPosDom) {
  309. node.x = parseFloat(getAttr(vizPosDom, 'x'));
  310. node.y = parseFloat(getAttr(vizPosDom, 'y'));
  311. // z
  312. }
  313. if (vizColorDom) {
  314. node.itemStyle.normal.color = 'rgb(' + [
  315. getAttr(vizColorDom, 'r') | 0,
  316. getAttr(vizColorDom, 'g') | 0,
  317. getAttr(vizColorDom, 'b') | 0
  318. ].join(',') + ')';
  319. }
  320. // if (vizShapeDom) {
  321. // node.shape = getAttr(vizShapeDom, 'shape');
  322. // }
  323. if (attvaluesDom) {
  324. var attvalueDomList = getChildrenByTagName(attvaluesDom, 'attvalue');
  325. node.attributes = {};
  326. for (var j = 0; j < attvalueDomList.length; j++) {
  327. var attvalueDom = attvalueDomList[j];
  328. var attId = getAttr(attvalueDom, 'for');
  329. var attValue = getAttr(attvalueDom, 'value');
  330. var attribute = attributesMap[attId];
  331. if (attribute) {
  332. switch (attribute.type) {
  333. case 'integer':
  334. case 'long':
  335. attValue = parseInt(attValue, 10);
  336. break;
  337. case 'float':
  338. case 'double':
  339. attValue = parseFloat(attValue);
  340. break;
  341. case 'boolean':
  342. attValue = attValue.toLowerCase() === 'true';
  343. break;
  344. default:
  345. }
  346. node.attributes[attId] = attValue;
  347. }
  348. }
  349. }
  350. return node;
  351. }) : [];
  352. }
  353. function parseEdges(parent) {
  354. return parent ? map(getChildrenByTagName(parent, 'edge'), function (edgeDom) {
  355. var id = getAttr(edgeDom, 'id');
  356. var label = getAttr(edgeDom, 'label');
  357. var sourceId = getAttr(edgeDom, 'source');
  358. var targetId = getAttr(edgeDom, 'target');
  359. var edge = {
  360. id: id,
  361. name: label,
  362. source: sourceId,
  363. target: targetId,
  364. lineStyle: {
  365. normal: {}
  366. }
  367. };
  368. var lineStyle = edge.lineStyle.normal;
  369. var vizThicknessDom = getChildByTagName(edgeDom, 'viz:thickness');
  370. var vizColorDom = getChildByTagName(edgeDom, 'viz:color');
  371. // var vizShapeDom = getChildByTagName(edgeDom, 'viz:shape');
  372. if (vizThicknessDom) {
  373. lineStyle.width = parseFloat(vizThicknessDom.getAttribute('value'));
  374. }
  375. if (vizColorDom) {
  376. lineStyle.color = 'rgb(' + [
  377. getAttr(vizColorDom, 'r') | 0,
  378. getAttr(vizColorDom, 'g') | 0,
  379. getAttr(vizColorDom, 'b') | 0
  380. ].join(',') + ')';
  381. }
  382. // if (vizShapeDom) {
  383. // edge.shape = vizShapeDom.getAttribute('shape');
  384. // }
  385. return edge;
  386. }) : [];
  387. }
  388. function getAttr(el, attrName) {
  389. return el.getAttribute(attrName);
  390. }
  391. function getChildByTagName(parent, tagName) {
  392. var node = parent.firstChild;
  393. while (node) {
  394. if (
  395. node.nodeType !== 1
  396. || node.nodeName.toLowerCase() !== tagName.toLowerCase()
  397. ) {
  398. node = node.nextSibling;
  399. }
  400. else {
  401. return node;
  402. }
  403. }
  404. return null;
  405. }
  406. function getChildrenByTagName(parent, tagName) {
  407. var node = parent.firstChild;
  408. var children = [];
  409. while (node) {
  410. if (node.nodeName.toLowerCase() === tagName.toLowerCase()) {
  411. children.push(node);
  412. }
  413. node = node.nextSibling;
  414. }
  415. return children;
  416. }
  417. var gexf = (Object.freeze || Object)({
  418. parse: parse
  419. });
  420. /*
  421. * Licensed to the Apache Software Foundation (ASF) under one
  422. * or more contributor license agreements. See the NOTICE file
  423. * distributed with this work for additional information
  424. * regarding copyright ownership. The ASF licenses this file
  425. * to you under the Apache License, Version 2.0 (the
  426. * "License"); you may not use this file except in compliance
  427. * with the License. You may obtain a copy of the License at
  428. *
  429. * http://www.apache.org/licenses/LICENSE-2.0
  430. *
  431. * Unless required by applicable law or agreed to in writing,
  432. * software distributed under the License is distributed on an
  433. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  434. * KIND, either express or implied. See the License for the
  435. * specific language governing permissions and limitations
  436. * under the License.
  437. */
  438. /*
  439. * A third-party license is embeded for some of the code in this file:
  440. * The method "quantile" was copied from "d3.js".
  441. * (See more details in the comment of the method below.)
  442. * The use of the source code of this file is also subject to the terms
  443. * and consitions of the license of "d3.js" (BSD-3Clause, see
  444. * </licenses/LICENSE-d3>).
  445. */
  446. /**
  447. * Linear mapping a value from domain to range
  448. * @memberOf module:echarts/util/number
  449. * @param {(number|Array.<number>)} val
  450. * @param {Array.<number>} domain Domain extent domain[0] can be bigger than domain[1]
  451. * @param {Array.<number>} range Range extent range[0] can be bigger than range[1]
  452. * @param {boolean} clamp
  453. * @return {(number|Array.<number>}
  454. */
  455. /**
  456. * Convert a percent string to absolute number.
  457. * Returns NaN if percent is not a valid string or number
  458. * @memberOf module:echarts/util/number
  459. * @param {string|number} percent
  460. * @param {number} all
  461. * @return {number}
  462. */
  463. /**
  464. * (1) Fix rounding error of float numbers.
  465. * (2) Support return string to avoid scientific notation like '3.5e-7'.
  466. *
  467. * @param {number} x
  468. * @param {number} [precision]
  469. * @param {boolean} [returnStr]
  470. * @return {number|string}
  471. */
  472. /**
  473. * asc sort arr.
  474. * The input arr will be modified.
  475. *
  476. * @param {Array} arr
  477. * @return {Array} The input arr.
  478. */
  479. function asc(arr) {
  480. arr.sort(function (a, b) {
  481. return a - b;
  482. });
  483. return arr;
  484. }
  485. /**
  486. * Get precision
  487. * @param {number} val
  488. */
  489. /**
  490. * @param {string|number} val
  491. * @return {number}
  492. */
  493. /**
  494. * Minimal dicernible data precisioin according to a single pixel.
  495. *
  496. * @param {Array.<number>} dataExtent
  497. * @param {Array.<number>} pixelExtent
  498. * @return {number} precision
  499. */
  500. /**
  501. * Get a data of given precision, assuring the sum of percentages
  502. * in valueList is 1.
  503. * The largest remainer method is used.
  504. * https://en.wikipedia.org/wiki/Largest_remainder_method
  505. *
  506. * @param {Array.<number>} valueList a list of all data
  507. * @param {number} idx index of the data to be processed in valueList
  508. * @param {number} precision integer number showing digits of precision
  509. * @return {number} percent ranging from 0 to 100
  510. */
  511. // Number.MAX_SAFE_INTEGER, ie do not support.
  512. /**
  513. * To 0 - 2 * PI, considering negative radian.
  514. * @param {number} radian
  515. * @return {number}
  516. */
  517. /**
  518. * @param {type} radian
  519. * @return {boolean}
  520. */
  521. /* eslint-enable */
  522. /**
  523. * @param {string|Date|number} value These values can be accepted:
  524. * + An instance of Date, represent a time in its own time zone.
  525. * + Or string in a subset of ISO 8601, only including:
  526. * + only year, month, date: '2012-03', '2012-03-01', '2012-03-01 05', '2012-03-01 05:06',
  527. * + separated with T or space: '2012-03-01T12:22:33.123', '2012-03-01 12:22:33.123',
  528. * + time zone: '2012-03-01T12:22:33Z', '2012-03-01T12:22:33+8000', '2012-03-01T12:22:33-05:00',
  529. * all of which will be treated as local time if time zone is not specified
  530. * (see <https://momentjs.com/>).
  531. * + Or other string format, including (all of which will be treated as loacal time):
  532. * '2012', '2012-3-1', '2012/3/1', '2012/03/01',
  533. * '2009/6/12 2:00', '2009/6/12 2:05:08', '2009/6/12 2:05:08.123'
  534. * + a timestamp, which represent a time in UTC.
  535. * @return {Date} date
  536. */
  537. /**
  538. * Quantity of a number. e.g. 0.1, 1, 10, 100
  539. *
  540. * @param {number} val
  541. * @return {number}
  542. */
  543. /**
  544. * Exponent of the quantity of a number
  545. * e.g., 1234 equals to 1.234*10^3, so quantityExponent(1234) is 3
  546. *
  547. * @param {number} val non-negative value
  548. * @return {number}
  549. */
  550. /**
  551. * find a “nice” number approximately equal to x. Round the number if round = true,
  552. * take ceiling if round = false. The primary observation is that the “nicest”
  553. * numbers in decimal are 1, 2, and 5, and all power-of-ten multiples of these numbers.
  554. *
  555. * See "Nice Numbers for Graph Labels" of Graphic Gems.
  556. *
  557. * @param {number} val Non-negative value.
  558. * @param {boolean} round
  559. * @return {number}
  560. */
  561. /**
  562. * This code was copied from "d3.js"
  563. * <https://github.com/d3/d3/blob/9cc9a875e636a1dcf36cc1e07bdf77e1ad6e2c74/src/arrays/quantile.js>.
  564. * See the license statement at the head of this file.
  565. * @param {Array.<number>} ascArr
  566. */
  567. function quantile(ascArr, p) {
  568. var H = (ascArr.length - 1) * p + 1;
  569. var h = Math.floor(H);
  570. var v = +ascArr[h - 1];
  571. var e = H - h;
  572. return e ? v + e * (ascArr[h] - v) : v;
  573. }
  574. /**
  575. * Order intervals asc, and split them when overlap.
  576. * expect(numberUtil.reformIntervals([
  577. * {interval: [18, 62], close: [1, 1]},
  578. * {interval: [-Infinity, -70], close: [0, 0]},
  579. * {interval: [-70, -26], close: [1, 1]},
  580. * {interval: [-26, 18], close: [1, 1]},
  581. * {interval: [62, 150], close: [1, 1]},
  582. * {interval: [106, 150], close: [1, 1]},
  583. * {interval: [150, Infinity], close: [0, 0]}
  584. * ])).toEqual([
  585. * {interval: [-Infinity, -70], close: [0, 0]},
  586. * {interval: [-70, -26], close: [1, 1]},
  587. * {interval: [-26, 18], close: [0, 1]},
  588. * {interval: [18, 62], close: [0, 1]},
  589. * {interval: [62, 150], close: [0, 1]},
  590. * {interval: [150, Infinity], close: [0, 0]}
  591. * ]);
  592. * @param {Array.<Object>} list, where `close` mean open or close
  593. * of the interval, and Infinity can be used.
  594. * @return {Array.<Object>} The origin list, which has been reformed.
  595. */
  596. /**
  597. * parseFloat NaNs numeric-cast false positives (null|true|false|"")
  598. * ...but misinterprets leading-number strings, particularly hex literals ("0x...")
  599. * subtraction forces infinities to NaN
  600. *
  601. * @param {*} v
  602. * @return {boolean}
  603. */
  604. /*
  605. * Licensed to the Apache Software Foundation (ASF) under one
  606. * or more contributor license agreements. See the NOTICE file
  607. * distributed with this work for additional information
  608. * regarding copyright ownership. The ASF licenses this file
  609. * to you under the Apache License, Version 2.0 (the
  610. * "License"); you may not use this file except in compliance
  611. * with the License. You may obtain a copy of the License at
  612. *
  613. * http://www.apache.org/licenses/LICENSE-2.0
  614. *
  615. * Unless required by applicable law or agreed to in writing,
  616. * software distributed under the License is distributed on an
  617. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  618. * KIND, either express or implied. See the License for the
  619. * specific language governing permissions and limitations
  620. * under the License.
  621. */
  622. /**
  623. * See:
  624. * <https://en.wikipedia.org/wiki/Box_plot#cite_note-frigge_hoaglin_iglewicz-2>
  625. * <http://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/boxplot.stats.html>
  626. *
  627. * Helper method for preparing data.
  628. *
  629. * @param {Array.<number>} rawData like
  630. * [
  631. * [12,232,443], (raw data set for the first box)
  632. * [3843,5545,1232], (raw datat set for the second box)
  633. * ...
  634. * ]
  635. * @param {Object} [opt]
  636. *
  637. * @param {(number|string)} [opt.boundIQR=1.5] Data less than min bound is outlier.
  638. * default 1.5, means Q1 - 1.5 * (Q3 - Q1).
  639. * If 'none'/0 passed, min bound will not be used.
  640. * @param {(number|string)} [opt.layout='horizontal']
  641. * Box plot layout, can be 'horizontal' or 'vertical'
  642. * @return {Object} {
  643. * boxData: Array.<Array.<number>>
  644. * outliers: Array.<Array.<number>>
  645. * axisData: Array.<string>
  646. * }
  647. */
  648. var prepareBoxplotData = function (rawData, opt) {
  649. opt = opt || [];
  650. var boxData = [];
  651. var outliers = [];
  652. var axisData = [];
  653. var boundIQR = opt.boundIQR;
  654. var useExtreme = boundIQR === 'none' || boundIQR === 0;
  655. for (var i = 0; i < rawData.length; i++) {
  656. axisData.push(i + '');
  657. var ascList = asc(rawData[i].slice());
  658. var Q1 = quantile(ascList, 0.25);
  659. var Q2 = quantile(ascList, 0.5);
  660. var Q3 = quantile(ascList, 0.75);
  661. var min = ascList[0];
  662. var max = ascList[ascList.length - 1];
  663. var bound = (boundIQR == null ? 1.5 : boundIQR) * (Q3 - Q1);
  664. var low = useExtreme
  665. ? min
  666. : Math.max(min, Q1 - bound);
  667. var high = useExtreme
  668. ? max
  669. : Math.min(max, Q3 + bound);
  670. boxData.push([low, Q1, Q2, Q3, high]);
  671. for (var j = 0; j < ascList.length; j++) {
  672. var dataItem = ascList[j];
  673. if (dataItem < low || dataItem > high) {
  674. var outlier = [i, dataItem];
  675. opt.layout === 'vertical' && outlier.reverse();
  676. outliers.push(outlier);
  677. }
  678. }
  679. }
  680. return {
  681. boxData: boxData,
  682. outliers: outliers,
  683. axisData: axisData
  684. };
  685. };
  686. /*
  687. * Licensed to the Apache Software Foundation (ASF) under one
  688. * or more contributor license agreements. See the NOTICE file
  689. * distributed with this work for additional information
  690. * regarding copyright ownership. The ASF licenses this file
  691. * to you under the Apache License, Version 2.0 (the
  692. * "License"); you may not use this file except in compliance
  693. * with the License. You may obtain a copy of the License at
  694. *
  695. * http://www.apache.org/licenses/LICENSE-2.0
  696. *
  697. * Unless required by applicable law or agreed to in writing,
  698. * software distributed under the License is distributed on an
  699. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  700. * KIND, either express or implied. See the License for the
  701. * specific language governing permissions and limitations
  702. * under the License.
  703. */
  704. var version = '1.0.0';
  705. // For backward compatibility, where the namespace `dataTool` will
  706. // be mounted on `echarts` is the extension `dataTool` is imported.
  707. // But the old version of echarts do not have `dataTool` namespace,
  708. // so check it before mounting.
  709. if (echarts.dataTool) {
  710. echarts.dataTool.version = version;
  711. echarts.dataTool.gexf = gexf;
  712. echarts.dataTool.prepareBoxplotData = prepareBoxplotData;
  713. }
  714. exports.version = version;
  715. exports.gexf = gexf;
  716. exports.prepareBoxplotData = prepareBoxplotData;
  717. })));
  718. //# sourceMappingURL=dataTool.js.map