(datas: SeriesData[], statisticType: MapValueCalculationType)
| 26 | |
| 27 | // FIXME 公用? |
| 28 | function dataStatistics(datas: SeriesData[], statisticType: MapValueCalculationType): SeriesData { |
| 29 | const dataNameMap = {} as {[mapKey: string]: number[]}; |
| 30 | |
| 31 | zrUtil.each(datas, function (data) { |
| 32 | data.each(data.mapDimension('value'), function (value: number, idx) { |
| 33 | // Add prefix to avoid conflict with Object.prototype. |
| 34 | const mapKey = 'ec-' + data.getName(idx); |
| 35 | dataNameMap[mapKey] = dataNameMap[mapKey] || []; |
| 36 | if (!isNaN(value)) { |
| 37 | dataNameMap[mapKey].push(value); |
| 38 | } |
| 39 | }); |
| 40 | }); |
| 41 | |
| 42 | return datas[0].map(datas[0].mapDimension('value'), function (value, idx) { |
| 43 | const mapKey = 'ec-' + datas[0].getName(idx); |
| 44 | let sum = 0; |
| 45 | let min = Infinity; |
| 46 | let max = -Infinity; |
| 47 | const len = dataNameMap[mapKey].length; |
| 48 | for (let i = 0; i < len; i++) { |
| 49 | min = Math.min(min, dataNameMap[mapKey][i]); |
| 50 | max = Math.max(max, dataNameMap[mapKey][i]); |
| 51 | sum += dataNameMap[mapKey][i]; |
| 52 | } |
| 53 | let result; |
| 54 | if (statisticType === 'min') { |
| 55 | result = min; |
| 56 | } |
| 57 | else if (statisticType === 'max') { |
| 58 | result = max; |
| 59 | } |
| 60 | else if (statisticType === 'average') { |
| 61 | result = sum / len; |
| 62 | } |
| 63 | else { |
| 64 | result = sum; |
| 65 | } |
| 66 | return len === 0 ? NaN : result; |
| 67 | }); |
| 68 | } |
| 69 | |
| 70 | export const mapDataStatisticStageHandler = createSimpleOverallStageHandler(SERIES_TYPE_MAP, mapDataStatistic); |
| 71 |
no test coverage detected
searching dependent graphs…