update labels

This commit is contained in:
Fine 2022-10-28 19:53:34 +08:00
parent 225018db2b
commit b4fa0202f9
3 changed files with 25 additions and 37 deletions

View File

@ -368,17 +368,12 @@ export function usePodsSource(
config.metricTypes[index] === MetricQueryTypes.ReadLabeledMetricsValues config.metricTypes[index] === MetricQueryTypes.ReadLabeledMetricsValues
) { ) {
const resVal = resp.data[key] || []; const resVal = resp.data[key] || [];
const labels = (c.label || "")
.split(",") for (let i = 0; i < resVal.length; i++) {
.map((item: string) => item.replace(/^\s*|\s*$/g, "")); const item = resVal[i];
const labelsIdx = (c.labelsIndex || "")
.split(",")
.map((item: string) => item.replace(/^\s*|\s*$/g, ""));
for (const item of resVal) {
const values = item.values.values.map((d: { value: number }) => const values = item.values.values.map((d: { value: number }) =>
aggregation(Number(d.value), c) aggregation(Number(d.value), c)
); );
const indexNum = labelsIdx.findIndex((d: string) => d === item.label);
if ( if (
[ [
Calculations.Average, Calculations.Average,
@ -386,38 +381,19 @@ export function usePodsSource(
Calculations.PercentageAvg, Calculations.PercentageAvg,
].includes(c.calculation) ].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]) { if (!d[item.label]) {
d[item.label] = {}; d[item.label] = {};
} }
d[item.label]["values"] = values; d[item.label]["avg"] = calculateExp(item.values.values, c);
if (idx === 0) { }
names.push(item.label); if (!d[item.label]) {
metricConfigArr.push(c); d[item.label] = {};
metricTypesArr.push(config.metricTypes[index]); }
} d[item.label]["values"] = values;
if (idx === 0) {
names.push(item.label);
metricConfigArr.push({ ...c, index: i });
metricTypesArr.push(config.metricTypes[index]);
} }
} }
} }

View File

@ -74,6 +74,7 @@ export type MetricConfigOpt = {
labelsIndex: string; labelsIndex: string;
sortOrder: string; sortOrder: string;
topN?: number; topN?: number;
index?: number;
}; };
export interface WidgetConfig { export interface WidgetConfig {

View File

@ -90,6 +90,7 @@ import { MetricConfigOpt } from "@/types/dashboard";
import { useListConfig } from "@/hooks/useListConfig"; import { useListConfig } from "@/hooks/useListConfig";
import Line from "../Line.vue"; import Line from "../Line.vue";
import Card from "../Card.vue"; import Card from "../Card.vue";
import { MetricQueryTypes } from "@/hooks/data";
/*global defineProps */ /*global defineProps */
const props = defineProps({ const props = defineProps({
@ -124,6 +125,16 @@ function getLabel(metric: string, index: string) {
props.config.metricConfig[i] && props.config.metricConfig[i] &&
props.config.metricConfig[i].label; props.config.metricConfig[i].label;
if (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(label);
} }
return encodeURIComponent(metric); return encodeURIComponent(metric);