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
) {
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,41 +381,22 @@ 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);
metricConfigArr.push({ ...c, index: i });
metricTypesArr.push(config.metricTypes[index]);
}
}
}
}
});
return d;
});

View File

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

View File

@ -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);