1
1
import { ViewColumn , window } from "vscode" ;
2
- import * as vscode from ' vscode' ;
2
+ import * as vscode from " vscode" ;
3
3
import { ContextProvider } from "../../contextProvider" ;
4
4
import { icons } from "../results/explain/icons" ;
5
+ import { ExplainNode } from "../results/explain/nodes" ;
5
6
6
- export type Styles = { [ key : string ] : string } ;
7
+ export type Styles = { [ key : string ] : string } ;
7
8
8
9
export 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 ;
12
13
}
13
14
14
15
export interface Edge {
15
- data : { id : string , source : string , target : string }
16
+ data : { id : string ; source : string ; target : string } ;
16
17
}
17
18
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 ;
23
24
}
24
25
25
26
const randomId = ( ) => Math . random ( ) . toString ( 36 ) . substring ( 7 ) ;
26
27
27
28
export class CytoscapeGraph {
28
29
private elementData = new Map < string , any > ( ) ;
30
+ private tooltips = { } ;
29
31
private elements : Element [ ] = [ ] ;
30
32
private edges : Edge [ ] = [ ] ;
31
33
@@ -36,49 +38,109 @@ export class CytoscapeGraph {
36
38
37
39
if ( node . data ) {
38
40
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 ;
39
45
}
40
46
41
47
this . elements . push ( {
42
- data : { id, label : node . label } ,
48
+ data : { id, label : node . label } ,
43
49
style : node . styles || { } ,
44
- classes : "l1"
50
+ classes : "l1" ,
45
51
} ) ;
46
52
47
53
if ( node . parent ) {
48
54
this . edges . push ( {
49
- data : { id : randomId ( ) , source : node . parent , target : id }
55
+ data : { id : randomId ( ) , source : node . parent , target : id } ,
50
56
} ) ;
51
57
}
52
58
53
59
return id ;
54
60
}
55
61
56
62
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
+ ) ;
58
69
webview . webview . html = this . getHtml ( webview . webview ) ;
59
70
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
+ ) ;
66
81
67
82
return webview ;
68
83
}
69
84
70
85
private getHtml ( webview : vscode . Webview ) : string {
71
- const data = JSON . stringify ( [ ...this . elements , ...this . edges ] )
86
+ const data = JSON . stringify ( [ ...this . elements , ...this . edges ] ) ;
72
87
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*/ `
82
144
<!DOCTYPE html>
83
145
<html lang="en">
84
146
@@ -93,6 +155,7 @@ export class CytoscapeGraph {
93
155
<script>
94
156
window.data = ${ data } ;
95
157
window.iconMap = ${ iconMap }
158
+ window.tooltips = ${ tooltips }
96
159
</script>
97
160
</head>
98
161
<body>
@@ -101,4 +164,4 @@ export class CytoscapeGraph {
101
164
</html>
102
165
` ;
103
166
}
104
- }
167
+ }
0 commit comments