From de90ae6d9b87ecb7902436e08b041c96b02bb386 Mon Sep 17 00:00:00 2001 From: Qiuxia Fan Date: Wed, 13 Apr 2022 21:01:05 +0800 Subject: [PATCH] view the values --- src/hooks/useListConfig.ts | 8 +++- src/hooks/useProcessor.ts | 10 ++++- src/views/dashboard/graphs/Card.vue | 18 ++++----- src/views/dashboard/graphs/EndpointList.vue | 2 +- src/views/dashboard/graphs/InstanceList.vue | 2 +- src/views/dashboard/graphs/ServiceList.vue | 41 ++++++++++++++++++++- 6 files changed, 63 insertions(+), 18 deletions(-) diff --git a/src/hooks/useListConfig.ts b/src/hooks/useListConfig.ts index 14673083..08e7456b 100644 --- a/src/hooks/useListConfig.ts +++ b/src/hooks/useListConfig.ts @@ -23,6 +23,12 @@ export function useListConfig(config: any, index: number) { const line = config.metricTypes[index] === MetricQueryTypes.ReadMetricsValues && calculation !== Calculations.Average; + const isAvg = + config.metricTypes[index] === MetricQueryTypes.ReadMetricsValues && + calculation === Calculations.Average; - return { isLinear: line }; + return { + isLinear: line, + isAvg, + }; } diff --git a/src/hooks/useProcessor.ts b/src/hooks/useProcessor.ts index 6ee86317..84ab0744 100644 --- a/src/hooks/useProcessor.ts +++ b/src/hooks/useProcessor.ts @@ -284,7 +284,13 @@ export function usePodsSource( d[name] = aggregation(resp.data[key], c); } if (config.metricTypes[index] === MetricQueryTypes.ReadMetricsValues) { - d[name] = calculateExp(resp.data[key].values.values, c); + d[name] = {}; + if (c.calculation === Calculations.Average) { + d[name]["avg"] = calculateExp(resp.data[key].values.values, c); + } + d[name]["values"] = resp.data[key].values.values.map( + (val: { value: number }) => aggregation(val.value, c) + ); } }); @@ -338,7 +344,7 @@ function calculateExp( return data; } -function aggregation( +export function aggregation( val: number, config: { calculation: string } ): number | string { diff --git a/src/views/dashboard/graphs/Card.vue b/src/views/dashboard/graphs/Card.vue index 42f95ab6..98b7cb4c 100644 --- a/src/views/dashboard/graphs/Card.vue +++ b/src/views/dashboard/graphs/Card.vue @@ -17,8 +17,10 @@ limitations under the License. -->
{{ singleVal.toFixed(2) }} @@ -52,7 +54,6 @@ const { t } = useI18n(); const metricConfig = computed(() => props.config.metricConfig || []); const key = computed(() => Object.keys(props.data)[0]); const singleVal = computed(() => Number(props.data[key.value])); -console.log(props.data); const unit = computed( () => metricConfig.value[0] && encodeURIComponent(metricConfig.value[0].unit) ); @@ -60,15 +61,10 @@ const unit = computed(