61c5508e3573ee986394315d6e02137689604a74.svn-base 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. define('echarts/chart/line', [
  2. 'require',
  3. './base',
  4. 'zrender/shape/Polyline',
  5. '../util/shape/Icon',
  6. '../util/shape/HalfSmoothPolygon',
  7. '../component/axis',
  8. '../component/grid',
  9. '../component/dataZoom',
  10. '../config',
  11. '../util/ecData',
  12. 'zrender/tool/util',
  13. 'zrender/tool/color',
  14. '../chart'
  15. ], function (require) {
  16. var ChartBase = require('./base');
  17. var PolylineShape = require('zrender/shape/Polyline');
  18. var IconShape = require('../util/shape/Icon');
  19. var HalfSmoothPolygonShape = require('../util/shape/HalfSmoothPolygon');
  20. require('../component/axis');
  21. require('../component/grid');
  22. require('../component/dataZoom');
  23. var ecConfig = require('../config');
  24. ecConfig.line = {
  25. zlevel: 0,
  26. z: 2,
  27. clickable: true,
  28. legendHoverLink: true,
  29. xAxisIndex: 0,
  30. yAxisIndex: 0,
  31. dataFilter: 'nearest',
  32. itemStyle: {
  33. normal: {
  34. label: { show: false },
  35. lineStyle: {
  36. width: 2,
  37. type: 'solid',
  38. shadowColor: 'rgba(0,0,0,0)',
  39. shadowBlur: 0,
  40. shadowOffsetX: 0,
  41. shadowOffsetY: 0
  42. }
  43. },
  44. emphasis: { label: { show: false } }
  45. },
  46. symbolSize: 2,
  47. showAllSymbol: false
  48. };
  49. var ecData = require('../util/ecData');
  50. var zrUtil = require('zrender/tool/util');
  51. var zrColor = require('zrender/tool/color');
  52. function Line(ecTheme, messageCenter, zr, option, myChart) {
  53. ChartBase.call(this, ecTheme, messageCenter, zr, option, myChart);
  54. this.refresh(option);
  55. }
  56. Line.prototype = {
  57. type: ecConfig.CHART_TYPE_LINE,
  58. _buildShape: function () {
  59. this.finalPLMap = {};
  60. this._buildPosition();
  61. },
  62. _buildHorizontal: function (seriesArray, maxDataLength, locationMap, xMarkMap) {
  63. var series = this.series;
  64. var seriesIndex = locationMap[0][0];
  65. var serie = series[seriesIndex];
  66. var categoryAxis = this.component.xAxis.getAxis(serie.xAxisIndex || 0);
  67. var valueAxis;
  68. var x;
  69. var y;
  70. var lastYP;
  71. var baseYP;
  72. var lastYN;
  73. var baseYN;
  74. var curPLMap = {};
  75. var data;
  76. var value;
  77. for (var i = 0, l = maxDataLength; i < l; i++) {
  78. if (categoryAxis.getNameByIndex(i) == null) {
  79. break;
  80. }
  81. x = categoryAxis.getCoordByIndex(i);
  82. for (var j = 0, k = locationMap.length; j < k; j++) {
  83. valueAxis = this.component.yAxis.getAxis(series[locationMap[j][0]].yAxisIndex || 0);
  84. baseYP = lastYP = baseYN = lastYN = valueAxis.getCoord(0);
  85. for (var m = 0, n = locationMap[j].length; m < n; m++) {
  86. seriesIndex = locationMap[j][m];
  87. serie = series[seriesIndex];
  88. data = serie.data[i];
  89. value = this.getDataFromOption(data, '-');
  90. curPLMap[seriesIndex] = curPLMap[seriesIndex] || [];
  91. xMarkMap[seriesIndex] = xMarkMap[seriesIndex] || {
  92. min: Number.POSITIVE_INFINITY,
  93. max: Number.NEGATIVE_INFINITY,
  94. sum: 0,
  95. counter: 0,
  96. average: 0
  97. };
  98. if (value === '-') {
  99. if (curPLMap[seriesIndex].length > 0) {
  100. this.finalPLMap[seriesIndex] = this.finalPLMap[seriesIndex] || [];
  101. this.finalPLMap[seriesIndex].push(curPLMap[seriesIndex]);
  102. curPLMap[seriesIndex] = [];
  103. }
  104. continue;
  105. }
  106. if (value >= 0) {
  107. lastYP -= m > 0 ? valueAxis.getCoordSize(value) : baseYP - valueAxis.getCoord(value);
  108. y = lastYP;
  109. } else if (value < 0) {
  110. lastYN += m > 0 ? valueAxis.getCoordSize(value) : valueAxis.getCoord(value) - baseYN;
  111. y = lastYN;
  112. }
  113. curPLMap[seriesIndex].push([
  114. x,
  115. y,
  116. i,
  117. categoryAxis.getNameByIndex(i),
  118. x,
  119. baseYP
  120. ]);
  121. if (xMarkMap[seriesIndex].min > value) {
  122. xMarkMap[seriesIndex].min = value;
  123. xMarkMap[seriesIndex].minY = y;
  124. xMarkMap[seriesIndex].minX = x;
  125. }
  126. if (xMarkMap[seriesIndex].max < value) {
  127. xMarkMap[seriesIndex].max = value;
  128. xMarkMap[seriesIndex].maxY = y;
  129. xMarkMap[seriesIndex].maxX = x;
  130. }
  131. xMarkMap[seriesIndex].sum += value;
  132. xMarkMap[seriesIndex].counter++;
  133. }
  134. }
  135. lastYP = this.component.grid.getY();
  136. var symbolSize;
  137. for (var j = 0, k = locationMap.length; j < k; j++) {
  138. for (var m = 0, n = locationMap[j].length; m < n; m++) {
  139. seriesIndex = locationMap[j][m];
  140. serie = series[seriesIndex];
  141. data = serie.data[i];
  142. value = this.getDataFromOption(data, '-');
  143. if (value != '-') {
  144. continue;
  145. }
  146. if (this.deepQuery([
  147. data,
  148. serie,
  149. this.option
  150. ], 'calculable')) {
  151. symbolSize = this.deepQuery([
  152. data,
  153. serie
  154. ], 'symbolSize');
  155. lastYP += symbolSize * 2 + 5;
  156. y = lastYP;
  157. this.shapeList.push(this._getCalculableItem(seriesIndex, i, categoryAxis.getNameByIndex(i), x, y, 'horizontal'));
  158. }
  159. }
  160. }
  161. }
  162. for (var sId in curPLMap) {
  163. if (curPLMap[sId].length > 0) {
  164. this.finalPLMap[sId] = this.finalPLMap[sId] || [];
  165. this.finalPLMap[sId].push(curPLMap[sId]);
  166. curPLMap[sId] = [];
  167. }
  168. }
  169. this._calculMarkMapXY(xMarkMap, locationMap, 'y');
  170. this._buildBorkenLine(seriesArray, this.finalPLMap, categoryAxis, 'horizontal');
  171. },
  172. _buildVertical: function (seriesArray, maxDataLength, locationMap, xMarkMap) {
  173. var series = this.series;
  174. var seriesIndex = locationMap[0][0];
  175. var serie = series[seriesIndex];
  176. var categoryAxis = this.component.yAxis.getAxis(serie.yAxisIndex || 0);
  177. var valueAxis;
  178. var x;
  179. var y;
  180. var lastXP;
  181. var baseXP;
  182. var lastXN;
  183. var baseXN;
  184. var curPLMap = {};
  185. var data;
  186. var value;
  187. for (var i = 0, l = maxDataLength; i < l; i++) {
  188. if (categoryAxis.getNameByIndex(i) == null) {
  189. break;
  190. }
  191. y = categoryAxis.getCoordByIndex(i);
  192. for (var j = 0, k = locationMap.length; j < k; j++) {
  193. valueAxis = this.component.xAxis.getAxis(series[locationMap[j][0]].xAxisIndex || 0);
  194. baseXP = lastXP = baseXN = lastXN = valueAxis.getCoord(0);
  195. for (var m = 0, n = locationMap[j].length; m < n; m++) {
  196. seriesIndex = locationMap[j][m];
  197. serie = series[seriesIndex];
  198. data = serie.data[i];
  199. value = this.getDataFromOption(data, '-');
  200. curPLMap[seriesIndex] = curPLMap[seriesIndex] || [];
  201. xMarkMap[seriesIndex] = xMarkMap[seriesIndex] || {
  202. min: Number.POSITIVE_INFINITY,
  203. max: Number.NEGATIVE_INFINITY,
  204. sum: 0,
  205. counter: 0,
  206. average: 0
  207. };
  208. if (value === '-') {
  209. if (curPLMap[seriesIndex].length > 0) {
  210. this.finalPLMap[seriesIndex] = this.finalPLMap[seriesIndex] || [];
  211. this.finalPLMap[seriesIndex].push(curPLMap[seriesIndex]);
  212. curPLMap[seriesIndex] = [];
  213. }
  214. continue;
  215. }
  216. if (value >= 0) {
  217. lastXP += m > 0 ? valueAxis.getCoordSize(value) : valueAxis.getCoord(value) - baseXP;
  218. x = lastXP;
  219. } else if (value < 0) {
  220. lastXN -= m > 0 ? valueAxis.getCoordSize(value) : baseXN - valueAxis.getCoord(value);
  221. x = lastXN;
  222. }
  223. curPLMap[seriesIndex].push([
  224. x,
  225. y,
  226. i,
  227. categoryAxis.getNameByIndex(i),
  228. baseXP,
  229. y
  230. ]);
  231. if (xMarkMap[seriesIndex].min > value) {
  232. xMarkMap[seriesIndex].min = value;
  233. xMarkMap[seriesIndex].minX = x;
  234. xMarkMap[seriesIndex].minY = y;
  235. }
  236. if (xMarkMap[seriesIndex].max < value) {
  237. xMarkMap[seriesIndex].max = value;
  238. xMarkMap[seriesIndex].maxX = x;
  239. xMarkMap[seriesIndex].maxY = y;
  240. }
  241. xMarkMap[seriesIndex].sum += value;
  242. xMarkMap[seriesIndex].counter++;
  243. }
  244. }
  245. lastXP = this.component.grid.getXend();
  246. var symbolSize;
  247. for (var j = 0, k = locationMap.length; j < k; j++) {
  248. for (var m = 0, n = locationMap[j].length; m < n; m++) {
  249. seriesIndex = locationMap[j][m];
  250. serie = series[seriesIndex];
  251. data = serie.data[i];
  252. value = this.getDataFromOption(data, '-');
  253. if (value != '-') {
  254. continue;
  255. }
  256. if (this.deepQuery([
  257. data,
  258. serie,
  259. this.option
  260. ], 'calculable')) {
  261. symbolSize = this.deepQuery([
  262. data,
  263. serie
  264. ], 'symbolSize');
  265. lastXP -= symbolSize * 2 + 5;
  266. x = lastXP;
  267. this.shapeList.push(this._getCalculableItem(seriesIndex, i, categoryAxis.getNameByIndex(i), x, y, 'vertical'));
  268. }
  269. }
  270. }
  271. }
  272. for (var sId in curPLMap) {
  273. if (curPLMap[sId].length > 0) {
  274. this.finalPLMap[sId] = this.finalPLMap[sId] || [];
  275. this.finalPLMap[sId].push(curPLMap[sId]);
  276. curPLMap[sId] = [];
  277. }
  278. }
  279. this._calculMarkMapXY(xMarkMap, locationMap, 'x');
  280. this._buildBorkenLine(seriesArray, this.finalPLMap, categoryAxis, 'vertical');
  281. },
  282. _buildOther: function (seriesArray, maxDataLength, locationMap, xMarkMap) {
  283. var series = this.series;
  284. var curPLMap = {};
  285. var xAxis;
  286. for (var j = 0, k = locationMap.length; j < k; j++) {
  287. for (var m = 0, n = locationMap[j].length; m < n; m++) {
  288. var seriesIndex = locationMap[j][m];
  289. var serie = series[seriesIndex];
  290. xAxis = this.component.xAxis.getAxis(serie.xAxisIndex || 0);
  291. var yAxis = this.component.yAxis.getAxis(serie.yAxisIndex || 0);
  292. var baseY = yAxis.getCoord(0);
  293. curPLMap[seriesIndex] = curPLMap[seriesIndex] || [];
  294. xMarkMap[seriesIndex] = xMarkMap[seriesIndex] || {
  295. min0: Number.POSITIVE_INFINITY,
  296. min1: Number.POSITIVE_INFINITY,
  297. max0: Number.NEGATIVE_INFINITY,
  298. max1: Number.NEGATIVE_INFINITY,
  299. sum0: 0,
  300. sum1: 0,
  301. counter0: 0,
  302. counter1: 0,
  303. average0: 0,
  304. average1: 0
  305. };
  306. for (var i = 0, l = serie.data.length; i < l; i++) {
  307. var data = serie.data[i];
  308. var value = this.getDataFromOption(data, '-');
  309. if (!(value instanceof Array)) {
  310. continue;
  311. }
  312. var x = xAxis.getCoord(value[0]);
  313. var y = yAxis.getCoord(value[1]);
  314. curPLMap[seriesIndex].push([
  315. x,
  316. y,
  317. i,
  318. value[0],
  319. x,
  320. baseY
  321. ]);
  322. if (xMarkMap[seriesIndex].min0 > value[0]) {
  323. xMarkMap[seriesIndex].min0 = value[0];
  324. xMarkMap[seriesIndex].minY0 = y;
  325. xMarkMap[seriesIndex].minX0 = x;
  326. }
  327. if (xMarkMap[seriesIndex].max0 < value[0]) {
  328. xMarkMap[seriesIndex].max0 = value[0];
  329. xMarkMap[seriesIndex].maxY0 = y;
  330. xMarkMap[seriesIndex].maxX0 = x;
  331. }
  332. xMarkMap[seriesIndex].sum0 += value[0];
  333. xMarkMap[seriesIndex].counter0++;
  334. if (xMarkMap[seriesIndex].min1 > value[1]) {
  335. xMarkMap[seriesIndex].min1 = value[1];
  336. xMarkMap[seriesIndex].minY1 = y;
  337. xMarkMap[seriesIndex].minX1 = x;
  338. }
  339. if (xMarkMap[seriesIndex].max1 < value[1]) {
  340. xMarkMap[seriesIndex].max1 = value[1];
  341. xMarkMap[seriesIndex].maxY1 = y;
  342. xMarkMap[seriesIndex].maxX1 = x;
  343. }
  344. xMarkMap[seriesIndex].sum1 += value[1];
  345. xMarkMap[seriesIndex].counter1++;
  346. }
  347. }
  348. }
  349. for (var sId in curPLMap) {
  350. if (curPLMap[sId].length > 0) {
  351. this.finalPLMap[sId] = this.finalPLMap[sId] || [];
  352. this.finalPLMap[sId].push(curPLMap[sId]);
  353. curPLMap[sId] = [];
  354. }
  355. }
  356. this._calculMarkMapXY(xMarkMap, locationMap, 'xy');
  357. this._buildBorkenLine(seriesArray, this.finalPLMap, xAxis, 'other');
  358. },
  359. _buildBorkenLine: function (seriesArray, pointList, categoryAxis, curOrient) {
  360. var orient = curOrient == 'other' ? 'horizontal' : curOrient;
  361. var series = this.series;
  362. var data;
  363. for (var sIdx = seriesArray.length - 1; sIdx >= 0; sIdx--) {
  364. var seriesIndex = seriesArray[sIdx];
  365. var serie = series[seriesIndex];
  366. var seriesPL = pointList[seriesIndex];
  367. if (serie.type === this.type && seriesPL != null) {
  368. var bbox = this._getBbox(seriesIndex, orient);
  369. var defaultColor = this._sIndex2ColorMap[seriesIndex];
  370. var lineWidth = this.query(serie, 'itemStyle.normal.lineStyle.width');
  371. var lineType = this.query(serie, 'itemStyle.normal.lineStyle.type');
  372. var lineColor = this.query(serie, 'itemStyle.normal.lineStyle.color');
  373. var normalColor = this.getItemStyleColor(this.query(serie, 'itemStyle.normal.color'), seriesIndex, -1);
  374. var isFill = this.query(serie, 'itemStyle.normal.areaStyle') != null;
  375. var fillNormalColor = this.query(serie, 'itemStyle.normal.areaStyle.color');
  376. for (var i = 0, l = seriesPL.length; i < l; i++) {
  377. var singlePL = seriesPL[i];
  378. var isLarge = curOrient != 'other' && this._isLarge(orient, singlePL);
  379. if (!isLarge) {
  380. for (var j = 0, k = singlePL.length; j < k; j++) {
  381. data = serie.data[singlePL[j][2]];
  382. if (this.deepQuery([
  383. data,
  384. serie,
  385. this.option
  386. ], 'calculable') || this.deepQuery([
  387. data,
  388. serie
  389. ], 'showAllSymbol') || categoryAxis.type === 'categoryAxis' && categoryAxis.isMainAxis(singlePL[j][2]) && this.deepQuery([
  390. data,
  391. serie
  392. ], 'symbol') != 'none') {
  393. this.shapeList.push(this._getSymbol(seriesIndex, singlePL[j][2], singlePL[j][3], singlePL[j][0], singlePL[j][1], orient));
  394. }
  395. }
  396. } else {
  397. singlePL = this._getLargePointList(orient, singlePL, serie.dataFilter);
  398. }
  399. var polylineShape = new PolylineShape({
  400. zlevel: serie.zlevel,
  401. z: serie.z,
  402. style: {
  403. miterLimit: lineWidth,
  404. pointList: singlePL,
  405. strokeColor: lineColor || normalColor || defaultColor,
  406. lineWidth: lineWidth,
  407. lineType: lineType,
  408. smooth: this._getSmooth(serie.smooth),
  409. smoothConstraint: bbox,
  410. shadowColor: this.query(serie, 'itemStyle.normal.lineStyle.shadowColor'),
  411. shadowBlur: this.query(serie, 'itemStyle.normal.lineStyle.shadowBlur'),
  412. shadowOffsetX: this.query(serie, 'itemStyle.normal.lineStyle.shadowOffsetX'),
  413. shadowOffsetY: this.query(serie, 'itemStyle.normal.lineStyle.shadowOffsetY')
  414. },
  415. hoverable: false,
  416. _main: true,
  417. _seriesIndex: seriesIndex,
  418. _orient: orient
  419. });
  420. ecData.pack(polylineShape, series[seriesIndex], seriesIndex, 0, i, series[seriesIndex].name);
  421. this.shapeList.push(polylineShape);
  422. if (isFill) {
  423. var halfSmoothPolygonShape = new HalfSmoothPolygonShape({
  424. zlevel: serie.zlevel,
  425. z: serie.z,
  426. style: {
  427. miterLimit: lineWidth,
  428. pointList: zrUtil.clone(singlePL).concat([
  429. [
  430. singlePL[singlePL.length - 1][4],
  431. singlePL[singlePL.length - 1][5]
  432. ],
  433. [
  434. singlePL[0][4],
  435. singlePL[0][5]
  436. ]
  437. ]),
  438. brushType: 'fill',
  439. smooth: this._getSmooth(serie.smooth),
  440. smoothConstraint: bbox,
  441. color: fillNormalColor ? fillNormalColor : zrColor.alpha(defaultColor, 0.5)
  442. },
  443. highlightStyle: { brushType: 'fill' },
  444. hoverable: false,
  445. _main: true,
  446. _seriesIndex: seriesIndex,
  447. _orient: orient
  448. });
  449. ecData.pack(halfSmoothPolygonShape, series[seriesIndex], seriesIndex, 0, i, series[seriesIndex].name);
  450. this.shapeList.push(halfSmoothPolygonShape);
  451. }
  452. }
  453. }
  454. }
  455. },
  456. _getBbox: function (seriesIndex, orient) {
  457. var bbox = this.component.grid.getBbox();
  458. var xMarkMap = this.xMarkMap[seriesIndex];
  459. if (xMarkMap.minX0 != null) {
  460. return [
  461. [
  462. Math.min(xMarkMap.minX0, xMarkMap.maxX0, xMarkMap.minX1, xMarkMap.maxX1),
  463. Math.min(xMarkMap.minY0, xMarkMap.maxY0, xMarkMap.minY1, xMarkMap.maxY1)
  464. ],
  465. [
  466. Math.max(xMarkMap.minX0, xMarkMap.maxX0, xMarkMap.minX1, xMarkMap.maxX1),
  467. Math.max(xMarkMap.minY0, xMarkMap.maxY0, xMarkMap.minY1, xMarkMap.maxY1)
  468. ]
  469. ];
  470. } else if (orient === 'horizontal') {
  471. bbox[0][1] = Math.min(xMarkMap.minY, xMarkMap.maxY);
  472. bbox[1][1] = Math.max(xMarkMap.minY, xMarkMap.maxY);
  473. } else {
  474. bbox[0][0] = Math.min(xMarkMap.minX, xMarkMap.maxX);
  475. bbox[1][0] = Math.max(xMarkMap.minX, xMarkMap.maxX);
  476. }
  477. return bbox;
  478. },
  479. _isLarge: function (orient, singlePL) {
  480. if (singlePL.length < 2) {
  481. return false;
  482. } else {
  483. return orient === 'horizontal' ? Math.abs(singlePL[0][0] - singlePL[1][0]) < 0.5 : Math.abs(singlePL[0][1] - singlePL[1][1]) < 0.5;
  484. }
  485. },
  486. _getLargePointList: function (orient, singlePL, filter) {
  487. var total;
  488. if (orient === 'horizontal') {
  489. total = this.component.grid.getWidth();
  490. } else {
  491. total = this.component.grid.getHeight();
  492. }
  493. var len = singlePL.length;
  494. var newList = [];
  495. if (typeof filter != 'function') {
  496. switch (filter) {
  497. case 'min':
  498. filter = function (arr) {
  499. return Math.max.apply(null, arr);
  500. };
  501. break;
  502. case 'max':
  503. filter = function (arr) {
  504. return Math.min.apply(null, arr);
  505. };
  506. break;
  507. case 'average':
  508. filter = function (arr) {
  509. var total = 0;
  510. for (var i = 0; i < arr.length; i++) {
  511. total += arr[i];
  512. }
  513. return total / arr.length;
  514. };
  515. break;
  516. default:
  517. filter = function (arr) {
  518. return arr[0];
  519. };
  520. }
  521. }
  522. var windowData = [];
  523. for (var i = 0; i < total; i++) {
  524. var idx0 = Math.floor(len / total * i);
  525. var idx1 = Math.min(Math.floor(len / total * (i + 1)), len);
  526. if (idx1 <= idx0) {
  527. continue;
  528. }
  529. for (var j = idx0; j < idx1; j++) {
  530. windowData[j - idx0] = orient === 'horizontal' ? singlePL[j][1] : singlePL[j][0];
  531. }
  532. windowData.length = idx1 - idx0;
  533. var filteredVal = filter(windowData);
  534. var nearestIdx = -1;
  535. var minDist = Infinity;
  536. for (var j = idx0; j < idx1; j++) {
  537. var val = orient === 'horizontal' ? singlePL[j][1] : singlePL[j][0];
  538. var dist = Math.abs(val - filteredVal);
  539. if (dist < minDist) {
  540. nearestIdx = j;
  541. minDist = dist;
  542. }
  543. }
  544. var newItem = singlePL[nearestIdx].slice();
  545. if (orient === 'horizontal') {
  546. newItem[1] = filteredVal;
  547. } else {
  548. newItem[0] = filteredVal;
  549. }
  550. newList.push(newItem);
  551. }
  552. return newList;
  553. },
  554. _getSmooth: function (isSmooth) {
  555. if (isSmooth) {
  556. return 0.3;
  557. } else {
  558. return 0;
  559. }
  560. },
  561. _getCalculableItem: function (seriesIndex, dataIndex, name, x, y, orient) {
  562. var series = this.series;
  563. var color = series[seriesIndex].calculableHolderColor || this.ecTheme.calculableHolderColor || ecConfig.calculableHolderColor;
  564. var itemShape = this._getSymbol(seriesIndex, dataIndex, name, x, y, orient);
  565. itemShape.style.color = color;
  566. itemShape.style.strokeColor = color;
  567. itemShape.rotation = [
  568. 0,
  569. 0
  570. ];
  571. itemShape.hoverable = false;
  572. itemShape.draggable = false;
  573. itemShape.style.text = undefined;
  574. return itemShape;
  575. },
  576. _getSymbol: function (seriesIndex, dataIndex, name, x, y, orient) {
  577. var series = this.series;
  578. var serie = series[seriesIndex];
  579. var data = serie.data[dataIndex];
  580. var itemShape = this.getSymbolShape(serie, seriesIndex, data, dataIndex, name, x, y, this._sIndex2ShapeMap[seriesIndex], this._sIndex2ColorMap[seriesIndex], '#fff', orient === 'vertical' ? 'horizontal' : 'vertical');
  581. itemShape.zlevel = serie.zlevel;
  582. itemShape.z = serie.z + 1;
  583. if (this.deepQuery([
  584. data,
  585. serie,
  586. this.option
  587. ], 'calculable')) {
  588. this.setCalculable(itemShape);
  589. itemShape.draggable = true;
  590. }
  591. return itemShape;
  592. },
  593. getMarkCoord: function (seriesIndex, mpData) {
  594. var serie = this.series[seriesIndex];
  595. var xMarkMap = this.xMarkMap[seriesIndex];
  596. var xAxis = this.component.xAxis.getAxis(serie.xAxisIndex);
  597. var yAxis = this.component.yAxis.getAxis(serie.yAxisIndex);
  598. if (mpData.type && (mpData.type === 'max' || mpData.type === 'min' || mpData.type === 'average')) {
  599. var valueIndex = mpData.valueIndex != null ? mpData.valueIndex : xMarkMap.maxX0 != null ? '1' : '';
  600. return [
  601. xMarkMap[mpData.type + 'X' + valueIndex],
  602. xMarkMap[mpData.type + 'Y' + valueIndex],
  603. xMarkMap[mpData.type + 'Line' + valueIndex],
  604. xMarkMap[mpData.type + valueIndex]
  605. ];
  606. }
  607. return [
  608. typeof mpData.xAxis != 'string' && xAxis.getCoordByIndex ? xAxis.getCoordByIndex(mpData.xAxis || 0) : xAxis.getCoord(mpData.xAxis || 0),
  609. typeof mpData.yAxis != 'string' && yAxis.getCoordByIndex ? yAxis.getCoordByIndex(mpData.yAxis || 0) : yAxis.getCoord(mpData.yAxis || 0)
  610. ];
  611. },
  612. refresh: function (newOption) {
  613. if (newOption) {
  614. this.option = newOption;
  615. this.series = newOption.series;
  616. }
  617. this.backupShapeList();
  618. this._buildShape();
  619. },
  620. ontooltipHover: function (param, tipShape) {
  621. var seriesIndex = param.seriesIndex;
  622. var dataIndex = param.dataIndex;
  623. var seriesPL;
  624. var singlePL;
  625. var len = seriesIndex.length;
  626. while (len--) {
  627. seriesPL = this.finalPLMap[seriesIndex[len]];
  628. if (seriesPL) {
  629. for (var i = 0, l = seriesPL.length; i < l; i++) {
  630. singlePL = seriesPL[i];
  631. for (var j = 0, k = singlePL.length; j < k; j++) {
  632. if (dataIndex === singlePL[j][2]) {
  633. tipShape.push(this._getSymbol(seriesIndex[len], singlePL[j][2], singlePL[j][3], singlePL[j][0], singlePL[j][1], 'horizontal'));
  634. }
  635. }
  636. }
  637. }
  638. }
  639. },
  640. addDataAnimation: function (params, done) {
  641. var series = this.series;
  642. var aniMap = {};
  643. for (var i = 0, l = params.length; i < l; i++) {
  644. aniMap[params[i][0]] = params[i];
  645. }
  646. var x;
  647. var dx;
  648. var y;
  649. var dy;
  650. var seriesIndex;
  651. var pointList;
  652. var isHorizontal;
  653. var aniCount = 0;
  654. function animationDone() {
  655. aniCount--;
  656. if (aniCount === 0) {
  657. done && done();
  658. }
  659. }
  660. function animationDuring(target) {
  661. target.style.controlPointList = null;
  662. }
  663. for (var i = this.shapeList.length - 1; i >= 0; i--) {
  664. seriesIndex = this.shapeList[i]._seriesIndex;
  665. if (aniMap[seriesIndex] && !aniMap[seriesIndex][3]) {
  666. if (this.shapeList[i]._main && this.shapeList[i].style.pointList.length > 1) {
  667. pointList = this.shapeList[i].style.pointList;
  668. dx = Math.abs(pointList[0][0] - pointList[1][0]);
  669. dy = Math.abs(pointList[0][1] - pointList[1][1]);
  670. isHorizontal = this.shapeList[i]._orient === 'horizontal';
  671. if (aniMap[seriesIndex][2]) {
  672. if (this.shapeList[i].type === 'half-smooth-polygon') {
  673. var len = pointList.length;
  674. this.shapeList[i].style.pointList[len - 3] = pointList[len - 2];
  675. this.shapeList[i].style.pointList[len - 3][isHorizontal ? 0 : 1] = pointList[len - 4][isHorizontal ? 0 : 1];
  676. this.shapeList[i].style.pointList[len - 2] = pointList[len - 1];
  677. }
  678. this.shapeList[i].style.pointList.pop();
  679. isHorizontal ? (x = dx, y = 0) : (x = 0, y = -dy);
  680. } else {
  681. this.shapeList[i].style.pointList.shift();
  682. if (this.shapeList[i].type === 'half-smooth-polygon') {
  683. var targetPoint = this.shapeList[i].style.pointList.pop();
  684. isHorizontal ? targetPoint[0] = pointList[0][0] : targetPoint[1] = pointList[0][1];
  685. this.shapeList[i].style.pointList.push(targetPoint);
  686. }
  687. isHorizontal ? (x = -dx, y = 0) : (x = 0, y = dy);
  688. }
  689. this.shapeList[i].style.controlPointList = null;
  690. this.zr.modShape(this.shapeList[i]);
  691. } else {
  692. if (aniMap[seriesIndex][2] && this.shapeList[i]._dataIndex === series[seriesIndex].data.length - 1) {
  693. this.zr.delShape(this.shapeList[i].id);
  694. continue;
  695. } else if (!aniMap[seriesIndex][2] && this.shapeList[i]._dataIndex === 0) {
  696. this.zr.delShape(this.shapeList[i].id);
  697. continue;
  698. }
  699. }
  700. this.shapeList[i].position = [
  701. 0,
  702. 0
  703. ];
  704. aniCount++;
  705. this.zr.animate(this.shapeList[i].id, '').when(this.query(this.option, 'animationDurationUpdate'), {
  706. position: [
  707. x,
  708. y
  709. ]
  710. }).during(animationDuring).done(animationDone).start();
  711. }
  712. }
  713. if (!aniCount) {
  714. done && done();
  715. }
  716. }
  717. };
  718. function legendLineIcon(ctx, style, refreshNextFrame) {
  719. var x = style.x;
  720. var y = style.y;
  721. var width = style.width;
  722. var height = style.height;
  723. var dy = height / 2;
  724. if (style.symbol.match('empty')) {
  725. ctx.fillStyle = '#fff';
  726. }
  727. style.brushType = 'both';
  728. var symbol = style.symbol.replace('empty', '').toLowerCase();
  729. if (symbol.match('star')) {
  730. dy = symbol.replace('star', '') - 0 || 5;
  731. y -= 1;
  732. symbol = 'star';
  733. } else if (symbol === 'rectangle' || symbol === 'arrow') {
  734. x += (width - height) / 2;
  735. width = height;
  736. }
  737. var imageLocation = '';
  738. if (symbol.match('image')) {
  739. imageLocation = symbol.replace(new RegExp('^image:\\/\\/'), '');
  740. symbol = 'image';
  741. x += Math.round((width - height) / 2) - 1;
  742. width = height = height + 2;
  743. }
  744. symbol = IconShape.prototype.iconLibrary[symbol];
  745. if (symbol) {
  746. var x2 = style.x;
  747. var y2 = style.y;
  748. ctx.moveTo(x2, y2 + dy);
  749. ctx.lineTo(x2 + 5, y2 + dy);
  750. ctx.moveTo(x2 + style.width - 5, y2 + dy);
  751. ctx.lineTo(x2 + style.width, y2 + dy);
  752. var self = this;
  753. symbol(ctx, {
  754. x: x + 4,
  755. y: y + 4,
  756. width: width - 8,
  757. height: height - 8,
  758. n: dy,
  759. image: imageLocation
  760. }, function () {
  761. self.modSelf();
  762. refreshNextFrame();
  763. });
  764. } else {
  765. ctx.moveTo(x, y + dy);
  766. ctx.lineTo(x + width, y + dy);
  767. }
  768. }
  769. IconShape.prototype.iconLibrary['legendLineIcon'] = legendLineIcon;
  770. zrUtil.inherits(Line, ChartBase);
  771. require('../chart').define('line', Line);
  772. return Line;
  773. });define('echarts/util/shape/HalfSmoothPolygon', [
  774. 'require',
  775. 'zrender/shape/Base',
  776. 'zrender/shape/util/smoothBezier',
  777. 'zrender/tool/util',
  778. 'zrender/shape/Polygon'
  779. ], function (require) {
  780. var Base = require('zrender/shape/Base');
  781. var smoothBezier = require('zrender/shape/util/smoothBezier');
  782. var zrUtil = require('zrender/tool/util');
  783. function HalfSmoothPolygon(options) {
  784. Base.call(this, options);
  785. }
  786. HalfSmoothPolygon.prototype = {
  787. type: 'half-smooth-polygon',
  788. buildPath: function (ctx, style) {
  789. var pointList = style.pointList;
  790. if (pointList.length < 2) {
  791. return;
  792. }
  793. if (style.smooth) {
  794. var controlPoints = smoothBezier(pointList.slice(0, -2), style.smooth, false, style.smoothConstraint);
  795. ctx.moveTo(pointList[0][0], pointList[0][1]);
  796. var cp1;
  797. var cp2;
  798. var p;
  799. var l = pointList.length;
  800. for (var i = 0; i < l - 3; i++) {
  801. cp1 = controlPoints[i * 2];
  802. cp2 = controlPoints[i * 2 + 1];
  803. p = pointList[i + 1];
  804. ctx.bezierCurveTo(cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]);
  805. }
  806. ctx.lineTo(pointList[l - 2][0], pointList[l - 2][1]);
  807. ctx.lineTo(pointList[l - 1][0], pointList[l - 1][1]);
  808. ctx.lineTo(pointList[0][0], pointList[0][1]);
  809. } else {
  810. require('zrender/shape/Polygon').prototype.buildPath(ctx, style);
  811. }
  812. return;
  813. }
  814. };
  815. zrUtil.inherits(HalfSmoothPolygon, Base);
  816. return HalfSmoothPolygon;
  817. });