view the values

This commit is contained in:
Qiuxia Fan 2022-04-13 21:01:05 +08:00
parent 6cb20aa301
commit de90ae6d9b
6 changed files with 63 additions and 18 deletions

View File

@ -23,6 +23,12 @@ export function useListConfig(config: any, index: number) {
const line = const line =
config.metricTypes[index] === MetricQueryTypes.ReadMetricsValues && config.metricTypes[index] === MetricQueryTypes.ReadMetricsValues &&
calculation !== Calculations.Average; calculation !== Calculations.Average;
const isAvg =
config.metricTypes[index] === MetricQueryTypes.ReadMetricsValues &&
calculation === Calculations.Average;
return { isLinear: line }; return {
isLinear: line,
isAvg,
};
} }

View File

@ -284,7 +284,13 @@ export function usePodsSource(
d[name] = aggregation(resp.data[key], c); d[name] = aggregation(resp.data[key], c);
} }
if (config.metricTypes[index] === MetricQueryTypes.ReadMetricsValues) { 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; return data;
} }
function aggregation( export function aggregation(
val: number, val: number,
config: { calculation: string } config: { calculation: string }
): number | string { ): number | string {

View File

@ -17,8 +17,10 @@ limitations under the License. -->
<div <div
v-if="!isNaN(singleVal)" v-if="!isNaN(singleVal)"
class="chart-card" class="chart-card"
:class="{ center: config.textAlign === 'center' }" :style="{
:style="{ fontSize: `${config.fontSize}px`, textAlign: config.textAlign }" fontSize: `${config.fontSize}px`,
justifyContent: config.textAlign || 'center',
}"
> >
{{ singleVal.toFixed(2) }} {{ singleVal.toFixed(2) }}
<span v-show="config.showUnit"> <span v-show="config.showUnit">
@ -52,7 +54,6 @@ const { t } = useI18n();
const metricConfig = computed(() => props.config.metricConfig || []); const metricConfig = computed(() => props.config.metricConfig || []);
const key = computed(() => Object.keys(props.data)[0]); const key = computed(() => Object.keys(props.data)[0]);
const singleVal = computed(() => Number(props.data[key.value])); const singleVal = computed(() => Number(props.data[key.value]));
console.log(props.data);
const unit = computed( const unit = computed(
() => metricConfig.value[0] && encodeURIComponent(metricConfig.value[0].unit) () => metricConfig.value[0] && encodeURIComponent(metricConfig.value[0].unit)
); );
@ -60,15 +61,10 @@ const unit = computed(
<style lang="scss" scoped> <style lang="scss" scoped>
.chart-card { .chart-card {
color: #333; color: #333;
width: 100%;
height: 100%; height: 100%;
} display: flex;
align-items: center;
.center {
box-sizing: border-box;
display: -webkit-box;
-webkit-box-orient: horizontal;
-webkit-box-pack: center;
-webkit-box-align: center;
} }
.no-data { .no-data {

View File

@ -59,7 +59,7 @@ limitations under the License. -->
showXAxis: false, showXAxis: false,
showYAxis: false, showYAxis: false,
smallTips: true, smallTips: true,
showSymbol: true, showlabels: false,
}" }"
/> />
<Card <Card

View File

@ -60,7 +60,7 @@ limitations under the License. -->
showXAxis: false, showXAxis: false,
showYAxis: false, showYAxis: false,
smallTips: true, smallTips: true,
showSymbol: true, showlabels: false,
}" }"
/> />
<Card <Card

View File

@ -65,7 +65,9 @@ limitations under the License. -->
<div class="chart"> <div class="chart">
<Line <Line
v-if="useListConfig(config, index).isLinear" v-if="useListConfig(config, index).isLinear"
:data="{ [metric]: scope.row[metric] }" :data="{
[metric]: scope.row[metric] && scope.row[metric].values,
}"
:intervalTime="intervalTime" :intervalTime="intervalTime"
:config="{ :config="{
showXAxis: false, showXAxis: false,
@ -74,6 +76,35 @@ limitations under the License. -->
showlabels: false, showlabels: false,
}" }"
/> />
<el-popover
v-else-if="useListConfig(config, index).isAvg"
placement="left"
:width="400"
trigger="click"
>
<template #reference>
<Card
:data="{
[metric]: scope.row[metric] && scope.row[metric].avg,
}"
:config="{ textAlign: 'left' }"
/>
</template>
<div class="view-line">
<Line
:data="{
[metric]: scope.row[metric] && scope.row[metric].values,
}"
:intervalTime="intervalTime"
:config="{
showXAxis: false,
showYAxis: false,
smallTips: true,
showlabels: false,
}"
/>
</div>
</el-popover>
<Card <Card
v-else v-else
:data="{ [metric]: scope.row[metric] }" :data="{ [metric]: scope.row[metric] }"
@ -241,6 +272,7 @@ async function queryServiceMetrics(currentServices: Service[]) {
}); });
return; return;
} }
console.log(services.value);
services.value = currentServices; services.value = currentServices;
} }
function objectSpanMethod(param: any): any { function objectSpanMethod(param: any): any {
@ -320,10 +352,15 @@ watch(
@import "./style.scss"; @import "./style.scss";
.chart { .chart {
height: 60px; height: 40px;
} }
.inputs { .inputs {
width: 300px; width: 300px;
} }
.view-line {
width: 300px;
height: 200px;
}
</style> </style>