From 6239ff709fe760dc0a002ec053c1f109fa3e9b64 Mon Sep 17 00:00:00 2001 From: Fine Date: Thu, 17 Oct 2024 18:16:30 +0800 Subject: [PATCH] add range --- src/views/dashboard/graphs/Card.vue | 30 +++++++++++++++++++++++++++- src/views/dashboard/graphs/Table.vue | 30 +++++++++++++++++++++++++--- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/src/views/dashboard/graphs/Card.vue b/src/views/dashboard/graphs/Card.vue index 0c4b34da..f921a1c5 100644 --- a/src/views/dashboard/graphs/Card.vue +++ b/src/views/dashboard/graphs/Card.vue @@ -22,7 +22,7 @@ limitations under the License. --> justifyContent: config.textAlign || 'center', }" > - {{ decorations[singleVal] || singleVal }} + {{ getValue() }} {{ decodeURIComponent(unit) }} @@ -60,6 +60,34 @@ limitations under the License. --> Array.isArray(props.data[key.value]) ? props.data[key.value][0] : props.data[key.value], ); const unit = computed(() => metricConfig.value[0] && encodeURIComponent(metricConfig.value[0].unit || "")); + + function getValue() { + if (decorations.value[singleVal.value]) { + return decorations.value[singleVal.value]; + } + const regex = /-?\d+(\.\d+)?/g; + const list = Object.keys(decorations.value); + for (const i of list) { + const k = i.replace(/\s+/g, ""); + let withinRange = false; + const ranges = k.match(regex)?.map(Number) || []; + if (k.startsWith("[")) { + withinRange = k.startsWith("[-∞") ? true : Number(singleVal.value) >= ranges[0]; + } else { + withinRange = k.startsWith("(-∞") ? true : Number(singleVal.value) > ranges[0]; + } + if (k.endsWith("]")) { + withinRange = withinRange && (k.endsWith("+∞]") ? true : Number(singleVal.value) <= (ranges[1] || ranges[0])); + } else { + withinRange = withinRange && (k.endsWith("+∞)") ? true : Number(singleVal.value) < (ranges[1] || ranges[0])); + } + console.log(withinRange); + if (withinRange) { + return decorations.value[i] || singleVal.value; + } + } + return singleVal.value; + }