dataTool.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  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. // GEXF File Parser
  248. // http://gexf.net/1.2draft/gexf-12draft-primer.pdf
  249. function parse(xml) {
  250. var doc;
  251. if (typeof xml === 'string') {
  252. var parser = new DOMParser();
  253. doc = parser.parseFromString(xml, 'text/xml');
  254. }
  255. else {
  256. doc = xml;
  257. }
  258. if (!doc || doc.getElementsByTagName('parsererror').length) {
  259. return null;
  260. }
  261. var gexfRoot = getChildByTagName(doc, 'gexf');
  262. if (!gexfRoot) {
  263. return null;
  264. }
  265. var graphRoot = getChildByTagName(gexfRoot, 'graph');
  266. var attributes = parseAttributes(getChildByTagName(graphRoot, 'attributes'));
  267. var attributesMap = {};
  268. for (var i = 0; i < attributes.length; i++) {
  269. attributesMap[attributes[i].id] = attributes[i];
  270. }
  271. return {
  272. nodes: parseNodes(getChildByTagName(graphRoot, 'nodes'), attributesMap),
  273. links: parseEdges(getChildByTagName(graphRoot, 'edges'))
  274. };
  275. }
  276. function parseAttributes(parent) {
  277. return parent ? map(getChildrenByTagName(parent, 'attribute'), function (attribDom) {
  278. return {
  279. id: getAttr(attribDom, 'id'),
  280. title: getAttr(attribDom, 'title'),
  281. type: getAttr(attribDom, 'type')
  282. };
  283. }) : [];
  284. }
  285. function parseNodes(parent, attributesMap) {
  286. return parent ? map(getChildrenByTagName(parent, 'node'), function (nodeDom) {
  287. var id = getAttr(nodeDom, 'id');
  288. var label = getAttr(nodeDom, 'label');
  289. var node = {
  290. id: id,
  291. name: label,
  292. itemStyle: {
  293. normal: {}
  294. }
  295. };
  296. var vizSizeDom = getChildByTagName(nodeDom, 'viz:size');
  297. var vizPosDom = getChildByTagName(nodeDom, 'viz:position');
  298. var vizColorDom = getChildByTagName(nodeDom, 'viz:color');
  299. // var vizShapeDom = getChildByTagName(nodeDom, 'viz:shape');
  300. var attvaluesDom = getChildByTagName(nodeDom, 'attvalues');
  301. if (vizSizeDom) {
  302. node.symbolSize = parseFloat(getAttr(vizSizeDom, 'value'));
  303. }
  304. if (vizPosDom) {
  305. node.x = parseFloat(getAttr(vizPosDom, 'x'));
  306. node.y = parseFloat(getAttr(vizPosDom, 'y'));
  307. // z
  308. }
  309. if (vizColorDom) {
  310. node.itemStyle.normal.color = 'rgb(' +[
  311. getAttr(vizColorDom, 'r') | 0,
  312. getAttr(vizColorDom, 'g') | 0,
  313. getAttr(vizColorDom, 'b') | 0
  314. ].join(',') + ')';
  315. }
  316. // if (vizShapeDom) {
  317. // node.shape = getAttr(vizShapeDom, 'shape');
  318. // }
  319. if (attvaluesDom) {
  320. var attvalueDomList = getChildrenByTagName(attvaluesDom, 'attvalue');
  321. node.attributes = {};
  322. for (var j = 0; j < attvalueDomList.length; j++) {
  323. var attvalueDom = attvalueDomList[j];
  324. var attId = getAttr(attvalueDom, 'for');
  325. var attValue = getAttr(attvalueDom, 'value');
  326. var attribute = attributesMap[attId];
  327. if (attribute) {
  328. switch (attribute.type) {
  329. case 'integer':
  330. case 'long':
  331. attValue = parseInt(attValue, 10);
  332. break;
  333. case 'float':
  334. case 'double':
  335. attValue = parseFloat(attValue);
  336. break;
  337. case 'boolean':
  338. attValue = attValue.toLowerCase() == 'true';
  339. break;
  340. default:
  341. }
  342. node.attributes[attId] = attValue;
  343. }
  344. }
  345. }
  346. return node;
  347. }) : [];
  348. }
  349. function parseEdges(parent) {
  350. return parent ? map(getChildrenByTagName(parent, 'edge'), function (edgeDom) {
  351. var id = getAttr(edgeDom, 'id');
  352. var label = getAttr(edgeDom, 'label');
  353. var sourceId = getAttr(edgeDom, 'source');
  354. var targetId = getAttr(edgeDom, 'target');
  355. var edge = {
  356. id: id,
  357. name: label,
  358. source: sourceId,
  359. target: targetId,
  360. lineStyle: {
  361. normal: {}
  362. }
  363. };
  364. var lineStyle = edge.lineStyle.normal;
  365. var vizThicknessDom = getChildByTagName(edgeDom, 'viz:thickness');
  366. var vizColorDom = getChildByTagName(edgeDom, 'viz:color');
  367. // var vizShapeDom = getChildByTagName(edgeDom, 'viz:shape');
  368. if (vizThicknessDom) {
  369. lineStyle.width = parseFloat(vizThicknessDom.getAttribute('value'));
  370. }
  371. if (vizColorDom) {
  372. lineStyle.color = 'rgb(' + [
  373. getAttr(vizColorDom, 'r') | 0,
  374. getAttr(vizColorDom, 'g') | 0,
  375. getAttr(vizColorDom, 'b') | 0
  376. ].join(',') + ')';
  377. }
  378. // if (vizShapeDom) {
  379. // edge.shape = vizShapeDom.getAttribute('shape');
  380. // }
  381. return edge;
  382. }) : [];
  383. }
  384. function getAttr(el, attrName) {
  385. return el.getAttribute(attrName);
  386. }
  387. function getChildByTagName (parent, tagName) {
  388. var node = parent.firstChild;
  389. while (node) {
  390. if (
  391. node.nodeType != 1 ||
  392. node.nodeName.toLowerCase() != tagName.toLowerCase()
  393. ) {
  394. node = node.nextSibling;
  395. } else {
  396. return node;
  397. }
  398. }
  399. return null;
  400. }
  401. function getChildrenByTagName (parent, tagName) {
  402. var node = parent.firstChild;
  403. var children = [];
  404. while (node) {
  405. if (node.nodeName.toLowerCase() == tagName.toLowerCase()) {
  406. children.push(node);
  407. }
  408. node = node.nextSibling;
  409. }
  410. return children;
  411. }
  412. var gexf = (Object.freeze || Object)({
  413. parse: parse
  414. });
  415. /*
  416. * Licensed to the Apache Software Foundation (ASF) under one
  417. * or more contributor license agreements. See the NOTICE file
  418. * distributed with this work for additional information
  419. * regarding copyright ownership. The ASF licenses this file
  420. * to you under the Apache License, Version 2.0 (the
  421. * "License"); you may not use this file except in compliance
  422. * with the License. You may obtain a copy of the License at
  423. *
  424. * http://www.apache.org/licenses/LICENSE-2.0
  425. *
  426. * Unless required by applicable law or agreed to in writing,
  427. * software distributed under the License is distributed on an
  428. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  429. * KIND, either express or implied. See the License for the
  430. * specific language governing permissions and limitations
  431. * under the License.
  432. */
  433. /*
  434. * A third-party license is embeded for some of the code in this file:
  435. * The method "quantile" was copied from "d3.js".
  436. * (See more details in the comment of the method below.)
  437. * The use of the source code of this file is also subject to the terms
  438. * and consitions of the license of "d3.js" (BSD-3Clause, see
  439. * </licenses/LICENSE-d3>).
  440. */
  441. /**
  442. * Linear mapping a value from domain to range
  443. * @memberOf module:echarts/util/number
  444. * @param {(number|Array.<number>)} val
  445. * @param {Array.<number>} domain Domain extent domain[0] can be bigger than domain[1]
  446. * @param {Array.<number>} range Range extent range[0] can be bigger than range[1]
  447. * @param {boolean} clamp
  448. * @return {(number|Array.<number>}
  449. */
  450. /**
  451. * Convert a percent string to absolute number.
  452. * Returns NaN if percent is not a valid string or number
  453. * @memberOf module:echarts/util/number
  454. * @param {string|number} percent
  455. * @param {number} all
  456. * @return {number}
  457. */
  458. /**
  459. * (1) Fix rounding error of float numbers.
  460. * (2) Support return string to avoid scientific notation like '3.5e-7'.
  461. *
  462. * @param {number} x
  463. * @param {number} [precision]
  464. * @param {boolean} [returnStr]
  465. * @return {number|string}
  466. */
  467. function asc(arr) {
  468. arr.sort(function (a, b) {
  469. return a - b;
  470. });
  471. return arr;
  472. }
  473. /**
  474. * Get precision
  475. * @param {number} val
  476. */
  477. /**
  478. * @param {string|number} val
  479. * @return {number}
  480. */
  481. /**
  482. * Minimal dicernible data precisioin according to a single pixel.
  483. *
  484. * @param {Array.<number>} dataExtent
  485. * @param {Array.<number>} pixelExtent
  486. * @return {number} precision
  487. */
  488. /**
  489. * Get a data of given precision, assuring the sum of percentages
  490. * in valueList is 1.
  491. * The largest remainer method is used.
  492. * https://en.wikipedia.org/wiki/Largest_remainder_method
  493. *
  494. * @param {Array.<number>} valueList a list of all data
  495. * @param {number} idx index of the data to be processed in valueList
  496. * @param {number} precision integer number showing digits of precision
  497. * @return {number} percent ranging from 0 to 100
  498. */
  499. // Number.MAX_SAFE_INTEGER, ie do not support.
  500. /**
  501. * To 0 - 2 * PI, considering negative radian.
  502. * @param {number} radian
  503. * @return {number}
  504. */
  505. /**
  506. * @param {type} radian
  507. * @return {boolean}
  508. */
  509. /* eslint-enable */
  510. /**
  511. * @param {string|Date|number} value These values can be accepted:
  512. * + An instance of Date, represent a time in its own time zone.
  513. * + Or string in a subset of ISO 8601, only including:
  514. * + only year, month, date: '2012-03', '2012-03-01', '2012-03-01 05', '2012-03-01 05:06',
  515. * + separated with T or space: '2012-03-01T12:22:33.123', '2012-03-01 12:22:33.123',
  516. * + time zone: '2012-03-01T12:22:33Z', '2012-03-01T12:22:33+8000', '2012-03-01T12:22:33-05:00',
  517. * all of which will be treated as local time if time zone is not specified
  518. * (see <https://momentjs.com/>).
  519. * + Or other string format, including (all of which will be treated as loacal time):
  520. * '2012', '2012-3-1', '2012/3/1', '2012/03/01',
  521. * '2009/6/12 2:00', '2009/6/12 2:05:08', '2009/6/12 2:05:08.123'
  522. * + a timestamp, which represent a time in UTC.
  523. * @return {Date} date
  524. */
  525. /**
  526. * Quantity of a number. e.g. 0.1, 1, 10, 100
  527. *
  528. * @param {number} val
  529. * @return {number}
  530. */
  531. /**
  532. * find a “nice” number approximately equal to x. Round the number if round = true,
  533. * take ceiling if round = false. The primary observation is that the “nicest”
  534. * numbers in decimal are 1, 2, and 5, and all power-of-ten multiples of these numbers.
  535. *
  536. * See "Nice Numbers for Graph Labels" of Graphic Gems.
  537. *
  538. * @param {number} val Non-negative value.
  539. * @param {boolean} round
  540. * @return {number}
  541. */
  542. /**
  543. * This code was copied from "d3.js"
  544. * <https://github.com/d3/d3/blob/9cc9a875e636a1dcf36cc1e07bdf77e1ad6e2c74/src/arrays/quantile.js>.
  545. * See the license statement at the head of this file.
  546. * @param {Array.<number>} ascArr
  547. */
  548. function quantile(ascArr, p) {
  549. var H = (ascArr.length - 1) * p + 1;
  550. var h = Math.floor(H);
  551. var v = +ascArr[h - 1];
  552. var e = H - h;
  553. return e ? v + e * (ascArr[h] - v) : v;
  554. }
  555. /**
  556. * Order intervals asc, and split them when overlap.
  557. * expect(numberUtil.reformIntervals([
  558. * {interval: [18, 62], close: [1, 1]},
  559. * {interval: [-Infinity, -70], close: [0, 0]},
  560. * {interval: [-70, -26], close: [1, 1]},
  561. * {interval: [-26, 18], close: [1, 1]},
  562. * {interval: [62, 150], close: [1, 1]},
  563. * {interval: [106, 150], close: [1, 1]},
  564. * {interval: [150, Infinity], close: [0, 0]}
  565. * ])).toEqual([
  566. * {interval: [-Infinity, -70], close: [0, 0]},
  567. * {interval: [-70, -26], close: [1, 1]},
  568. * {interval: [-26, 18], close: [0, 1]},
  569. * {interval: [18, 62], close: [0, 1]},
  570. * {interval: [62, 150], close: [0, 1]},
  571. * {interval: [150, Infinity], close: [0, 0]}
  572. * ]);
  573. * @param {Array.<Object>} list, where `close` mean open or close
  574. * of the interval, and Infinity can be used.
  575. * @return {Array.<Object>} The origin list, which has been reformed.
  576. */
  577. /**
  578. * parseFloat NaNs numeric-cast false positives (null|true|false|"")
  579. * ...but misinterprets leading-number strings, particularly hex literals ("0x...")
  580. * subtraction forces infinities to NaN
  581. *
  582. * @param {*} v
  583. * @return {boolean}
  584. */
  585. /*
  586. * Licensed to the Apache Software Foundation (ASF) under one
  587. * or more contributor license agreements. See the NOTICE file
  588. * distributed with this work for additional information
  589. * regarding copyright ownership. The ASF licenses this file
  590. * to you under the Apache License, Version 2.0 (the
  591. * "License"); you may not use this file except in compliance
  592. * with the License. You may obtain a copy of the License at
  593. *
  594. * http://www.apache.org/licenses/LICENSE-2.0
  595. *
  596. * Unless required by applicable law or agreed to in writing,
  597. * software distributed under the License is distributed on an
  598. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  599. * KIND, either express or implied. See the License for the
  600. * specific language governing permissions and limitations
  601. * under the License.
  602. */
  603. /**
  604. * See:
  605. * <https://en.wikipedia.org/wiki/Box_plot#cite_note-frigge_hoaglin_iglewicz-2>
  606. * <http://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/boxplot.stats.html>
  607. *
  608. * Helper method for preparing data.
  609. *
  610. * @param {Array.<number>} rawData like
  611. * [
  612. * [12,232,443], (raw data set for the first box)
  613. * [3843,5545,1232], (raw datat set for the second box)
  614. * ...
  615. * ]
  616. * @param {Object} [opt]
  617. *
  618. * @param {(number|string)} [opt.boundIQR=1.5] Data less than min bound is outlier.
  619. * default 1.5, means Q1 - 1.5 * (Q3 - Q1).
  620. * If 'none'/0 passed, min bound will not be used.
  621. * @param {(number|string)} [opt.layout='horizontal']
  622. * Box plot layout, can be 'horizontal' or 'vertical'
  623. * @return {Object} {
  624. * boxData: Array.<Array.<number>>
  625. * outliers: Array.<Array.<number>>
  626. * axisData: Array.<string>
  627. * }
  628. */
  629. var prepareBoxplotData = function (rawData, opt) {
  630. opt = opt || [];
  631. var boxData = [];
  632. var outliers = [];
  633. var axisData = [];
  634. var boundIQR = opt.boundIQR;
  635. var useExtreme = boundIQR === 'none' || boundIQR === 0;
  636. for (var i = 0; i < rawData.length; i++) {
  637. axisData.push(i + '');
  638. var ascList = asc(rawData[i].slice());
  639. var Q1 = quantile(ascList, 0.25);
  640. var Q2 = quantile(ascList, 0.5);
  641. var Q3 = quantile(ascList, 0.75);
  642. var min = ascList[0];
  643. var max = ascList[ascList.length - 1];
  644. var bound = (boundIQR == null ? 1.5 : boundIQR) * (Q3 - Q1);
  645. var low = useExtreme
  646. ? min
  647. : Math.max(min, Q1 - bound);
  648. var high = useExtreme
  649. ? max
  650. : Math.min(max, Q3 + bound);
  651. boxData.push([low, Q1, Q2, Q3, high]);
  652. for (var j = 0; j < ascList.length; j++) {
  653. var dataItem = ascList[j];
  654. if (dataItem < low || dataItem > high) {
  655. var outlier = [i, dataItem];
  656. opt.layout === 'vertical' && outlier.reverse();
  657. outliers.push(outlier);
  658. }
  659. }
  660. }
  661. return {
  662. boxData: boxData,
  663. outliers: outliers,
  664. axisData: axisData
  665. };
  666. };
  667. /*
  668. * Licensed to the Apache Software Foundation (ASF) under one
  669. * or more contributor license agreements. See the NOTICE file
  670. * distributed with this work for additional information
  671. * regarding copyright ownership. The ASF licenses this file
  672. * to you under the Apache License, Version 2.0 (the
  673. * "License"); you may not use this file except in compliance
  674. * with the License. You may obtain a copy of the License at
  675. *
  676. * http://www.apache.org/licenses/LICENSE-2.0
  677. *
  678. * Unless required by applicable law or agreed to in writing,
  679. * software distributed under the License is distributed on an
  680. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  681. * KIND, either express or implied. See the License for the
  682. * specific language governing permissions and limitations
  683. * under the License.
  684. */
  685. var version = '1.0.0';
  686. // For backward compatibility, where the namespace `dataTool` will
  687. // be mounted on `echarts` is the extension `dataTool` is imported.
  688. // But the old version of echarts do not have `dataTool` namespace,
  689. // so check it before mounting.
  690. if (echarts.dataTool) {
  691. echarts.dataTool.version = version;
  692. echarts.dataTool.gexf = gexf;
  693. echarts.dataTool.prepareBoxplotData = prepareBoxplotData;
  694. }
  695. exports.version = version;
  696. exports.gexf = gexf;
  697. exports.prepareBoxplotData = prepareBoxplotData;
  698. })));
  699. //# sourceMappingURL=dataTool.js.map