This commit is contained in:
Fine 2024-10-17 19:15:25 +08:00
parent d2a17bbfae
commit 18fdd6306c
5 changed files with 23 additions and 24 deletions

View File

@ -123,7 +123,7 @@ export interface CardConfig {
fontSize?: number; fontSize?: number;
showUnit?: boolean; showUnit?: boolean;
textAlign?: "center" | "right" | "left"; textAlign?: "center" | "right" | "left";
decorations?: { [key: string]: string }; valueMappings?: { [key: string]: string };
} }
export interface TextConfig { export interface TextConfig {

View File

@ -32,7 +32,7 @@ limitations under the License. -->
:config="{ :config="{
i: 0, i: 0,
...graph, ...graph,
decorations: graph?.decorations, valueMappings: graph?.valueMappings,
metricConfig: config.metricConfig, metricConfig: config.metricConfig,
expressions: config.expressions || [], expressions: config.expressions || [],
typesOfMQE: typesOfMQE || [], typesOfMQE: typesOfMQE || [],

View File

@ -39,22 +39,22 @@ limitations under the License. -->
const dashboardStore = useDashboardStore(); const dashboardStore = useDashboardStore();
const graph = dashboardStore.selectedGrid.graph; const graph = dashboardStore.selectedGrid.graph;
const decorations = ref<{ [key: string]: string }>(graph?.valueMappings || {}); const valueMappings = ref<{ [key: string]: string }>(graph?.valueMappings || {});
const keys = ref<string[]>(graph.valueMappings ? Object.keys(decorations.value) : [""]); const keys = ref<string[]>(graph.valueMappings ? Object.keys(valueMappings.value) : [""]);
function changeKeys(event: any, index: number) { function changeKeys(event: any, index: number) {
const params = event.target.textContent || ""; const params = event.target.textContent || "";
const list = Object.keys(decorations.value); const list = Object.keys(valueMappings.value);
if (params) { if (params) {
decorations.value[params] = decorations.value[list[index]]; valueMappings.value[params] = valueMappings.value[list[index]];
} }
delete decorations.value[list[index]]; delete valueMappings.value[list[index]];
keys.value = Object.keys(decorations.value); keys.value = Object.keys(valueMappings.value);
updateConfig(); updateConfig();
} }
function changeValues(event: any, key: string) { function changeValues(event: any, key: string) {
decorations.value[key] = event.target.textContent || ""; valueMappings.value[key] = event.target.textContent || "";
updateConfig(); updateConfig();
} }
@ -66,7 +66,7 @@ limitations under the License. -->
if (!keys.value.length) { if (!keys.value.length) {
return; return;
} }
delete decorations.value[keys.value[index]]; delete valueMappings.value[keys.value[index]];
keys.value.splice(index, 1); keys.value.splice(index, 1);
updateConfig(); updateConfig();
} }
@ -74,7 +74,7 @@ limitations under the License. -->
function updateConfig() { function updateConfig() {
const graph = { const graph = {
...dashboardStore.selectedGrid.graph, ...dashboardStore.selectedGrid.graph,
valueMappings: decorations.value, valueMappings: valueMappings.value,
}; };
dashboardStore.selectWidget({ ...dashboardStore.selectedGrid, graph }); dashboardStore.selectWidget({ ...dashboardStore.selectedGrid, graph });
} }

View File

@ -48,13 +48,13 @@ limitations under the License. -->
showUnit: true, showUnit: true,
textAlign: "center", textAlign: "center",
metricConfig: [], metricConfig: [],
decorations: {}, valueMappings: {},
}), }),
}, },
}); });
const { t } = useI18n(); const { t } = useI18n();
const metricConfig = computed(() => props.config.metricConfig || []); const metricConfig = computed(() => props.config.metricConfig || []);
const decorations = computed(() => props.config.decorations || {}); const valueMappings = computed(() => props.config.valueMappings || {});
const key = computed(() => Object.keys(props.data)[0]); const key = computed(() => Object.keys(props.data)[0]);
const singleVal = computed(() => const singleVal = computed(() =>
Array.isArray(props.data[key.value]) ? props.data[key.value][0] : props.data[key.value], Array.isArray(props.data[key.value]) ? props.data[key.value][0] : props.data[key.value],
@ -62,11 +62,11 @@ limitations under the License. -->
const unit = computed(() => metricConfig.value[0] && encodeURIComponent(metricConfig.value[0].unit || "")); const unit = computed(() => metricConfig.value[0] && encodeURIComponent(metricConfig.value[0].unit || ""));
function getValue() { function getValue() {
if (decorations.value[singleVal.value]) { if (valueMappings.value[singleVal.value]) {
return decorations.value[singleVal.value]; return valueMappings.value[singleVal.value];
} }
const regex = /-?\d+(\.\d+)?/g; const regex = /-?\d+(\.\d+)?/g;
const list = Object.keys(decorations.value); const list = Object.keys(valueMappings.value);
for (const i of list) { for (const i of list) {
const k = i.replace(/\s+/g, ""); const k = i.replace(/\s+/g, "");
let withinRange = false; let withinRange = false;
@ -81,9 +81,8 @@ limitations under the License. -->
} else { } else {
withinRange = withinRange && (k.endsWith("+∞)") || Number(singleVal.value) < (ranges[1] || ranges[0])); withinRange = withinRange && (k.endsWith("+∞)") || Number(singleVal.value) < (ranges[1] || ranges[0]));
} }
console.log(withinRange);
if (withinRange) { if (withinRange) {
return decorations.value[i] || singleVal.value; return valueMappings.value[i] || singleVal.value;
} }
} }
return singleVal.value; return singleVal.value;

View File

@ -58,14 +58,14 @@ limitations under the License. -->
showTableValues: boolean; showTableValues: boolean;
tableHeaderCol2: string; tableHeaderCol2: string;
typesOfMQE: string[]; typesOfMQE: string[];
decorations: {}; valueMappings: {};
}>, }>,
default: () => ({ showTableValues: true }), default: () => ({ showTableValues: true }),
}, },
}); });
const { t } = useI18n(); const { t } = useI18n();
const decorations = computed<{ [key: string]: string }>(() => props.config.decorations || {}); const valueMappings = computed<{ [key: string]: string }>(() => props.config.valueMappings || {});
const nameWidth = computed(() => (props.config.showTableValues ? 80 : 100)); const nameWidth = computed(() => (props.config.showTableValues ? 80 : 100));
const dataKeys = computed(() => { const dataKeys = computed(() => {
const keys = Object.keys(props.data || {}).filter( const keys = Object.keys(props.data || {}).filter(
@ -78,11 +78,11 @@ limitations under the License. -->
function getColValue(keys: string[]) { function getColValue(keys: string[]) {
const source = props.data[(keys as string[]).join(",")][props.data[(keys as string[]).join(",")].length - 1 || 0]; const source = props.data[(keys as string[]).join(",")][props.data[(keys as string[]).join(",")].length - 1 || 0];
if (decorations.value[source]) { if (valueMappings.value[source]) {
return decorations.value[source]; return valueMappings.value[source];
} }
const regex = /-?\d+(\.\d+)?/g; const regex = /-?\d+(\.\d+)?/g;
const list = Object.keys(decorations.value); const list = Object.keys(valueMappings.value);
for (const i of list) { for (const i of list) {
const k = i.replace(/\s+/g, ""); const k = i.replace(/\s+/g, "");
let withinRange = false; let withinRange = false;
@ -98,7 +98,7 @@ limitations under the License. -->
withinRange = withinRange && (k.endsWith("+∞)") || Number(source) < (ranges[1] || ranges[0])); withinRange = withinRange && (k.endsWith("+∞)") || Number(source) < (ranges[1] || ranges[0]));
} }
if (withinRange) { if (withinRange) {
return decorations.value[i]; return valueMappings.value[i];
} }
} }
return source; return source;