dataTool.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory(require("echarts"));
  4. else if(typeof define === 'function' && define.amd)
  5. define(["echarts"], factory);
  6. else if(typeof exports === 'object')
  7. exports["dataTool"] = factory(require("echarts"));
  8. else
  9. root["echarts"] = root["echarts"] || {}, root["echarts"]["dataTool"] = factory(root["echarts"]);
  10. })(this, function(__WEBPACK_EXTERNAL_MODULE_1__) {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/ // The require function
  15. /******/ function __webpack_require__(moduleId) {
  16. /******/ // Check if module is in cache
  17. /******/ if(installedModules[moduleId])
  18. /******/ return installedModules[moduleId].exports;
  19. /******/ // Create a new module (and put it into the cache)
  20. /******/ var module = installedModules[moduleId] = {
  21. /******/ exports: {},
  22. /******/ id: moduleId,
  23. /******/ loaded: false
  24. /******/ };
  25. /******/ // Execute the module function
  26. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  27. /******/ // Flag the module as loaded
  28. /******/ module.loaded = true;
  29. /******/ // Return the exports of the module
  30. /******/ return module.exports;
  31. /******/ }
  32. /******/ // expose the modules object (__webpack_modules__)
  33. /******/ __webpack_require__.m = modules;
  34. /******/ // expose the module cache
  35. /******/ __webpack_require__.c = installedModules;
  36. /******/ // __webpack_public_path__
  37. /******/ __webpack_require__.p = "";
  38. /******/ // Load entry module and return exports
  39. /******/ return __webpack_require__(0);
  40. /******/ })
  41. /************************************************************************/
  42. /******/ ([
  43. /* 0 */
  44. /***/ function(module, exports, __webpack_require__) {
  45. var __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_RESULT__ = function (require) {
  46. var echarts = __webpack_require__(1);
  47. echarts.dataTool = {
  48. version: '1.0.0',
  49. gexf: __webpack_require__(5),
  50. prepareBoxplotData: __webpack_require__(6)
  51. };
  52. return echarts.dataTool;
  53. }.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  54. /***/ },
  55. /* 1 */
  56. /***/ function(module, exports) {
  57. module.exports = __WEBPACK_EXTERNAL_MODULE_1__;
  58. /***/ },
  59. /* 2 */,
  60. /* 3 */,
  61. /* 4 */,
  62. /* 5 */
  63. /***/ function(module, exports, __webpack_require__) {
  64. var __WEBPACK_AMD_DEFINE_RESULT__;// GEXF File Parser
  65. // http://gexf.net/1.2draft/gexf-12draft-primer.pdf
  66. !(__WEBPACK_AMD_DEFINE_RESULT__ = function (require) {
  67. 'use strict';
  68. var zrUtil = __webpack_require__(1).util;
  69. function parse(xml) {
  70. var doc;
  71. if (typeof xml === 'string') {
  72. var parser = new DOMParser();
  73. doc = parser.parseFromString(xml, 'text/xml');
  74. }
  75. else {
  76. doc = xml;
  77. }
  78. if (!doc || doc.getElementsByTagName('parsererror').length) {
  79. return null;
  80. }
  81. var gexfRoot = getChildByTagName(doc, 'gexf');
  82. if (!gexfRoot) {
  83. return null;
  84. }
  85. var graphRoot = getChildByTagName(gexfRoot, 'graph');
  86. var attributes = parseAttributes(getChildByTagName(graphRoot, 'attributes'));
  87. var attributesMap = {};
  88. for (var i = 0; i < attributes.length; i++) {
  89. attributesMap[attributes[i].id] = attributes[i];
  90. }
  91. return {
  92. nodes: parseNodes(getChildByTagName(graphRoot, 'nodes'), attributesMap),
  93. links: parseEdges(getChildByTagName(graphRoot, 'edges'))
  94. };
  95. }
  96. function parseAttributes(parent) {
  97. return parent ? zrUtil.map(getChildrenByTagName(parent, 'attribute'), function (attribDom) {
  98. return {
  99. id: getAttr(attribDom, 'id'),
  100. title: getAttr(attribDom, 'title'),
  101. type: getAttr(attribDom, 'type')
  102. };
  103. }) : [];
  104. }
  105. function parseNodes(parent, attributesMap) {
  106. return parent ? zrUtil.map(getChildrenByTagName(parent, 'node'), function (nodeDom) {
  107. var id = getAttr(nodeDom, 'id');
  108. var label = getAttr(nodeDom, 'label');
  109. var node = {
  110. id: id,
  111. name: label,
  112. itemStyle: {
  113. normal: {}
  114. }
  115. };
  116. var vizSizeDom = getChildByTagName(nodeDom, 'viz:size');
  117. var vizPosDom = getChildByTagName(nodeDom, 'viz:position');
  118. var vizColorDom = getChildByTagName(nodeDom, 'viz:color');
  119. // var vizShapeDom = getChildByTagName(nodeDom, 'viz:shape');
  120. var attvaluesDom = getChildByTagName(nodeDom, 'attvalues');
  121. if (vizSizeDom) {
  122. node.symbolSize = parseFloat(getAttr(vizSizeDom, 'value'));
  123. }
  124. if (vizPosDom) {
  125. node.x = parseFloat(getAttr(vizPosDom, 'x'));
  126. node.y = parseFloat(getAttr(vizPosDom, 'y'));
  127. // z
  128. }
  129. if (vizColorDom) {
  130. node.itemStyle.normal.color = 'rgb(' +[
  131. getAttr(vizColorDom, 'r') | 0,
  132. getAttr(vizColorDom, 'g') | 0,
  133. getAttr(vizColorDom, 'b') | 0
  134. ].join(',') + ')';
  135. }
  136. // if (vizShapeDom) {
  137. // node.shape = getAttr(vizShapeDom, 'shape');
  138. // }
  139. if (attvaluesDom) {
  140. var attvalueDomList = getChildrenByTagName(attvaluesDom, 'attvalue');
  141. node.attributes = {};
  142. for (var j = 0; j < attvalueDomList.length; j++) {
  143. var attvalueDom = attvalueDomList[j];
  144. var attId = getAttr(attvalueDom, 'for');
  145. var attValue = getAttr(attvalueDom, 'value');
  146. var attribute = attributesMap[attId];
  147. if (attribute) {
  148. switch (attribute.type) {
  149. case 'integer':
  150. case 'long':
  151. attValue = parseInt(attValue, 10);
  152. break;
  153. case 'float':
  154. case 'double':
  155. attValue = parseFloat(attValue);
  156. break;
  157. case 'boolean':
  158. attValue = attValue.toLowerCase() == 'true';
  159. break;
  160. default:
  161. }
  162. node.attributes[attId] = attValue;
  163. }
  164. }
  165. }
  166. return node;
  167. }) : [];
  168. }
  169. function parseEdges(parent) {
  170. return parent ? zrUtil.map(getChildrenByTagName(parent, 'edge'), function (edgeDom) {
  171. var id = getAttr(edgeDom, 'id');
  172. var label = getAttr(edgeDom, 'label');
  173. var sourceId = getAttr(edgeDom, 'source');
  174. var targetId = getAttr(edgeDom, 'target');
  175. var edge = {
  176. id: id,
  177. name: label,
  178. source: sourceId,
  179. target: targetId,
  180. lineStyle: {
  181. normal: {}
  182. }
  183. };
  184. var lineStyle = edge.lineStyle.normal;
  185. var vizThicknessDom = getChildByTagName(edgeDom, 'viz:thickness');
  186. var vizColorDom = getChildByTagName(edgeDom, 'viz:color');
  187. // var vizShapeDom = getChildByTagName(edgeDom, 'viz:shape');
  188. if (vizThicknessDom) {
  189. lineStyle.width = parseFloat(vizThicknessDom.getAttribute('value'));
  190. }
  191. if (vizColorDom) {
  192. lineStyle.color = 'rgb(' + [
  193. getAttr(vizColorDom, 'r') | 0,
  194. getAttr(vizColorDom, 'g') | 0,
  195. getAttr(vizColorDom, 'b') | 0
  196. ].join(',') + ')';
  197. }
  198. // if (vizShapeDom) {
  199. // edge.shape = vizShapeDom.getAttribute('shape');
  200. // }
  201. return edge;
  202. }) : [];
  203. }
  204. function getAttr(el, attrName) {
  205. return el.getAttribute(attrName);
  206. }
  207. function getChildByTagName (parent, tagName) {
  208. var node = parent.firstChild;
  209. while (node) {
  210. if (
  211. node.nodeType != 1 ||
  212. node.nodeName.toLowerCase() != tagName.toLowerCase()
  213. ) {
  214. node = node.nextSibling;
  215. } else {
  216. return node;
  217. }
  218. }
  219. return null;
  220. }
  221. function getChildrenByTagName (parent, tagName) {
  222. var node = parent.firstChild;
  223. var children = [];
  224. while (node) {
  225. if (node.nodeName.toLowerCase() == tagName.toLowerCase()) {
  226. children.push(node);
  227. }
  228. node = node.nextSibling;
  229. }
  230. return children;
  231. }
  232. return {
  233. parse: parse
  234. };
  235. }.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  236. /***/ },
  237. /* 6 */
  238. /***/ function(module, exports, __webpack_require__) {
  239. var __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_RESULT__ = function (require) {
  240. var quantile = __webpack_require__(7);
  241. var numberUtil = __webpack_require__(1).number;
  242. /**
  243. * Helper method for preparing data.
  244. * @param {Array.<number>} rawData like
  245. * [
  246. * [12,232,443], (raw data set for the first box)
  247. * [3843,5545,1232], (raw datat set for the second box)
  248. * ...
  249. * ]
  250. * @param {Object} [opt]
  251. *
  252. * @param {(number|string)} [opt.boundIQR=1.5] Data less than min bound is outlier.
  253. * default 1.5, means Q1 - 1.5 * (Q3 - Q1).
  254. * If pass 'none', min bound will not be used.
  255. * @param {(number|string)} [opt.layout='horizontal']
  256. * Box plot layout, can be 'horizontal' or 'vertical'
  257. */
  258. return function (rawData, opt) {
  259. opt = opt || [];
  260. var boxData = [];
  261. var outliers = [];
  262. var axisData = [];
  263. var boundIQR = opt.boundIQR;
  264. for (var i = 0; i < rawData.length; i++) {
  265. axisData.push(i + '');
  266. var ascList = numberUtil.asc(rawData[i].slice());
  267. var Q1 = quantile(ascList, 0.25);
  268. var Q2 = quantile(ascList, 0.5);
  269. var Q3 = quantile(ascList, 0.75);
  270. var IQR = Q3 - Q1;
  271. var low = boundIQR === 'none'
  272. ? ascList[0]
  273. : Q1 - (boundIQR == null ? 1.5 : boundIQR) * IQR;
  274. var high = boundIQR === 'none'
  275. ? ascList[ascList.length - 1]
  276. : Q3 + (boundIQR == null ? 1.5 : boundIQR) * IQR;
  277. boxData.push([low, Q1, Q2, Q3, high]);
  278. for (var j = 0; j < ascList.length; j++) {
  279. var dataItem = ascList[j];
  280. if (dataItem < low || dataItem > high) {
  281. var outlier = [i, dataItem];
  282. opt.layout === 'vertical' && outlier.reverse();
  283. outliers.push(outlier);
  284. }
  285. }
  286. }
  287. return {
  288. boxData: boxData,
  289. outliers: outliers,
  290. axisData: axisData
  291. };
  292. };
  293. }.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  294. /***/ },
  295. /* 7 */
  296. /***/ function(module, exports, __webpack_require__) {
  297. var __WEBPACK_AMD_DEFINE_RESULT__;/**
  298. * Copyright (c) 2010-2015, Michael Bostock
  299. * All rights reserved.
  300. *
  301. * Redistribution and use in source and binary forms, with or without
  302. * modification, are permitted provided that the following conditions are met:
  303. *
  304. * * Redistributions of source code must retain the above copyright notice, this
  305. * list of conditions and the following disclaimer.
  306. *
  307. * * Redistributions in binary form must reproduce the above copyright notice,
  308. * this list of conditions and the following disclaimer in the documentation
  309. * and/or other materials provided with the distribution.
  310. *
  311. * * The name Michael Bostock may not be used to endorse or promote products
  312. * derived from this software without specific prior written permission.
  313. *
  314. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  315. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  316. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  317. * DISCLAIMED. IN NO EVENT SHALL MICHAEL BOSTOCK BE LIABLE FOR ANY DIRECT,
  318. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  319. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  320. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  321. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  322. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  323. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  324. */
  325. !(__WEBPACK_AMD_DEFINE_RESULT__ = function (require) {
  326. /**
  327. * @see <https://github.com/mbostock/d3/blob/master/src/arrays/quantile.js>
  328. * @see <http://en.wikipedia.org/wiki/Quantile>
  329. * @param {Array.<number>} ascArr
  330. */
  331. return function(ascArr, p) {
  332. var H = (ascArr.length - 1) * p + 1,
  333. h = Math.floor(H),
  334. v = +ascArr[h - 1],
  335. e = H - h;
  336. return e ? v + e * (ascArr[h] - v) : v;
  337. };
  338. }.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  339. /***/ }
  340. /******/ ])
  341. });
  342. ;