-
-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: waterfall view #118
Draft
KermanX
wants to merge
23
commits into
antfu-collective:main
Choose a base branch
from
KermanX:feat/waterfall
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
feat: waterfall view #118
Changes from 15 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
9677bfe
feat: waterfall
KermanX 64bcf74
chore: update
KermanX 9ef9862
fix
KermanX 0680408
fix
KermanX 4e70c6e
fix
KermanX 7a6fc29
update
KermanX ae7f8e1
fix light mode
KermanX 74907a8
fix
KermanX f0d93ef
Merge branch 'main' into pr/KermanX/118
antfu a599931
refactor: waterfall via echarts
83d95da
fix: fix time range
aa16759
fix: remove etc btns
9550157
Merge pull request #1 from ArthurDarkstone/feat/waterfall-echarts
KermanX b28c2f9
Merge branch 'main' into feat/waterfall
KermanX fe940e2
fix: limit waterfall only for dev
9a983d0
feat: sort by asc & add filters
34d5495
Merge branch 'main' into feat/waterfall
KermanX 0bee4c0
Merge branch 'feat/waterfall' of https://github.com/kermanx/vite-plug…
KermanX 3a67362
fix
KermanX 39b9138
chore: update
KermanX 9d28411
feat: stacked view
KermanX cad4f94
chore: update
KermanX 979fdef
wip: hmr event
KermanX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
<script setup lang="ts"> | ||
const emit = defineEmits(['element']) | ||
</script> | ||
|
||
<template> | ||
<div class="h-[calc(100vh-55px)]"> | ||
<div :ref="el => emit('element', el)" class="h-[calc(100vh-55px)]"> | ||
<slot /> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,285 @@ | ||
<script setup lang="ts"> | ||
import { graphic, use } from 'echarts/core' | ||
import { CanvasRenderer } from 'echarts/renderers' | ||
import type { CustomSeriesOption } from 'echarts/charts' | ||
import { BarChart, CustomChart } from 'echarts/charts' | ||
import type { | ||
SingleAxisComponentOption, | ||
TooltipComponentOption, | ||
} from 'echarts/components' | ||
import { | ||
DataZoomComponent, | ||
GridComponent, | ||
LegendComponent, | ||
TitleComponent, | ||
TooltipComponent, | ||
VisualMapComponent, | ||
} from 'echarts/components' | ||
import VChart from 'vue-echarts' | ||
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' | ||
|
||
const container = ref<HTMLDivElement | null>() | ||
|
||
const dataZoomBar = 100 | ||
const zoomBarOffset = 100 | ||
|
||
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 reversed = ref(false) | ||
const searchText = ref('') | ||
const searchFn = computed(() => { | ||
const text = searchText.value.trim() | ||
if (text === '') { | ||
return () => true | ||
} | ||
const regex = new RegExp(text, 'i') | ||
return (name: string) => regex.test(name) | ||
}) | ||
|
||
const categories = computed(() => { | ||
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++) { | ||
hash = str.charCodeAt(i) + ((hash << 5) - hash) | ||
} | ||
let color = '#' | ||
for (let i = 0; i < 3; i++) { | ||
const value = (hash >> (i * 8)) & 0xFF | ||
color += (`00${value.toString(16)}`).substr(-2) | ||
} | ||
return color | ||
} | ||
|
||
const types = computed(() => { | ||
return Object.keys(data.value).map((id) => { | ||
return { | ||
name: id, | ||
color: generatorHashColorByString(id), | ||
} | ||
}) | ||
}) | ||
|
||
const waterfallData = computed(() => { | ||
const result: any = [] | ||
|
||
Object.entries(data.value).forEach(([id, steps], index) => { | ||
steps.forEach((s) => { | ||
const typeItem = types.value.find(i => i.name === id) | ||
|
||
const duration = s.end - s.start | ||
|
||
if (searchFn.value(id) && searchFn.value(s.name)) { | ||
result.push({ | ||
name: typeItem ? typeItem.name : id, | ||
value: [index, s.start, (s.end - s.start) < 1 ? 1 : s.end, duration], | ||
itemStyle: { | ||
normal: { | ||
color: typeItem ? typeItem.color : '#000', | ||
}, | ||
}, | ||
}) | ||
} | ||
}) | ||
}) | ||
|
||
// console.log(result) | ||
|
||
return result | ||
}) | ||
|
||
async function refetch() { | ||
data.value = await rpc.getWaterfallInfo(inspectSSR.value) | ||
} | ||
|
||
onRefetch.on(refetch) | ||
watch(inspectSSR, refetch) | ||
|
||
getHot().then((hot) => { | ||
if (hot) { | ||
hot.on('vite-plugin-inspect:update', refetch) | ||
} | ||
}) | ||
|
||
use([ | ||
VisualMapComponent, | ||
CanvasRenderer, | ||
BarChart, | ||
TooltipComponent, | ||
TitleComponent, | ||
LegendComponent, | ||
GridComponent, | ||
DataZoomComponent, | ||
CustomChart, | ||
]) | ||
|
||
function renderItem(params: CustomSeriesRenderItemParams | any, api: CustomSeriesRenderItemAPI): CustomSeriesRenderItemReturn { | ||
const categoryIndex = api.value(0) | ||
const start = api.coord([api.value(1), categoryIndex]) | ||
const end = api.coord([api.value(2), categoryIndex]) | ||
const height = (api.size?.([0, 1]) as number[])[1] * 0.6 | ||
const rectShape = graphic.clipRectByRect( | ||
{ | ||
x: start[0], | ||
y: start[1] - height / 2, | ||
width: end[0] - start[0], | ||
height, | ||
}, | ||
{ | ||
x: params.coordSys.x, | ||
y: params.coordSys.y, | ||
width: params.coordSys.width, | ||
height: params.coordSys.height, | ||
}, | ||
) | ||
|
||
return ( | ||
rectShape && { | ||
type: 'rect', | ||
transition: ['shape'], | ||
shape: rectShape, | ||
style: api.style(), | ||
} | ||
) | ||
} | ||
|
||
const option = computed(() => ({ | ||
tooltip: { | ||
formatter(params: TopLevelFormatterParams | any) { | ||
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', | ||
showDataShadow: false, | ||
top: height.value - dataZoomBar, | ||
labelFormatter: '', | ||
}, | ||
{ | ||
type: 'inside', | ||
filterMode: 'weakFilter', | ||
}, | ||
], | ||
grid: { | ||
height: height.value - dataZoomBar - zoomBarOffset, | ||
}, | ||
xAxis: { | ||
min: startTime.value, | ||
max: endTime.value, | ||
// type: 'value', | ||
|
||
scale: true, | ||
axisLabel: { | ||
formatter(val: number) { | ||
return `${(val - startTime.value).toFixed(val % 1 ? 2 : 0)} ms` | ||
}, | ||
}, | ||
} satisfies SingleAxisComponentOption, | ||
yAxis: { | ||
data: categories.value, | ||
} satisfies SingleAxisComponentOption, | ||
series: [ | ||
{ | ||
type: 'custom', | ||
name: 'c', | ||
renderItem, | ||
itemStyle: { | ||
opacity: 0.8, | ||
}, | ||
encode: { | ||
x: [1, 2], | ||
y: 0, | ||
}, | ||
data: waterfallData.value, | ||
}, | ||
] satisfies CustomSeriesOption[], | ||
|
||
})) | ||
|
||
const chartStyle = computed(() => { | ||
return { | ||
height: `${height.value}px`, | ||
} | ||
}) | ||
</script> | ||
|
||
<template> | ||
<NavBar> | ||
<RouterLink class="my-auto icon-btn !outline-none" to="/"> | ||
<div i-carbon-arrow-left /> | ||
</RouterLink> | ||
<div my-auto text-sm font-mono> | ||
Waterfall | ||
</div> | ||
<input v-model="searchText" placeholder="Search..." class="w-full px-4 py-2 text-xs"> | ||
|
||
<button text-lg icon-btn title="Inspect SSR" @click="inspectSSR = !inspectSSR"> | ||
<div i-carbon-cloud-services :class="inspectSSR ? 'opacity-100' : 'opacity-25'" /> | ||
</button> | ||
<button class="text-lg icon-btn" title="Show resolveId" @click="waterfallShowResolveId = !waterfallShowResolveId"> | ||
<div i-carbon-connect-source :class="waterfallShowResolveId ? 'opacity-100' : 'opacity-25'" /> | ||
</button> | ||
|
||
<!-- <button class="text-lg icon-btn" title="Show resolveId" @click="reversed = !reversed"> | ||
<div i-carbon-arrows-vertical :class="reversed ? 'opacity-100' : 'opacity-25'" /> | ||
</button> --> | ||
<div flex-auto /> | ||
</NavBar> | ||
|
||
<div ref="container" h-full p4> | ||
<div v-if="!waterfallData.length" flex="~" h-40 w-full> | ||
<div ma italic op50> | ||
No data | ||
</div> | ||
</div> | ||
<VChart class="w-100%" :style="chartStyle" :option="option" autoresize /> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
group by id or plugin name ?