From b4fa0202f9e841300681e836ded7fd8d43f0227d Mon Sep 17 00:00:00 2001 From: Fine Date: Fri, 28 Oct 2022 19:53:34 +0800 Subject: [PATCH] update labels --- src/hooks/useProcessor.ts | 50 +++++-------------- src/types/dashboard.d.ts | 1 + .../graphs/components/ColumnGraph.vue | 11 ++++ 3 files changed, 25 insertions(+), 37 deletions(-) diff --git a/src/hooks/useProcessor.ts b/src/hooks/useProcessor.ts index bc6b17e9..0fa81033 100644 --- a/src/hooks/useProcessor.ts +++ b/src/hooks/useProcessor.ts @@ -368,17 +368,12 @@ export function usePodsSource( config.metricTypes[index] === MetricQueryTypes.ReadLabeledMetricsValues ) { const resVal = resp.data[key] || []; - const labels = (c.label || "") - .split(",") - .map((item: string) => item.replace(/^\s*|\s*$/g, "")); - const labelsIdx = (c.labelsIndex || "") - .split(",") - .map((item: string) => item.replace(/^\s*|\s*$/g, "")); - for (const item of resVal) { + + for (let i = 0; i < resVal.length; i++) { + const item = resVal[i]; const values = item.values.values.map((d: { value: number }) => aggregation(Number(d.value), c) ); - const indexNum = labelsIdx.findIndex((d: string) => d === item.label); if ( [ Calculations.Average, @@ -386,38 +381,19 @@ export function usePodsSource( Calculations.PercentageAvg, ].includes(c.calculation) ) { - if (labels[indexNum] && indexNum > -1) { - if (!d[labels[indexNum]]) { - d[labels[indexNum]] = {}; - } - d[labels[indexNum]]["avg"] = calculateExp(item.values.values, c); - } else { - if (!d[item.label]) { - d[item.label] = {}; - } - d[item.label]["avg"] = calculateExp(item.values.values, c); - } - } - if (labels[indexNum] && indexNum > -1) { - if (!d[labels[indexNum]]) { - d[labels[indexNum]] = {}; - } - d[labels[indexNum]]["values"] = values; - if (idx === 0) { - names.push(labels[indexNum]); - metricConfigArr.push(c); - metricTypesArr.push(config.metricTypes[index]); - } - } else { if (!d[item.label]) { d[item.label] = {}; } - d[item.label]["values"] = values; - if (idx === 0) { - names.push(item.label); - metricConfigArr.push(c); - metricTypesArr.push(config.metricTypes[index]); - } + d[item.label]["avg"] = calculateExp(item.values.values, c); + } + if (!d[item.label]) { + d[item.label] = {}; + } + d[item.label]["values"] = values; + if (idx === 0) { + names.push(item.label); + metricConfigArr.push({ ...c, index: i }); + metricTypesArr.push(config.metricTypes[index]); } } } diff --git a/src/types/dashboard.d.ts b/src/types/dashboard.d.ts index b82afe9a..ceabab34 100644 --- a/src/types/dashboard.d.ts +++ b/src/types/dashboard.d.ts @@ -74,6 +74,7 @@ export type MetricConfigOpt = { labelsIndex: string; sortOrder: string; topN?: number; + index?: number; }; export interface WidgetConfig { diff --git a/src/views/dashboard/graphs/components/ColumnGraph.vue b/src/views/dashboard/graphs/components/ColumnGraph.vue index 33cd5825..5034265b 100644 --- a/src/views/dashboard/graphs/components/ColumnGraph.vue +++ b/src/views/dashboard/graphs/components/ColumnGraph.vue @@ -90,6 +90,7 @@ import { MetricConfigOpt } from "@/types/dashboard"; import { useListConfig } from "@/hooks/useListConfig"; import Line from "../Line.vue"; import Card from "../Card.vue"; +import { MetricQueryTypes } from "@/hooks/data"; /*global defineProps */ const props = defineProps({ @@ -124,6 +125,16 @@ function getLabel(metric: string, index: string) { props.config.metricConfig[i] && props.config.metricConfig[i].label; if (label) { + if ( + props.config.metricTypes[i] === MetricQueryTypes.ReadLabeledMetricsValues + ) { + const name = (label || "") + .split(",") + .map((item: string) => item.replace(/^\s*|\s*$/g, ""))[ + props.config.metricConfig[i].index || 0 + ]; + return encodeURIComponent(name || ""); + } return encodeURIComponent(label); } return encodeURIComponent(metric);