11import { ViewColumn , window } from "vscode" ;
2- import * as vscode from ' vscode' ;
2+ import * as vscode from " vscode" ;
33import { ContextProvider } from "../../contextProvider" ;
44import { icons } from "../results/explain/icons" ;
5+ import { ExplainNode } from "../results/explain/nodes" ;
56
6- export type Styles = { [ key : string ] : string } ;
7+ export type Styles = { [ key : string ] : string } ;
78
89export interface Element {
9- data : { id : string , label : string } ,
10- style : Styles ,
11- classes : string
10+ data : { id : string ; label : string } ;
11+ style : Styles ;
12+ classes : string ;
1213}
1314
1415export interface Edge {
15- data : { id : string , source : string , target : string }
16+ data : { id : string ; source : string ; target : string } ;
1617}
1718
18- interface NewNode {
19- label : string ,
20- styles ?: Styles ,
21- parent ?: string ,
22- data ?: any ;
19+ interface NewNode {
20+ label : string ;
21+ styles ?: Styles ;
22+ parent ?: string ;
23+ data ?: ExplainNode ;
2324}
2425
2526const randomId = ( ) => Math . random ( ) . toString ( 36 ) . substring ( 7 ) ;
2627
2728export class CytoscapeGraph {
2829 private elementData = new Map < string , any > ( ) ;
30+ private tooltips = { } ;
2931 private elements : Element [ ] = [ ] ;
3032 private edges : Edge [ ] = [ ] ;
3133
@@ -36,49 +38,109 @@ export class CytoscapeGraph {
3638
3739 if ( node . data ) {
3840 this . elementData . set ( id , node . data ) ;
41+ const tooltip = node . data . tooltipProps
42+ . map ( ( prop ) => `${ prop . title } : ${ prop . value } ` )
43+ . join ( "\n" ) ;
44+ this . tooltips [ id ] = tooltip ;
3945 }
4046
4147 this . elements . push ( {
42- data : { id, label : node . label } ,
48+ data : { id, label : node . label } ,
4349 style : node . styles || { } ,
44- classes : "l1"
50+ classes : "l1" ,
4551 } ) ;
4652
4753 if ( node . parent ) {
4854 this . edges . push ( {
49- data : { id : randomId ( ) , source : node . parent , target : id }
55+ data : { id : randomId ( ) , source : node . parent , target : id } ,
5056 } ) ;
5157 }
5258
5359 return id ;
5460 }
5561
5662 createView ( title : string , onNodeSelected : ( data : unknown ) => void ) : any {
57- const webview = window . createWebviewPanel ( `c` , title , { viewColumn : ViewColumn . One } , { enableScripts : true , retainContextWhenHidden : true } ) ;
63+ const webview = window . createWebviewPanel (
64+ `c` ,
65+ title ,
66+ { viewColumn : ViewColumn . One } ,
67+ { enableScripts : true , retainContextWhenHidden : true }
68+ ) ;
5869 webview . webview . html = this . getHtml ( webview . webview ) ;
5970
60- webview . webview . onDidReceiveMessage ( ( message ) => {
61- if ( message . command === 'selected' ) {
62- const data = this . elementData . get ( message . nodeId ) ;
63- onNodeSelected ( data ) ;
64- }
65- } , undefined , [ ] ) ;
71+ webview . webview . onDidReceiveMessage (
72+ ( message ) => {
73+ if ( message . command === "selected" ) {
74+ const data = this . elementData . get ( message . nodeId ) ;
75+ onNodeSelected ( data ) ;
76+ }
77+ } ,
78+ undefined ,
79+ [ ]
80+ ) ;
6681
6782 return webview ;
6883 }
6984
7085 private getHtml ( webview : vscode . Webview ) : string {
71- const data = JSON . stringify ( [ ...this . elements , ...this . edges ] )
86+ const data = JSON . stringify ( [ ...this . elements , ...this . edges ] ) ;
7287 const iconMap = JSON . stringify ( icons ) ;
73- const context = ContextProvider . getContext ( )
74- const cssUri = webview . asWebviewUri ( vscode . Uri . joinPath ( context . extensionUri , 'src' , 'views' , 'cytoscape' , 'media' , 'explain.css' ) )
75- const codiconsUri = webview . asWebviewUri ( vscode . Uri . joinPath ( context . extensionUri , 'src' , 'views' , 'cytoscape' , 'media' , 'codicons' , 'dist' , 'codicon.css' ) )
76- const cytoscapeUri = webview . asWebviewUri ( vscode . Uri . joinPath ( context . extensionUri , 'src' , 'views' , 'cytoscape' , 'media' , 'cytoscape.min.js' ) )
77- const cytoscapeHtmlLabelUri = webview . asWebviewUri ( vscode . Uri . joinPath ( context . extensionUri , 'src' , 'views' , 'cytoscape' , 'media' , 'cytoscape-node-html-label.min.js' ) )
78- const explainUri = webview . asWebviewUri ( vscode . Uri . joinPath ( context . extensionUri , 'src' , 'views' , 'cytoscape' , 'media' , 'explain.js' ) )
79-
80-
81- return /*html*/ `
88+ const tooltips = JSON . stringify ( this . tooltips ) ;
89+ const context = ContextProvider . getContext ( ) ;
90+ const cssUri = webview . asWebviewUri (
91+ vscode . Uri . joinPath (
92+ context . extensionUri ,
93+ "src" ,
94+ "views" ,
95+ "cytoscape" ,
96+ "media" ,
97+ "explain.css"
98+ )
99+ ) ;
100+ const codiconsUri = webview . asWebviewUri (
101+ vscode . Uri . joinPath (
102+ context . extensionUri ,
103+ "src" ,
104+ "views" ,
105+ "cytoscape" ,
106+ "media" ,
107+ "codicons" ,
108+ "dist" ,
109+ "codicon.css"
110+ )
111+ ) ;
112+ const cytoscapeUri = webview . asWebviewUri (
113+ vscode . Uri . joinPath (
114+ context . extensionUri ,
115+ "src" ,
116+ "views" ,
117+ "cytoscape" ,
118+ "media" ,
119+ "cytoscape.min.js"
120+ )
121+ ) ;
122+ const cytoscapeHtmlLabelUri = webview . asWebviewUri (
123+ vscode . Uri . joinPath (
124+ context . extensionUri ,
125+ "src" ,
126+ "views" ,
127+ "cytoscape" ,
128+ "media" ,
129+ "cytoscape-node-html-label.min.js"
130+ )
131+ ) ;
132+ const explainUri = webview . asWebviewUri (
133+ vscode . Uri . joinPath (
134+ context . extensionUri ,
135+ "src" ,
136+ "views" ,
137+ "cytoscape" ,
138+ "media" ,
139+ "explain.js"
140+ )
141+ ) ;
142+
143+ return /*html*/ `
82144 <!DOCTYPE html>
83145 <html lang="en">
84146
@@ -93,6 +155,7 @@ export class CytoscapeGraph {
93155 <script>
94156 window.data = ${ data } ;
95157 window.iconMap = ${ iconMap }
158+ window.tooltips = ${ tooltips }
96159 </script>
97160 </head>
98161 <body>
@@ -101,4 +164,4 @@ export class CytoscapeGraph {
101164 </html>
102165 ` ;
103166 }
104- }
167+ }
0 commit comments