diff --git a/src/hooks/useListConfig.ts b/src/hooks/useListConfig.ts new file mode 100644 index 00000000..14673083 --- /dev/null +++ b/src/hooks/useListConfig.ts @@ -0,0 +1,28 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { MetricQueryTypes, Calculations } from "./data"; +export function useListConfig(config: any, index: number) { + const calculation = + config.metricConfig && + config.metricConfig[index] && + config.metricConfig[index].calculation; + const line = + config.metricTypes[index] === MetricQueryTypes.ReadMetricsValues && + calculation !== Calculations.Average; + + return { isLinear: line }; +} diff --git a/src/hooks/useProcessor.ts b/src/hooks/useProcessor.ts index 09d014a8..6ee86317 100644 --- a/src/hooks/useProcessor.ts +++ b/src/hooks/useProcessor.ts @@ -318,16 +318,21 @@ export function useQueryTopologyMetrics(metrics: string[], ids: string[]) { return { queryStr, conditions }; } function calculateExp( - arr: number[], + arr: any[], config: { calculation: string } ): (number | string)[] { - let data: (number | string)[] = arr; + let data: (number | string)[] = []; switch (config.calculation) { case Calculations.Average: - data = [arr.reduce((a, b) => a + b) / arr.length]; + data = [ + ( + arr.map((d: { value: number }) => d.value).reduce((a, b) => a + b) / + arr.length + ).toFixed(2), + ]; break; default: - data = arr.map((d) => aggregation(d, config)); + data = arr.map((d) => aggregation(d.value, config)); break; } return data; @@ -341,19 +346,19 @@ function aggregation( switch (config.calculation) { case Calculations.Percentage: - data = val / 100; + data = (val / 100).toFixed(2); break; case Calculations.ByteToKB: - data = val / 1024; + data = (val / 1024).toFixed(2); break; case Calculations.ByteToMB: - data = val / 1024 / 1024; + data = (val / 1024 / 1024).toFixed(2); break; case Calculations.ByteToGB: - data = val / 1024 / 1024 / 1024; + data = (val / 1024 / 1024 / 1024).toFixed(2); break; case Calculations.Apdex: - data = val / 10000; + data = (val / 10000).toFixed(2); break; case Calculations.ConvertSeconds: data = dayjs(val).format("YYYY-MM-DD HH:mm:ss"); @@ -365,7 +370,7 @@ function aggregation( data = data.toFixed(2); break; case Calculations.MsTos: - data = val / 1000; + data = (val / 1000).toFixed(2); break; default: data; diff --git a/src/views/dashboard/graphs/Card.vue b/src/views/dashboard/graphs/Card.vue index 241dacc1..42f95ab6 100644 --- a/src/views/dashboard/graphs/Card.vue +++ b/src/views/dashboard/graphs/Card.vue @@ -52,6 +52,7 @@ 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) ); diff --git a/src/views/dashboard/graphs/EndpointList.vue b/src/views/dashboard/graphs/EndpointList.vue index 9dc8d1b6..7de337b3 100644 --- a/src/views/dashboard/graphs/EndpointList.vue +++ b/src/views/dashboard/graphs/EndpointList.vue @@ -52,7 +52,7 @@ limitations under the License. -->