diff --git a/src/views/dashboard/related/topology/components/Settings.vue b/src/views/dashboard/related/topology/components/Settings.vue
index 95678eea..4a66efe8 100644
--- a/src/views/dashboard/related/topology/components/Settings.vue
+++ b/src/views/dashboard/related/topology/components/Settings.vue
@@ -110,30 +110,51 @@ limitations under the License. -->
{{ t("legendSettings") }}
-
{{ t("metrics") }}
-
-
-
+
{{ t("conditions") }} (&&)
+
placeholder="Select a condition"
@change="changeCondition"
/> -->
-
({ metric: {}, condition: "", secondMetric: {} });
+ metric: { name: string; condition: string; value: string }[];
+}>({ metric: [{ name: "", condition: "", value: "" }] });
getMetricList();
async function getMetricList() {
@@ -257,19 +252,23 @@ async function getMetricList() {
);
}
async function setLegend() {
- if (!legend.metric.name) {
- return;
- }
- if (!legend.metric.value) {
- return;
- }
- if (!legend.metric.condition) {
- return;
- }
+ const metrics = legend.metric.filter(
+ (d: any) => d.name && d.value && d.condition
+ );
+ const names = metrics.map((d: any) => d.name);
- updateSettings();
+ emit("update", {
+ linkDashboard: states.linkDashboard,
+ nodeDashboard: isServer
+ ? items.filter((d: { scope: string; dashboard: string }) => d.dashboard)
+ : states.nodeDashboard,
+ linkServerMetrics: states.linkServerMetrics,
+ linkClientMetrics: states.linkClientMetrics,
+ nodeMetrics: states.nodeMetrics,
+ legend: metrics,
+ });
const ids = topologyStore.nodes.map((d: Node) => d.id);
- const param = await useQueryTopologyMetrics([legend.metric.name], ids);
+ const param = await useQueryTopologyMetrics(names, ids);
const res = await topologyStore.getLegendMetrics(param);
if (res.errors) {
@@ -277,15 +276,9 @@ async function setLegend() {
}
emit("updateNodes");
}
-function changeLegend(type: string, opt: any) {
- legend.metric[type] = opt[0].value || opt;
+function changeLegend(type: string, opt: any, index: number) {
+ (legend.metric[index] as any)[type] = opt[0].value || opt;
}
-// function changeCondition(opt: Option[]) {
-// legend.condition = opt[0].value;
-// }
-// function changeLegendMetric(type: string, opt: any) {
-// legend.secondMetric[type] = opt[0].value || opt;
-// }
function changeScope(index: number, opt: Option[]) {
items[index].scope = opt[0].value;
items[index].dashboard = "";
@@ -310,7 +303,7 @@ function updateSettings() {
linkServerMetrics: states.linkServerMetrics,
linkClientMetrics: states.linkClientMetrics,
nodeMetrics: states.nodeMetrics,
- legend,
+ legend: legend.metric,
});
}
async function changeLinkServerMetrics(options: Option[]) {
@@ -362,6 +355,12 @@ async function changeNodeMetrics(options: Option[]) {
ElMessage.error(res.errors);
}
}
+function deleteMetric(index: number) {
+ legend.metric.splice(index, 1);
+}
+function addMetric() {
+ legend.metric.push({ name: "", condition: "", value: "" });
+}
diff --git a/src/views/dashboard/related/topology/utils/legend.ts b/src/views/dashboard/related/topology/utils/legend.ts
index ea8336d3..a5b0c957 100644
--- a/src/views/dashboard/related/topology/utils/legend.ts
+++ b/src/views/dashboard/related/topology/utils/legend.ts
@@ -37,9 +37,13 @@ export default function topoLegend(
.attr("x", clientWidth - (item === "CUBEERROR" ? 310 : 410))
.attr("y", clientHeight - 30)
.text(() => {
+ const l = config || [];
+ const str = l
+ .map((d: any) => `${d.name} ${d.condition} ${d.value}`)
+ .join(" and ");
return item === "CUBEERROR"
? config
- ? `Unhealthy (${config.metric.name} ${config.metric.condition} ${config.metric.value})`
+ ? `Unhealthy (${str})`
: "Unhealthy"
: "Healthy";
})
diff --git a/src/views/dashboard/related/topology/utils/nodeElement.ts b/src/views/dashboard/related/topology/utils/nodeElement.ts
index abb3aca2..6a9fbe1d 100644
--- a/src/views/dashboard/related/topology/utils/nodeElement.ts
+++ b/src/views/dashboard/related/topology/utils/nodeElement.ts
@@ -50,20 +50,19 @@ export default (d3: any, graph: any, funcs: any, tip: any, legend: any) => {
if (!legend) {
return icons.CUBE;
}
- const val = legend.metric.name.includes("_sla")
- ? d[legend.metric.name] / 100
- : d[legend.metric.name];
- if (legend.metric.condition === "<") {
- return val < Number(legend.metric.value) && d.isReal
- ? icons.CUBEERROR
- : icons.CUBE;
+ if (!legend.length) {
+ return icons.CUBE;
}
- if (legend.metric.condition === ">") {
- return val > Number(legend.metric.value) && d.isReal
- ? icons.CUBEERROR
- : icons.CUBE;
+ let c = true;
+ for (const l of legend) {
+ const val = l.name.includes("_sla") ? d[l.name] / 100 : d[l.name];
+ if (l.condition === "<") {
+ c = c && val < Number(l.value);
+ } else {
+ c = c && val > Number(l.value);
+ }
}
- return icons.CUBE;
+ return c && d.isReal ? icons.CUBEERROR : icons.CUBE;
});
nodeEnter
.append("image")