|
5 | 5 | * for exporting NetVis graphs as standalone HTML files. |
6 | 6 | */ |
7 | 7 |
|
| 8 | +import { STANDALONE_BUNDLE } from './standaloneBundleContent'; |
| 9 | + |
8 | 10 | /** |
9 | 11 | * Configuration for HTML export. |
10 | 12 | */ |
@@ -60,8 +62,8 @@ export function generateStandaloneHtml(config: ExportConfig): string { |
60 | 62 | // Generate inline CSS |
61 | 63 | const css = generateCss(); |
62 | 64 |
|
63 | | - // Generate inline JavaScript (D3.js rendering code) |
64 | | - const js = generateJs(); |
| 65 | + // Get the pre-built JavaScript bundle (D3.js + rendering code) |
| 66 | + const js = getJsBundle(); |
65 | 67 |
|
66 | 68 | return `<!DOCTYPE html> |
67 | 69 | <html lang="en"> |
@@ -215,93 +217,11 @@ function generateCss(): string { |
215 | 217 | } |
216 | 218 |
|
217 | 219 | /** |
218 | | - * Generate JavaScript code for standalone HTML. |
219 | | - * This is a minimal D3.js-based graph renderer. |
| 220 | + * Get JavaScript bundle for standalone HTML. |
| 221 | + * |
| 222 | + * Returns the pre-built D3.js + NetVis rendering code bundle. |
| 223 | + * This is the same bundle used by Python's HTMLExporter. |
220 | 224 | */ |
221 | | -function generateJs(): string { |
222 | | - // For the standalone export, we need to include the D3.js bundle |
223 | | - // In the actual implementation, this would be loaded from the build |
224 | | - return ` |
225 | | - // NetVis standalone renderer |
226 | | - var netvis = (function() { |
227 | | - // Minimal graph rendering (placeholder for full D3.js bundle) |
228 | | - function renderGraph(container, data) { |
229 | | - if (!container) return; |
230 | | -
|
231 | | - const width = container.clientWidth || 800; |
232 | | - const height = container.clientHeight || 600; |
233 | | -
|
234 | | - // Create SVG |
235 | | - const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); |
236 | | - svg.setAttribute('width', width); |
237 | | - svg.setAttribute('height', height); |
238 | | - svg.setAttribute('viewBox', '0 0 ' + width + ' ' + height); |
239 | | - container.appendChild(svg); |
240 | | -
|
241 | | - // Simple force-directed layout simulation |
242 | | - const nodes = data.nodes || []; |
243 | | - const links = data.links || []; |
244 | | -
|
245 | | - // Initialize node positions |
246 | | - nodes.forEach(function(node, i) { |
247 | | - node.x = node.x || width / 2 + (Math.random() - 0.5) * 200; |
248 | | - node.y = node.y || height / 2 + (Math.random() - 0.5) * 200; |
249 | | - }); |
250 | | -
|
251 | | - // Draw links |
252 | | - const linkGroup = document.createElementNS('http://www.w3.org/2000/svg', 'g'); |
253 | | - linkGroup.setAttribute('class', 'netvis-links'); |
254 | | - svg.appendChild(linkGroup); |
255 | | -
|
256 | | - links.forEach(function(link) { |
257 | | - const source = nodes.find(function(n) { return n.id === link.source || n.id === link.source.id; }); |
258 | | - const target = nodes.find(function(n) { return n.id === link.target || n.id === link.target.id; }); |
259 | | - if (source && target) { |
260 | | - const line = document.createElementNS('http://www.w3.org/2000/svg', 'line'); |
261 | | - line.setAttribute('class', 'netvis-link'); |
262 | | - line.setAttribute('x1', source.x); |
263 | | - line.setAttribute('y1', source.y); |
264 | | - line.setAttribute('x2', target.x); |
265 | | - line.setAttribute('y2', target.y); |
266 | | - line.setAttribute('stroke', '#999'); |
267 | | - line.setAttribute('stroke-opacity', '0.6'); |
268 | | - linkGroup.appendChild(line); |
269 | | - } |
270 | | - }); |
271 | | -
|
272 | | - // Draw nodes |
273 | | - const nodeGroup = document.createElementNS('http://www.w3.org/2000/svg', 'g'); |
274 | | - nodeGroup.setAttribute('class', 'netvis-nodes'); |
275 | | - svg.appendChild(nodeGroup); |
276 | | -
|
277 | | - nodes.forEach(function(node) { |
278 | | - const g = document.createElementNS('http://www.w3.org/2000/svg', 'g'); |
279 | | - g.setAttribute('class', 'netvis-node'); |
280 | | - g.setAttribute('transform', 'translate(' + node.x + ',' + node.y + ')'); |
281 | | -
|
282 | | - const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle'); |
283 | | - circle.setAttribute('r', 8); |
284 | | - circle.setAttribute('fill', node.color || '#69b3a2'); |
285 | | - circle.setAttribute('stroke', '#fff'); |
286 | | - circle.setAttribute('stroke-width', '1.5'); |
287 | | - g.appendChild(circle); |
288 | | -
|
289 | | - if (node.name || node.label) { |
290 | | - const text = document.createElementNS('http://www.w3.org/2000/svg', 'text'); |
291 | | - text.setAttribute('class', 'netvis-node-label'); |
292 | | - text.setAttribute('dx', '12'); |
293 | | - text.setAttribute('dy', '4'); |
294 | | - text.textContent = node.name || node.label; |
295 | | - g.appendChild(text); |
296 | | - } |
297 | | -
|
298 | | - nodeGroup.appendChild(g); |
299 | | - }); |
300 | | - } |
301 | | -
|
302 | | - return { |
303 | | - renderGraph: renderGraph |
304 | | - }; |
305 | | - })(); |
306 | | - `; |
| 225 | +function getJsBundle(): string { |
| 226 | + return STANDALONE_BUNDLE; |
307 | 227 | } |
0 commit comments