config.tsx 2.5 KB
Newer Older
G
GraceWalk 已提交
1
import api, { MetricType } from '@src/api';
2
import { getBasicChartConfig, CHART_COLOR_LIST } from '@src/constants/chartConfig';
Z
zengqiao 已提交
3

G
GraceWalk 已提交
4 5 6 7 8 9 10 11 12
const METRIC_DASHBOARD_REQ_MAP = {
  [MetricType.Broker]: (clusterId: string) => api.getDashboardMetricChartData(clusterId, MetricType.Broker),
  [MetricType.Topic]: (clusterId: string) => api.getDashboardMetricChartData(clusterId, MetricType.Topic),
  [MetricType.Zookeeper]: (clusterId: string) => '',
};

export const getMetricDashboardReq = (clusterId: string, type: MetricType.Broker | MetricType.Topic | MetricType.Zookeeper) =>
  METRIC_DASHBOARD_REQ_MAP[type](clusterId);

Z
zengqiao 已提交
13
const seriesCallback = (lines: { name: string; data: [number, string | number][] }[]) => {
G
GraceWalk 已提交
14
  const len = CHART_COLOR_LIST.length;
Z
zengqiao 已提交
15
  // series 配置
G
GraceWalk 已提交
16
  return lines.map((line, i) => {
Z
zengqiao 已提交
17 18
    return {
      ...line,
G
GraceWalk 已提交
19
      z: len - i,
Z
zengqiao 已提交
20
      lineStyle: {
Z
zengqiao 已提交
21
        width: 1.5,
Z
zengqiao 已提交
22
      },
G
GraceWalk 已提交
23
      connectNulls: false,
Z
zengqiao 已提交
24 25
      symbol: 'emptyCircle',
      symbolSize: 4,
Z
zengqiao 已提交
26
      smooth: 0.25,
G
GraceWalk 已提交
27
      color: CHART_COLOR_LIST[i % len],
Z
zengqiao 已提交
28
      areaStyle: {
G
GraceWalk 已提交
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
        color: {
          type: 'linear',
          x: 0,
          y: 0,
          x2: 0,
          y2: 1,
          colorStops: [
            {
              offset: 0,
              color: CHART_COLOR_LIST[i % len] + '10',
            },
            {
              offset: 1,
              color: 'rgba(255,255,255,0)', // 100% 处的颜色
            },
          ],
          global: false, // 缺省为 false
        },
Z
zengqiao 已提交
47
      },
Z
zengqiao 已提交
48 49 50 51 52
    };
  });
};

// 返回图表配置
G
GraceWalk 已提交
53
export const getChartConfig = (title: string, metricLength: number, showLegend = true) => {
Z
zengqiao 已提交
54 55 56
  return {
    option: getBasicChartConfig({
      title: { show: false },
G
GraceWalk 已提交
57
      grid: { top: 24, bottom: showLegend ? 40 : 20 },
Z
zengqiao 已提交
58
      tooltip: { enterable: metricLength > 9, legendContextMaxHeight: 192 },
G
GraceWalk 已提交
59
      legend: { show: showLegend },
Z
zengqiao 已提交
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
    }),
    seriesCallback,
  };
};

export const getDetailChartConfig = (title: string, sliderPos: readonly [number, number]) => {
  return {
    option: getBasicChartConfig({
      title: {
        show: false,
      },
      xAxis: {
        type: 'time',
        boundaryGap: false,
      },
      legend: {
        show: false,
      },
      dataZoom: [
        {
          type: 'inside',
          startValue: sliderPos[0],
          endValue: sliderPos[1],
          zoomOnMouseWheel: false,
G
GraceWalk 已提交
84
          minValueSpan: 10 * 60 * 1000,
Z
zengqiao 已提交
85 86 87 88 89 90 91 92 93 94
        },
        {
          start: 0,
          end: 0,
        },
      ],
    }),
    seriesCallback,
  };
};