Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions packages/web/projects/vgpu/hooks/useInstantVector.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const useInstantVector = (configs, parseQuery = (query) => query, times) => {
},
});

data.value[index].data = percentData.data[0]?.values;
data.value[index].data = percentData.data[0]?.values || [];
}
},
);
Expand All @@ -67,7 +67,7 @@ const useInstantVector = (configs, parseQuery = (query) => query, times) => {
},
});

data.value[index].data = percentData.data[0]?.values;
data.value[index].data = percentData.data[0]?.values || [];
}
},
);
Expand All @@ -79,13 +79,17 @@ const useInstantVector = (configs, parseQuery = (query) => query, times) => {
fetchInstantData();
});

watch(
times,
() => {
fetchRangeData();
},
// { immediate: true },
);
if (times) {
watch(
() => times.value,
() => {
// Only fetch data when both start and end times are available
if (times?.value?.[0] && times?.value?.[1]) {
fetchRangeData();
}
},
);
}

return data;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,12 @@ export const getLineOptions = ({
};

export const getRangeOptions = (data) => {
if (!data || !data[0] || !data[0].data) {
return {
series: [],
};
}

return {
legend: {
// data: [],
Expand All @@ -487,6 +493,7 @@ export const getRangeOptions = (data) => {
type: 'cross',
},
formatter: function (params) {
if (!params || params.length === 0) return '';
var res = params[0].name + '<br/>';
for (var i = 0; i < params.length; i++) {
res +=
Expand Down
4 changes: 2 additions & 2 deletions packages/web/projects/vgpu/views/monitor/overview/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ const fetchRangeData = () => {
query: v.query,
})
.then((res) => {
v.data = res.data[0].values;
v.data = res.data?.[0]?.values || [];
});
}
}
Expand All @@ -407,7 +407,7 @@ const fetchRangeData = () => {
query: `sum({__name__=~"alert:.*:count"})`,
})
.then((res) => {
alarmData.value = res.data[0].values;
alarmData.value = res.data?.[0]?.values || [];
});

};
Expand Down
42 changes: 28 additions & 14 deletions packages/web/src/components/Echarts-plus.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,46 @@ const props = defineProps({
});

const echartsRef = ref(null);
const myChart = ref(null);

const refresh = debounce(() => {
const myChart = echarts.init(echartsRef.value);
myChart.setOption(props.options);
myChart.on('finished', () => {
myChart.resize();
myChart.off('finished');
});
if (myChart.value) {
myChart.value.dispose();
}
myChart.value = echarts.init(echartsRef.value);
if (props.options) {
myChart.value.setOption(props.options);
}
if (props.onClick) {
// myChart.on('click', props.onClick);
myChart.value.on('click', (params) => {
props.onClick(params, myChart.value);
});
}
}, 10);

const resizeObserver = new ResizeObserver((e) => {
refresh();
const resizeObserver = new ResizeObserver(() => {
requestAnimationFrame(() => {
refresh();
});
});

const currentName = ref();

watchEffect(() => {
const options = props.options;
nextTick(() => {
const myChart = echarts.init(echartsRef.value);
myChart.setOption(props.options);
if (myChart.value) {
myChart.value.dispose();
}
myChart.value = echarts.init(echartsRef.value);
if (props.options) {
myChart.value.setOption(props.options);
}

if (props.onClick) {
myChart.off('click');
myChart.on('click', (params) => {
props.onClick(params, myChart);
myChart.value.off('click');
myChart.value.on('click', (params) => {
props.onClick(params, myChart.value);
});
}
});
Expand All @@ -60,6 +71,9 @@ onMounted(() => {
});

onUnmounted(() => {
if (myChart.value) {
myChart.value.dispose();
}
resizeObserver.disconnect();
});

Expand Down
Loading