|
| 1 | +function addData(area, axis, setKey) { |
| 2 | + if (axis.type !== "value") { |
| 3 | + area[setKey] = axis.data; |
| 4 | + } else { |
| 5 | + area[setKey] = [ ]; |
| 6 | + } |
| 7 | + return; |
| 8 | +} |
| 9 | + |
| 10 | +// ECharts doesn't send x-axis data in brush events but we need it |
| 11 | +// because sorting algo may be opaque |
| 12 | +function addAxisData(option, e, axisKey, setKey, axisIndexKey) { |
| 13 | + var i, j, gridIndex; |
| 14 | + for (i = 0; i < e.areas.length; i++) { |
| 15 | + gridIndex = parseInt(e.areas[i].panelId.match(/\d+$/g)[0]); |
| 16 | + e.areas[i].gridIndex = gridIndex; |
| 17 | + if (typeof option === "undefined") { |
| 18 | + e.areas[i][setKey] = [ ]; |
| 19 | + e.areas[i][axisIndexKey] = 0; |
| 20 | + } else if (typeof option[axisKey].length === "undefined" && gridIndex === 0) { |
| 21 | + addData(e.areas[i], option[axisKey], setKey); |
| 22 | + e.areas[i][axisIndexKey] = 0; |
| 23 | + } else if (option[axisKey].length === 1 && gridIndex === 0) { |
| 24 | + addData(e.areas[i], option[axisKey][0], setKey); |
| 25 | + e.areas[i][axisIndexKey] = 0; |
| 26 | + } else { |
| 27 | + for (j = 0; j < option[axisKey].length; j++) { |
| 28 | + if (option[axisKey][j].gridIndex === gridIndex) { |
| 29 | + addData(e.areas[i], option[axisKey][j], setKey); |
| 30 | + e.areas[i][axisIndexKey] = j; |
| 31 | + } |
| 32 | + } |
| 33 | + } |
| 34 | + } |
| 35 | + return e; |
| 36 | +} |
| 37 | + |
| 38 | +function addXAxisData(option, e) { |
| 39 | + return addAxisData(option, e, "xAxis", "xAxisData", "xAxisIndex"); |
| 40 | +} |
| 41 | + |
| 42 | +function addYAxisData(option, e) { |
| 43 | + return addAxisData(option, e, "yAxis", "yAxisData", "yAxisIndex"); |
| 44 | +} |
| 45 | + |
| 46 | +function addSeriesAndTitles(option, e) { |
| 47 | + var i, xIx, yIx, serie, ai, area; |
| 48 | + for (ai = 0; ai < e.areas.length; ai++) { |
| 49 | + area = e.areas[ai]; |
| 50 | + area.serieNames = []; |
| 51 | + area.serieIndices = []; |
| 52 | + for (i = 0; i < option.series.length; i++) { |
| 53 | + serie = option.series[i]; |
| 54 | + xIx = serie.xAxisIndex || 0; |
| 55 | + yIx = serie.xAxisIndex || 0; |
| 56 | + if (xIx == area.xAxisIndex && yIx == area.yAxisIndex) { |
| 57 | + area.serieNames.push(serie.name); |
| 58 | + area.serieIndices.push(i); |
| 59 | + } |
| 60 | + } |
| 61 | + } |
| 62 | + var titles, titleTexts = []; |
| 63 | + if (!option.title) { |
| 64 | + titles = []; |
| 65 | + } else if (typeof option.title.length === "undefined") { |
| 66 | + titles = [option.title]; |
| 67 | + } else { |
| 68 | + titles = option.title; |
| 69 | + } |
| 70 | + for (i = 0; i < titles.length; i++) { |
| 71 | + if (titles[i].text) titleTexts.push(titles[i].text); |
| 72 | + } |
| 73 | + e.titleTexts = titleTexts; |
| 74 | + return e; |
| 75 | +} |
| 76 | + |
| 77 | +function addAll(option, e) { |
| 78 | + return addSeriesAndTitles(option, addYAxisData(option, addXAxisData(option, e))); |
| 79 | +} |
| 80 | + |
1 | 81 | exports.on_ = function(chart) { |
2 | 82 | return function(eName) { |
3 | 83 | return function(callback) { |
4 | 84 | return function() { |
5 | 85 | return chart.on(eName, function(e) { |
| 86 | + if (eName === "brush") { |
| 87 | + addAll(this.getOption(), e); |
| 88 | + } |
6 | 89 | callback(e)(); |
7 | | - }); |
| 90 | + }); |
8 | 91 | }; |
9 | 92 | }; |
10 | 93 | }; |
11 | 94 | }; |
| 95 | + |
| 96 | +exports.dispatchAction_ = function(action) { |
| 97 | + return function(chart) { |
| 98 | + return function() { |
| 99 | + return chart.dispatchAction(action); |
| 100 | + }; |
| 101 | + }; |
| 102 | +} |
0 commit comments