From a599931ef951731607dab59821d8a16eae1943ea Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 15 Sep 2024 11:55:37 +0800 Subject: [PATCH 1/3] refactor: waterfall via echarts --- src/client/pages/index/waterfall.vue | 284 +++++++++++++++++---------- 1 file changed, 176 insertions(+), 108 deletions(-) diff --git a/src/client/pages/index/waterfall.vue b/src/client/pages/index/waterfall.vue index 1ccb26c..1b5bf4d 100644 --- a/src/client/pages/index/waterfall.vue +++ b/src/client/pages/index/waterfall.vue @@ -1,8 +1,31 @@ @@ -138,43 +236,13 @@ watch(scale, (newScale, oldScale) => {
- -
-
-
- - {{ i }} - s - -
-
-
-
- {{ i }} -
-
-
- -
+ +
+
+
+ No data
- + +
From 83d95da5166963307ca1c9249b1000ae3f34ab5d Mon Sep 17 00:00:00 2001 From: liliang18 Date: Wed, 18 Sep 2024 15:13:51 +0800 Subject: [PATCH 2/3] fix: fix time range --- src/client/pages/index/waterfall.vue | 51 +++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/src/client/pages/index/waterfall.vue b/src/client/pages/index/waterfall.vue index 1b5bf4d..66b21c1 100644 --- a/src/client/pages/index/waterfall.vue +++ b/src/client/pages/index/waterfall.vue @@ -13,9 +13,10 @@ import { LegendComponent, TitleComponent, TooltipComponent, + VisualMapComponent, } from 'echarts/components' import VChart from 'vue-echarts' -import type { CustomSeriesRenderItemAPI, CustomSeriesRenderItemParams, CustomSeriesRenderItemReturn, TopLevelFormatterParams } from 'echarts/types/dist/shared' +import type { CustomSeriesRenderItemAPI, CustomSeriesRenderItemParams, CustomSeriesRenderItemReturn, LegendComponentOption, TopLevelFormatterParams } from 'echarts/types/dist/shared' import { rpc } from '../../logic/rpc' import { getHot } from '../../logic/hot' import { inspectSSR, onRefetch, waterfallShowResolveId } from '../../logic' @@ -43,9 +44,22 @@ const searchFn = computed(() => { }) const categories = computed(() => { - return Object.keys(data.value) + return Object.keys(data.value).filter(searchFn.value) }) +// const legendData = computed(() => { +// const l = categories.value.map((id) => { +// return { +// name: id, +// icon: 'circle', +// } +// }) + +// console.log(l) + +// return l +// }) + function generatorHashColorByString(str: string) { let hash = 0 for (let i = 0; i < str.length; i++) { @@ -80,7 +94,7 @@ const waterfallData = computed(() => { if (searchFn.value(id) && searchFn.value(s.name)) { result.push({ name: typeItem ? typeItem.name : id, - value: [index, s.start, s.end, duration], + value: [index, s.start, (s.end - s.start) < 1 ? 1 : s.end, duration], itemStyle: { normal: { color: typeItem ? typeItem.color : '#000', @@ -91,6 +105,8 @@ const waterfallData = computed(() => { }) }) + // console.log(result) + return result }) @@ -108,6 +124,7 @@ getHot().then((hot) => { }) use([ + VisualMapComponent, CanvasRenderer, BarChart, TooltipComponent, @@ -151,15 +168,34 @@ function renderItem(params: CustomSeriesRenderItemParams | any, api: CustomSerie const option = computed(() => ({ tooltip: { formatter(params: TopLevelFormatterParams | any) { - return `${params.marker + params.name}: ${params.value[3]} ms` + return `${params.marker + params.name}: ${params.value[3] <= 1 ? '<1' : params.value[3]}ms}` }, } satisfies TooltipComponentOption, + legendData: { + top: 'center', + data: ['c'], + } satisfies LegendComponentOption, + title: { text: 'Waterfall', + // left: 'center', + }, + visualMap: { + type: 'piecewise', + // show: false, + orient: 'horizontal', left: 'center', + bottom: 10, + pieces: [ + + ], + seriesIndex: 1, + dimension: 1, }, dataZoom: [ + // 最多支持放大到1ms + { type: 'slider', filterMode: 'weakFilter', @@ -178,10 +214,14 @@ const option = computed(() => ({ xAxis: { min: startTime.value, max: endTime.value, + // type: 'value', + scale: true, axisLabel: { formatter(val: number) { - return `${Math.max(0, val - startTime.value)} ms` + // console.log(val, startTime.value, val - startTime.value, Math.max(0, val - startTime.value)) + + return `${Math.max(0, val - startTime.value).toFixed(2)} ms` }, }, } satisfies SingleAxisComponentOption, @@ -191,6 +231,7 @@ const option = computed(() => ({ series: [ { type: 'custom', + name: 'c', renderItem, itemStyle: { opacity: 0.8, From aa16759ec5d658e62f513d41f9e62cc9ae18ac7d Mon Sep 17 00:00:00 2001 From: liliang18 Date: Wed, 18 Sep 2024 19:12:29 +0800 Subject: [PATCH 3/3] fix: remove etc btns --- src/client/pages/index/waterfall.vue | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/client/pages/index/waterfall.vue b/src/client/pages/index/waterfall.vue index 66b21c1..d60efb5 100644 --- a/src/client/pages/index/waterfall.vue +++ b/src/client/pages/index/waterfall.vue @@ -31,8 +31,8 @@ const { height } = useElementSize(container) const data = shallowRef(await rpc.getWaterfallInfo(inspectSSR.value)) const startTime = computed(() => Math.min(...Object.values(data.value).map(i => i[0]?.start ?? Infinity))) const endTime = computed(() => Math.max(...Object.values(data.value).map(i => i[i.length - 1]?.end ?? -Infinity)) + 1000) -const scale = ref(0.3) +// const reversed = ref(false) const searchText = ref('') const searchFn = computed(() => { const text = searchText.value.trim() @@ -219,9 +219,7 @@ const option = computed(() => ({ scale: true, axisLabel: { formatter(val: number) { - // console.log(val, startTime.value, val - startTime.value, Math.max(0, val - startTime.value)) - - return `${Math.max(0, val - startTime.value).toFixed(2)} ms` + return `${(val - startTime.value).toFixed(val % 1 ? 2 : 0)} ms` }, }, } satisfies SingleAxisComponentOption, @@ -269,12 +267,10 @@ const chartStyle = computed(() => { - - + +