MCPcopy
hub / github.com/apache/echarts / dataStatistics

Function dataStatistics

src/chart/map/mapDataStatistic.ts:28–68  ·  view source on GitHub ↗
(datas: SeriesData[], statisticType: MapValueCalculationType)

Source from the content-addressed store, hash-verified

26
27// FIXME 公用?
28function 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
70export const mapDataStatisticStageHandler = createSimpleOverallStageHandler(SERIES_TYPE_MAP, mapDataStatistic);
71

Callers 1

mapDataStatisticFunction · 0.85

Calls 4

mapDimensionMethod · 0.80
getNameMethod · 0.80
eachMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…