@@ -485,40 +485,53 @@ function crateGraph(ctx: Ctx, full: boolean): Cmd {
485
485
486
486
console . log ( dot ) ;
487
487
488
- let script_d3 = vscode . Uri . file ( path . join ( ctx . extensionPath , 'node_modules' , 'd3' , 'dist' , 'd3.min.js' ) ) ;
489
- let script_d3_gv = vscode . Uri . file ( path . join ( ctx . extensionPath , 'node_modules' , 'd3-graphviz' , 'build' , 'd3-graphviz.min.js' ) ) ;
490
- let script_wasm = vscode . Uri . file ( path . join ( ctx . extensionPath , 'node_modules' , '@hpcc-js' , 'wasm' , 'dist' , 'index.min.js' ) ) ;
491
-
492
- console . log ( script_d3 , script_d3_gv , script_wasm ) ;
488
+ let scripts = [
489
+ { file : vscode . Uri . file ( path . join ( ctx . extensionPath , 'node_modules' , 'd3' , 'dist' , 'd3.min.js' ) ) } ,
490
+ { file : vscode . Uri . file ( path . join ( ctx . extensionPath , 'node_modules' , '@hpcc-js' , 'wasm' , 'dist' , 'index.min.js' ) ) , worker : true } ,
491
+ { file : vscode . Uri . file ( path . join ( ctx . extensionPath , 'node_modules' , 'd3-graphviz' , 'build' , 'd3-graphviz.min.js' ) ) } ,
492
+ ]
493
+ console . log ( scripts ) ;
494
+
495
+ const scripts_html = scripts . map ( ( { file, worker } ) => {
496
+ let uri = panel . webview . asWebviewUri ( file ) ;
497
+ return `<script type="${ worker ? "javascript/worker" : "text/javascript" } " src="${ uri } "></script>`
498
+ } ) . join ( "\n" )
493
499
494
500
const html = `
495
- <!DOCTYPE html>
496
- <meta charset="utf-8">
497
- <head>
498
- <style>
499
- body {
500
- padding: 0px
501
- }
502
- ::-webkit-scrollbar {
503
- display: none;
504
- }
505
- </style>
506
- </head>
507
- <body>
508
- <script src="${ panel . webview . asWebviewUri ( script_d3 ) } "></script>
509
- <script src="${ panel . webview . asWebviewUri ( script_wasm ) } "></script>
510
- <script src="${ panel . webview . asWebviewUri ( script_d3_gv ) } "></script>
511
- <div id="graph"></div>
512
- <script>
513
- d3.select("#graph")
514
- .graphviz()
515
- .fit(true)
516
- .width(window.innerWidth)
517
- .height(window.innerHeight)
518
- .renderDot(\`${ dot } \`);
519
- </script>
520
- </body>
521
- ` ;
501
+ <!DOCTYPE html>
502
+ <meta charset="utf-8">
503
+ <head>
504
+ <style>
505
+ /* Fill the entire view */
506
+ html, body { margin:0; padding:0; overflow:hidden }
507
+ svg { position:fixed; top:0; left:0; height:100%; width:100% }
508
+
509
+ /* Disable the graphviz backgroud and fill the polygons */
510
+ .graph > polygon { display:none; }
511
+ :is(.node,.edge) polygon { fill: white; }
512
+
513
+ /* Invert the line colours for dark themes */
514
+ body:not(.vscode-light) .edge path { stroke: white; }
515
+ </style>
516
+ </head>
517
+ <body>
518
+ ${ scripts_html }
519
+ <div id="graph"></div>
520
+ <script>
521
+ let graph = d3.select("#graph")
522
+ .graphviz()
523
+ .fit(true)
524
+ .zoomScaleExtent([0.1, Infinity])
525
+ .renderDot(\`${ dot } \`);
526
+
527
+ d3.select(window).on("click", (event) => {
528
+ if (event.ctrlKey) {
529
+ graph.resetZoom(d3.transition().duration(100));
530
+ }
531
+ });
532
+ </script>
533
+ </body>
534
+ ` ;
522
535
523
536
console . log ( html ) ;
524
537
0 commit comments