riku
2025-07-18 306ef09707d6bcf9ffa67de55f86ab6f4362deee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
 * 将监测数据格式化为e-charts图表数据
 */
import { factorName } from '@/constant/factor-name';
 
function refreshX(factorDatas) {
  const newTimes = factorDatas.times.map((v) => {
    return v.split(' ')[1];
  });
  return newTimes;
}
function refreshY(factorDatas) {
  const allSeries = new Map();
  for (const key in factorDatas.factor) {
    if (Object.hasOwnProperty.call(factorDatas.factor, key)) {
      const e = factorDatas.factor[key];
      if (!allSeries.has(key)) {
        allSeries.set(key, {
          key: key,
          name: factorName[e.factorName],
          label: e.factorName,
          type: 'line',
          data: [],
          showAllSymbol: true,
          animationDelay: function (idx) {
            return idx * 10;
          }
        });
      }
      if (e.datas.length == 0) {
        continue;
      }
      const series = allSeries.get(key);
      // 插入新数据
      const newSeries = e.datas.map((v) => v.factorData);
      series.data = series.data.concat(newSeries);
      // 计算数据范围
      const { min, max } = dataRange(series.data);
      series.min = min;
      series.max = max;
      // 记录最新数据
      series.currentData =
        Math.round(series.data[series.data.length - 1] * 10) / 10;
    }
  }
  return allSeries;
}
 
function dataRange(dataList) {
  let min, max;
  dataList.forEach((e) => {
    if (!min || min > e) {
      min = e;
    }
    if (!max || max < e) {
      max = e;
    }
  });
  return { min, max };
}
function toList(xAxis, allSeries, selectedFactors) {
  const list = [];
  selectedFactors.forEach((t) => {
    if (allSeries.has(t.value)) {
      list.push({
        xAxis: xAxis,
        series: allSeries.get(t.value)
      });
    }
  });
  return list;
}
 
export default {
  parseData(factorDatas, selectedFactors) {
    const xAxis = refreshX(factorDatas);
    const allSeries = refreshY(factorDatas);
    return toList(xAxis, allSeries, selectedFactors);
  }
};