dataTool.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  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. * Copyright (c) 2010-2015, Michael Bostock
  417. * All rights reserved.
  418. *
  419. * Redistribution and use in source and binary forms, with or without
  420. * modification, are permitted provided that the following conditions are met:
  421. *
  422. * * Redistributions of source code must retain the above copyright notice, this
  423. * list of conditions and the following disclaimer.
  424. *
  425. * * Redistributions in binary form must reproduce the above copyright notice,
  426. * this list of conditions and the following disclaimer in the documentation
  427. * and/or other materials provided with the distribution.
  428. *
  429. * * The name Michael Bostock may not be used to endorse or promote products
  430. * derived from this software without specific prior written permission.
  431. *
  432. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  433. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  434. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  435. * DISCLAIMED. IN NO EVENT SHALL MICHAEL BOSTOCK BE LIABLE FOR ANY DIRECT,
  436. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  437. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  438. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  439. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  440. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  441. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  442. */
  443. /**
  444. * @see <https://github.com/mbostock/d3/blob/master/src/arrays/quantile.js>
  445. * @see <http://en.wikipedia.org/wiki/Quantile>
  446. * @param {Array.<number>} ascArr
  447. */
  448. var quantile = function(ascArr, p) {
  449. var H = (ascArr.length - 1) * p + 1,
  450. h = Math.floor(H),
  451. v = +ascArr[h - 1],
  452. e = H - h;
  453. return e ? v + e * (ascArr[h] - v) : v;
  454. };
  455. /*
  456. * Licensed to the Apache Software Foundation (ASF) under one
  457. * or more contributor license agreements. See the NOTICE file
  458. * distributed with this work for additional information
  459. * regarding copyright ownership. The ASF licenses this file
  460. * to you under the Apache License, Version 2.0 (the
  461. * "License"); you may not use this file except in compliance
  462. * with the License. You may obtain a copy of the License at
  463. *
  464. * http://www.apache.org/licenses/LICENSE-2.0
  465. *
  466. * Unless required by applicable law or agreed to in writing,
  467. * software distributed under the License is distributed on an
  468. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  469. * KIND, either express or implied. See the License for the
  470. * specific language governing permissions and limitations
  471. * under the License.
  472. */
  473. /**
  474. * Linear mapping a value from domain to range
  475. * @memberOf module:echarts/util/number
  476. * @param {(number|Array.<number>)} val
  477. * @param {Array.<number>} domain Domain extent domain[0] can be bigger than domain[1]
  478. * @param {Array.<number>} range Range extent range[0] can be bigger than range[1]
  479. * @param {boolean} clamp
  480. * @return {(number|Array.<number>}
  481. */
  482. /**
  483. * Convert a percent string to absolute number.
  484. * Returns NaN if percent is not a valid string or number
  485. * @memberOf module:echarts/util/number
  486. * @param {string|number} percent
  487. * @param {number} all
  488. * @return {number}
  489. */
  490. /**
  491. * (1) Fix rounding error of float numbers.
  492. * (2) Support return string to avoid scientific notation like '3.5e-7'.
  493. *
  494. * @param {number} x
  495. * @param {number} [precision]
  496. * @param {boolean} [returnStr]
  497. * @return {number|string}
  498. */
  499. function asc(arr) {
  500. arr.sort(function (a, b) {
  501. return a - b;
  502. });
  503. return arr;
  504. }
  505. /**
  506. * Get precision
  507. * @param {number} val
  508. */
  509. /**
  510. * @param {string|number} val
  511. * @return {number}
  512. */
  513. /**
  514. * Minimal dicernible data precisioin according to a single pixel.
  515. *
  516. * @param {Array.<number>} dataExtent
  517. * @param {Array.<number>} pixelExtent
  518. * @return {number} precision
  519. */
  520. /**
  521. * Get a data of given precision, assuring the sum of percentages
  522. * in valueList is 1.
  523. * The largest remainer method is used.
  524. * https://en.wikipedia.org/wiki/Largest_remainder_method
  525. *
  526. * @param {Array.<number>} valueList a list of all data
  527. * @param {number} idx index of the data to be processed in valueList
  528. * @param {number} precision integer number showing digits of precision
  529. * @return {number} percent ranging from 0 to 100
  530. */
  531. // Number.MAX_SAFE_INTEGER, ie do not support.
  532. /**
  533. * To 0 - 2 * PI, considering negative radian.
  534. * @param {number} radian
  535. * @return {number}
  536. */
  537. /**
  538. * @param {type} radian
  539. * @return {boolean}
  540. */
  541. /**
  542. * @param {string|Date|number} value These values can be accepted:
  543. * + An instance of Date, represent a time in its own time zone.
  544. * + Or string in a subset of ISO 8601, only including:
  545. * + only year, month, date: '2012-03', '2012-03-01', '2012-03-01 05', '2012-03-01 05:06',
  546. * + separated with T or space: '2012-03-01T12:22:33.123', '2012-03-01 12:22:33.123',
  547. * + time zone: '2012-03-01T12:22:33Z', '2012-03-01T12:22:33+8000', '2012-03-01T12:22:33-05:00',
  548. * all of which will be treated as local time if time zone is not specified
  549. * (see <https://momentjs.com/>).
  550. * + Or other string format, including (all of which will be treated as loacal time):
  551. * '2012', '2012-3-1', '2012/3/1', '2012/03/01',
  552. * '2009/6/12 2:00', '2009/6/12 2:05:08', '2009/6/12 2:05:08.123'
  553. * + a timestamp, which represent a time in UTC.
  554. * @return {Date} date
  555. */
  556. /**
  557. * Quantity of a number. e.g. 0.1, 1, 10, 100
  558. *
  559. * @param {number} val
  560. * @return {number}
  561. */
  562. /**
  563. * find a “nice” number approximately equal to x. Round the number if round = true,
  564. * take ceiling if round = false. The primary observation is that the “nicest”
  565. * numbers in decimal are 1, 2, and 5, and all power-of-ten multiples of these numbers.
  566. *
  567. * See "Nice Numbers for Graph Labels" of Graphic Gems.
  568. *
  569. * @param {number} val Non-negative value.
  570. * @param {boolean} round
  571. * @return {number}
  572. */
  573. /**
  574. * Order intervals asc, and split them when overlap.
  575. * expect(numberUtil.reformIntervals([
  576. * {interval: [18, 62], close: [1, 1]},
  577. * {interval: [-Infinity, -70], close: [0, 0]},
  578. * {interval: [-70, -26], close: [1, 1]},
  579. * {interval: [-26, 18], close: [1, 1]},
  580. * {interval: [62, 150], close: [1, 1]},
  581. * {interval: [106, 150], close: [1, 1]},
  582. * {interval: [150, Infinity], close: [0, 0]}
  583. * ])).toEqual([
  584. * {interval: [-Infinity, -70], close: [0, 0]},
  585. * {interval: [-70, -26], close: [1, 1]},
  586. * {interval: [-26, 18], close: [0, 1]},
  587. * {interval: [18, 62], close: [0, 1]},
  588. * {interval: [62, 150], close: [0, 1]},
  589. * {interval: [150, Infinity], close: [0, 0]}
  590. * ]);
  591. * @param {Array.<Object>} list, where `close` mean open or close
  592. * of the interval, and Infinity can be used.
  593. * @return {Array.<Object>} The origin list, which has been reformed.
  594. */
  595. /**
  596. * parseFloat NaNs numeric-cast false positives (null|true|false|"")
  597. * ...but misinterprets leading-number strings, particularly hex literals ("0x...")
  598. * subtraction forces infinities to NaN
  599. *
  600. * @param {*} v
  601. * @return {boolean}
  602. */
  603. /*
  604. * Licensed to the Apache Software Foundation (ASF) under one
  605. * or more contributor license agreements. See the NOTICE file
  606. * distributed with this work for additional information
  607. * regarding copyright ownership. The ASF licenses this file
  608. * to you under the Apache License, Version 2.0 (the
  609. * "License"); you may not use this file except in compliance
  610. * with the License. You may obtain a copy of the License at
  611. *
  612. * http://www.apache.org/licenses/LICENSE-2.0
  613. *
  614. * Unless required by applicable law or agreed to in writing,
  615. * software distributed under the License is distributed on an
  616. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  617. * KIND, either express or implied. See the License for the
  618. * specific language governing permissions and limitations
  619. * under the License.
  620. */
  621. /**
  622. * See:
  623. * <https://en.wikipedia.org/wiki/Box_plot#cite_note-frigge_hoaglin_iglewicz-2>
  624. * <http://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/boxplot.stats.html>
  625. *
  626. * Helper method for preparing data.
  627. *
  628. * @param {Array.<number>} rawData like
  629. * [
  630. * [12,232,443], (raw data set for the first box)
  631. * [3843,5545,1232], (raw datat set for the second box)
  632. * ...
  633. * ]
  634. * @param {Object} [opt]
  635. *
  636. * @param {(number|string)} [opt.boundIQR=1.5] Data less than min bound is outlier.
  637. * default 1.5, means Q1 - 1.5 * (Q3 - Q1).
  638. * If 'none'/0 passed, min bound will not be used.
  639. * @param {(number|string)} [opt.layout='horizontal']
  640. * Box plot layout, can be 'horizontal' or 'vertical'
  641. * @return {Object} {
  642. * boxData: Array.<Array.<number>>
  643. * outliers: Array.<Array.<number>>
  644. * axisData: Array.<string>
  645. * }
  646. */
  647. var prepareBoxplotData = function (rawData, opt) {
  648. opt = opt || [];
  649. var boxData = [];
  650. var outliers = [];
  651. var axisData = [];
  652. var boundIQR = opt.boundIQR;
  653. var useExtreme = boundIQR === 'none' || boundIQR === 0;
  654. for (var i = 0; i < rawData.length; i++) {
  655. axisData.push(i + '');
  656. var ascList = asc(rawData[i].slice());
  657. var Q1 = quantile(ascList, 0.25);
  658. var Q2 = quantile(ascList, 0.5);
  659. var Q3 = quantile(ascList, 0.75);
  660. var min = ascList[0];
  661. var max = ascList[ascList.length - 1];
  662. var bound = (boundIQR == null ? 1.5 : boundIQR) * (Q3 - Q1);
  663. var low = useExtreme
  664. ? min
  665. : Math.max(min, Q1 - bound);
  666. var high = useExtreme
  667. ? max
  668. : Math.min(max, Q3 + bound);
  669. boxData.push([low, Q1, Q2, Q3, high]);
  670. for (var j = 0; j < ascList.length; j++) {
  671. var dataItem = ascList[j];
  672. if (dataItem < low || dataItem > high) {
  673. var outlier = [i, dataItem];
  674. opt.layout === 'vertical' && outlier.reverse();
  675. outliers.push(outlier);
  676. }
  677. }
  678. }
  679. return {
  680. boxData: boxData,
  681. outliers: outliers,
  682. axisData: axisData
  683. };
  684. };
  685. /*
  686. * Licensed to the Apache Software Foundation (ASF) under one
  687. * or more contributor license agreements. See the NOTICE file
  688. * distributed with this work for additional information
  689. * regarding copyright ownership. The ASF licenses this file
  690. * to you under the Apache License, Version 2.0 (the
  691. * "License"); you may not use this file except in compliance
  692. * with the License. You may obtain a copy of the License at
  693. *
  694. * http://www.apache.org/licenses/LICENSE-2.0
  695. *
  696. * Unless required by applicable law or agreed to in writing,
  697. * software distributed under the License is distributed on an
  698. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  699. * KIND, either express or implied. See the License for the
  700. * specific language governing permissions and limitations
  701. * under the License.
  702. */
  703. var version = '1.0.0';
  704. // For backward compatibility, where the namespace `dataTool` will
  705. // be mounted on `echarts` is the extension `dataTool` is imported.
  706. // But the old version of echarts do not have `dataTool` namespace,
  707. // so check it before mounting.
  708. if (echarts.dataTool) {
  709. echarts.dataTool.version = version;
  710. echarts.dataTool.gexf = gexf;
  711. echarts.dataTool.prepareBoxplotData = prepareBoxplotData;
  712. }
  713. exports.version = version;
  714. exports.gexf = gexf;
  715. exports.prepareBoxplotData = prepareBoxplotData;
  716. })));
  717. //# sourceMappingURL=dataTool.js.map