feat: add an avg calculation for metrics of list graphs (#65)

This commit is contained in:
Fine0830
2022-04-14 14:38:32 +08:00
committed by GitHub
parent 2dd9df19d7
commit 69a9c6de13
16 changed files with 279 additions and 189 deletions

View File

@@ -42,35 +42,11 @@ limitations under the License. -->
</span>
</template>
</el-table-column>
<el-table-column
v-for="(metric, index) in colMetrics"
:label="`${decodeURIComponent(
getLabel(metric, index)
)} ${decodeURIComponent(getUnit(index))}`"
:key="metric + index"
min-width="120"
>
<template #default="scope">
<div class="chart">
<Line
v-if="config.metricTypes[index] === 'readMetricsValues'"
:data="metric ? { [metric]: scope.row[metric] } : {}"
:intervalTime="intervalTime"
:config="{
showXAxis: false,
showYAxis: false,
smallTips: true,
showSymbol: true,
}"
/>
<Card
v-else
:data="{ [metric]: scope.row[metric] }"
:config="{ textAlign: 'left' }"
/>
</div>
</template>
</el-table-column>
<ColumnGraph
:intervalTime="intervalTime"
:colMetrics="colMetrics"
:config="config"
/>
<el-table-column label="Attributes">
<template #default="scope">
<el-popover placement="left" :width="400" trigger="click">
@@ -110,8 +86,6 @@ import { ref, watch, computed } from "vue";
import { useI18n } from "vue-i18n";
import { ElMessage } from "element-plus";
import type { PropType } from "vue";
import Line from "./Line.vue";
import Card from "./Card.vue";
import { useSelectorStore } from "@/store/modules/selectors";
import { useDashboardStore } from "@/store/modules/dashboard";
import { InstanceListConfig } from "@/types/dashboard";
@@ -121,6 +95,7 @@ import { EntityType } from "../data";
import router from "@/router";
import getDashboard from "@/hooks/useDashboardsSession";
import { MetricConfigOpt } from "@/types/dashboard";
import ColumnGraph from "./components/ColumnGraph.vue";
/*global defineProps */
const props = defineProps({
@@ -236,28 +211,6 @@ function searchList() {
queryInstanceMetrics(instances.value);
}
function getUnit(index: number) {
const u =
props.config.metricConfig &&
props.config.metricConfig[index] &&
props.config.metricConfig[index].unit;
if (u) {
return `(${encodeURIComponent(u)})`;
}
return encodeURIComponent("");
}
function getLabel(metric: string, index: number) {
const label =
props.config.metricConfig &&
props.config.metricConfig[index] &&
props.config.metricConfig[index].label;
if (label) {
return encodeURIComponent(label);
}
return encodeURIComponent(metric);
}
watch(
() => [...(props.config.metricTypes || []), ...(props.config.metrics || [])],
(data, old) => {