add mini line chart

This commit is contained in:
Fine 2025-01-09 16:40:56 +08:00
parent b6f88275ca
commit b2627de8c2
4 changed files with 63 additions and 14 deletions

View File

@ -34,7 +34,24 @@ export function useSnapshot(metrics: { name: string; results: any[] }[]) {
return sources; return sources;
} }
function getMetricsMap() {
const metricsMap: { [key: string]: number[] } = {};
for (const metric of metrics) {
for (const item of metric.results) {
const arr = item.values.map((v: { value: string }) => Number(v.value));
if (!item.metric.labels.length) {
metricsMap[metric.name] = arr;
} else {
const label = item.metric.labels[0];
metricsMap[`${label.key}=${label.value}`] = arr;
}
}
}
return metricsMap;
}
return { return {
processResults, processResults,
getMetricsMap,
}; };
} }

View File

@ -111,6 +111,7 @@ export interface LineConfig extends AreaConfig {
showYAxis?: boolean; showYAxis?: boolean;
smallTips?: boolean; smallTips?: boolean;
showlabels?: boolean; showlabels?: boolean;
noTooltips?: boolean;
} }
export interface AreaConfig { export interface AreaConfig {

View File

@ -22,8 +22,9 @@ limitations under the License. -->
<div class="message mb-5 b"> <div class="message mb-5 b">
{{ i.message }} {{ i.message }}
</div> </div>
<div class="flex-h">
<div <div
class="timeline-table-i-scope mr-10 l sm" class="timeline-table-i-scope"
:class="{ :class="{
blue: i.scope === 'Service', blue: i.scope === 'Service',
green: i.scope === 'Endpoint', green: i.scope === 'Endpoint',
@ -32,6 +33,20 @@ limitations under the License. -->
> >
{{ t(i.scope.toLowerCase()) }} {{ t(i.scope.toLowerCase()) }}
</div> </div>
<div class="mini-chart">
<Line
:data="handleMetrics(i.snapshot)"
:intervalTime="appStore.intervalTime"
:config="{
showXAxis: false,
showYAxis: false,
smallTips: false,
showlabels: false,
noTooltips: true,
}"
/>
</div>
</div>
<div class="grey sm show-xs"> <div class="grey sm show-xs">
{{ dateFormat(parseInt(i.startTime)) }} {{ dateFormat(parseInt(i.startTime)) }}
</div> </div>
@ -118,12 +133,16 @@ limitations under the License. -->
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import type { Alarm, Event } from "@/types/alarm"; import type { Alarm, Event } from "@/types/alarm";
import { useAlarmStore } from "@/store/modules/alarm"; import { useAlarmStore } from "@/store/modules/alarm";
import { useAppStoreWithOut } from "@/store/modules/app";
import { EventsDetailHeaders, AlarmDetailCol, EventsDetailKeys } from "./data"; import { EventsDetailHeaders, AlarmDetailCol, EventsDetailKeys } from "./data";
import { dateFormat } from "@/utils/dateFormat"; import { dateFormat } from "@/utils/dateFormat";
import { useSnapshot } from "@/hooks/useSnapshot";
import Snapshot from "./components/Snapshot.vue"; import Snapshot from "./components/Snapshot.vue";
import Line from "@/views/dashboard/graphs/Line.vue";
const { t } = useI18n(); const { t } = useI18n();
const alarmStore = useAlarmStore(); const alarmStore = useAlarmStore();
const appStore = useAppStoreWithOut();
const isShowDetails = ref<boolean>(false); const isShowDetails = ref<boolean>(false);
const showEventDetails = ref<boolean>(false); const showEventDetails = ref<boolean>(false);
const currentDetail = ref<Alarm | any>({}); const currentDetail = ref<Alarm | any>({});
@ -144,6 +163,12 @@ limitations under the License. -->
currentEvent.value = event; currentEvent.value = event;
showEventDetails.value = true; showEventDetails.value = true;
} }
function handleMetrics(snapshot: any) {
const { getMetricsMap } = useSnapshot(snapshot.metrics);
return getMetricsMap();
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.timeline-table { .timeline-table {
@ -190,11 +215,10 @@ limitations under the License. -->
} }
.timeline-table-i-scope { .timeline-table-i-scope {
display: inline-block; padding: 0 5px;
padding: 0 8px;
border: 1px solid; border: 1px solid;
margin-top: -1px; border-radius: 3px;
border-radius: 4px; display: inline-block;
} }
.timeline-item { .timeline-item {
@ -251,4 +275,9 @@ limitations under the License. -->
} }
} }
} }
.mini-chart {
height: 20px;
width: 400px;
}
</style> </style>

View File

@ -60,6 +60,7 @@ limitations under the License. -->
showYAxis: true, showYAxis: true,
smallTips: false, smallTips: false,
showlabels: true, showlabels: true,
noTooltips: false,
}), }),
}, },
}); });
@ -97,6 +98,7 @@ limitations under the License. -->
const color: string[] = chartColors(); const color: string[] = chartColors();
const tooltip = { const tooltip = {
trigger: "axis", trigger: "axis",
show: !props.config.noTooltips,
backgroundColor: appStore.theme === Themes.Dark ? "#333" : "#fff", backgroundColor: appStore.theme === Themes.Dark ? "#333" : "#fff",
borderColor: appStore.theme === Themes.Dark ? "#333" : "#fff", borderColor: appStore.theme === Themes.Dark ? "#333" : "#fff",
textStyle: { textStyle: {
@ -108,10 +110,10 @@ limitations under the License. -->
extraCssText: "max-height:85%; overflow: auto;", extraCssText: "max-height:85%; overflow: auto;",
}; };
const tips = { const tips = {
show: !props.config.noTooltips,
formatter(params: any) { formatter(params: any) {
return `${params[0].value[1]}`; return `${params[0].value[1]}`;
}, },
confine: true,
extraCssText: `height: 20px; padding:0 2px;`, extraCssText: `height: 20px; padding:0 2px;`,
trigger: "axis", trigger: "axis",
backgroundColor: appStore.theme === Themes.Dark ? "#666" : "#eee", backgroundColor: appStore.theme === Themes.Dark ? "#666" : "#eee",