CodePrometheus commented on code in PR #421:
URL: 
https://github.com/apache/skywalking-booster-ui/pull/421#discussion_r1804689909


##########
src/views/dashboard/graphs/Card.vue:
##########
@@ -48,18 +48,45 @@ limitations under the License. -->
         showUnit: true,
         textAlign: "center",
         metricConfig: [],
-        decorations: {},
+        valueMappings: {},
       }),
     },
   });
   const { t } = useI18n();
   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 singleVal = computed(() =>
     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 (valueMappings.value[singleVal.value]) {
+      return valueMappings.value[singleVal.value];
+    }
+    const regex = /-?\d+(\.\d+)?/g;
+    const list = Object.keys(valueMappings.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("[-∞") || Number(singleVal.value) >= 
ranges[0];
+      } else {
+        withinRange = k.startsWith("(-∞") || Number(singleVal.value) > 
ranges[0];
+      }
+      if (k.endsWith("]")) {
+        withinRange = withinRange && (k.endsWith("+∞]") || 
Number(singleVal.value) <= (ranges[1] || ranges[0]));

Review Comment:
   If this supports writing regular expressions directly, how about that. For 
example, ^(10|[0-9])$ matches 0-10.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to