dataTool.js 23 KB

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