2
2
import type { TreeNodeInput } from ' nanovis'
3
3
import type { ModuleInfo , SessionContext } from ' ~~/shared/types'
4
4
import { Flamegraph , normalizeTreeNode } from ' nanovis'
5
- import { computed , defineProps , onMounted , ref , useTemplateRef } from ' vue'
5
+ import { computed , defineProps , onMounted , ref , shallowRef , useTemplateRef , watch } from ' vue'
6
6
7
7
const props = defineProps <{
8
8
info: ModuleInfo
@@ -59,9 +59,10 @@ const hoverNode = ref<{
59
59
const hoverX = ref <number >(0 )
60
60
const hoverY = ref <number >(0 )
61
61
const el = useTemplateRef <HTMLDivElement >(' el' )
62
+ const flamegraph = shallowRef <Flamegraph | null >(null )
62
63
63
- onMounted (() => {
64
- const flamegraph = new Flamegraph (tree .value , {
64
+ function buildFlamegraph() {
65
+ flamegraph . value = new Flamegraph (tree .value , {
65
66
animate: true ,
66
67
palette: {
67
68
fg: ' #888' ,
@@ -88,13 +89,26 @@ onMounted(() => {
88
89
}
89
90
},
90
91
})
92
+ el .value ! .appendChild (flamegraph .value ! .el )
93
+ }
91
94
92
- el .value ! .appendChild (flamegraph .el )
95
+ function disposeFlamegraph() {
96
+ flamegraph .value ?.dispose ()
97
+ }
93
98
99
+ onMounted (() => {
100
+ buildFlamegraph ()
94
101
return () => {
95
- flamegraph . dispose ()
102
+ disposeFlamegraph ()
96
103
}
97
104
})
105
+
106
+ watch (tree , async () => {
107
+ disposeFlamegraph ()
108
+ buildFlamegraph ()
109
+ }, {
110
+ deep: true ,
111
+ })
98
112
</script >
99
113
100
114
<template >
0 commit comments