-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathGraphContainer.vue
More file actions
223 lines (200 loc) · 5.34 KB
/
GraphContainer.vue
File metadata and controls
223 lines (200 loc) · 5.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<script setup lang="ts">
import {
generateChunkGraphMermaid,
generateModuleGraphMermaid,
} from '~/composables/graph-mermaid'
import type { ChunkNode, ModuleNode } from '~/composables/bundler'
const props = defineProps<{
moduleGraph?: ModuleNode[]
chunkGraph?: ChunkNode[]
isLoading?: boolean
}>()
const activeTab = ref<'module' | 'chunk'>('module')
const { mermaidLoaded, mermaidError, renderDiagram } = useMermaid()
const moduleGraphSvg = ref<string>('')
const chunkGraphSvg = ref<string>('')
const renderError = ref<string | null>(null)
// Compute graph statistics
const stats = computed(() => {
return {
modules: props.moduleGraph?.length || 0,
chunks: props.chunkGraph?.length || 0,
entries: props.moduleGraph?.filter((m) => m.isEntry).length || 0,
}
})
// Render module graph when data changes
watch(
() => props.moduleGraph,
async (modules) => {
if (!modules || modules.length === 0) {
moduleGraphSvg.value = ''
return
}
const definition = generateModuleGraphMermaid(modules)
const svg = await renderDiagram(definition, 'module-graph')
if (svg) {
moduleGraphSvg.value = svg
renderError.value = null
} else {
renderError.value = 'Failed to render module graph'
}
},
{ immediate: true },
)
// Render chunk graph when data changes
watch(
() => props.chunkGraph,
async (chunks) => {
if (!chunks || chunks.length === 0) {
chunkGraphSvg.value = ''
return
}
const definition = generateChunkGraphMermaid(chunks)
const svg = await renderDiagram(definition, 'chunk-graph')
if (svg) {
chunkGraphSvg.value = svg
renderError.value = null
} else {
renderError.value = 'Failed to render chunk graph'
}
},
{ immediate: true },
)
</script>
<template>
<div h-full flex flex-col>
<div flex items-center border-b border-base>
<button
class="graph-tab"
:class="activeTab === 'module' && 'tab-active'"
@click="activeTab = 'module'"
>
Module Graph
</button>
<button
class="graph-tab"
:class="activeTab === 'chunk' && 'tab-active'"
@click="activeTab = 'chunk'"
>
Chunk Graph
</button>
</div>
<div min-h-0 w-full flex-1 overflow-auto p4>
<Loading v-if="props.isLoading" text="Loading graph..." />
<!-- Error Message -->
<div v-else-if="mermaidError || renderError" class="error-state">
<div i-ph:warning text-6xl text-red op60 />
<div mt4 text-secondary>
{{ mermaidError || renderError }}
</div>
</div>
<!-- Module Graph View -->
<div
v-else-if="activeTab === 'module'"
class="graph-container"
flex="~ col"
items-center
>
<div v-if="stats.modules > 0" mb4 w-full text-sm text-secondary>
<div>{{ stats.modules }} modules, {{ stats.entries }} entries</div>
</div>
<div
v-if="moduleGraphSvg"
class="mermaid-diagram"
v-html="moduleGraphSvg"
/>
<div v-else-if="!mermaidLoaded" class="empty-state">
<div i-ph:graph text-6xl text-secondary op40 />
<div mt4 text-secondary>Loading Mermaid...</div>
</div>
<div v-else class="empty-state">
<div i-ph:graph text-6xl text-secondary op40 />
<div mt4 text-secondary>No module graph data available</div>
</div>
</div>
<!-- Chunk Graph View -->
<div
v-else-if="activeTab === 'chunk'"
class="graph-container"
flex="~ col"
items-center
>
<div v-if="stats.chunks > 0" mb4 w-full text-sm text-secondary>
<div>{{ stats.chunks }} chunks</div>
</div>
<div
v-if="chunkGraphSvg"
class="mermaid-diagram"
v-html="chunkGraphSvg"
/>
<div v-else-if="!mermaidLoaded" class="empty-state">
<div i-ph:graph text-6xl text-secondary op40 />
<div mt4 text-secondary>Loading Mermaid...</div>
</div>
<div v-else class="empty-state">
<div i-ph:graph text-6xl text-secondary op40 />
<div mt4 text-secondary>No chunk graph data available</div>
</div>
</div>
</div>
</div>
</template>
<style scoped>
.graph-tab {
display: flex;
align-items: center;
gap: 4px;
padding: 8px 16px;
cursor: pointer;
white-space: nowrap;
font-size: 13px;
color: var(--c-text-secondary);
border-bottom: 2px solid transparent;
transition:
color var(--transition-fast),
background var(--transition-fast),
border-color var(--transition-fast);
}
.graph-tab:hover {
color: var(--c-text-base);
background: var(--c-bg-mute);
}
.graph-tab.tab-active {
color: var(--c-accent);
border-bottom-color: var(--c-accent);
}
.graph-container {
width: 100%;
max-width: 100%;
}
.mermaid-diagram {
width: 100%;
display: flex;
justify-content: center;
overflow: auto;
}
.mermaid-diagram :deep(svg) {
max-width: 100%;
height: auto;
}
.empty-state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100%;
min-height: 200px;
}
.error-state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100%;
min-height: 200px;
color: #dc2626;
}
:global(.dark) .error-state {
color: #f87171;
}
</style>