Skip to content

Commit 1bf06b0

Browse files
committed
Click on node to show detail
Signed-off-by: worksofliam <[email protected]>
1 parent 501c16f commit 1bf06b0

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/views/cytoscape/index.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,17 @@ export class CytoscapeGraph {
4848
return id;
4949
}
5050

51-
createView(title: string) {
51+
createView(title: string, onNodeSelected: (data: unknown) => void): any {
5252
const webview = window.createWebviewPanel(`c`, title, {viewColumn: ViewColumn.One}, {enableScripts: true, retainContextWhenHidden: true});
5353
webview.webview.html = this.getHtml();
5454

55+
webview.webview.onDidReceiveMessage((message) => {
56+
if (message.command === 'selected') {
57+
const data = this.elementData.get(message.nodeId);
58+
onNodeSelected(data);
59+
}
60+
}, undefined, []);
61+
5562
return webview;
5663
}
5764

@@ -90,6 +97,7 @@ export class CytoscapeGraph {
9097
<div class="diagram-container" id="diagramContainer"></div>
9198
9299
<script>
100+
const vscode = acquireVsCodeApi();
93101
document.addEventListener("DOMContentLoaded", function () {
94102
// Initialize Cytoscape
95103
const cy = cytoscape({
@@ -136,8 +144,11 @@ export class CytoscapeGraph {
136144
137145
// Add click event to show alert for nodes
138146
cy.on('tap', 'node', function (evt) {
139-
const node = evt.target;
140-
console.log("You clicked: " + node.data('label'));
147+
const id = evt.target.id();
148+
vscode.postMessage({
149+
command: 'selected',
150+
nodeId: id
151+
});
141152
});
142153
});
143154
</script>

src/views/results/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,16 +254,14 @@ async function runHandler(options?: StatementInfo) {
254254

255255
explainTree = new ExplainTree(explained.vedata);
256256
const topLevel = explainTree.get();
257-
const rootNode = doveResultsView.setRootNode(topLevel);
258-
doveNodeView.setNode(rootNode.explainNode);
259-
doveTreeDecorationProvider.updateTreeItems(rootNode);
260-
257+
261258
const graph = new CytoscapeGraph();
262259

263260
function addNode(node: ExplainNode, parent?: string) {
264261
const id = graph.addNode({
265262
label: node.title,
266263
parent: parent,
264+
data: node,
267265
});
268266

269267
if (node.children) {
@@ -275,7 +273,11 @@ async function runHandler(options?: StatementInfo) {
275273

276274
addNode(topLevel);
277275

278-
const webview = graph.createView(`Explain Graph`);
276+
const webview = graph.createView(`Explain Graph`, (data: ExplainNode) => {
277+
if (data) {
278+
doveNodeView.setNode(data);
279+
}
280+
});
279281

280282
} else {
281283
vscode.window.showInformationMessage(`No job currently selected.`);

0 commit comments

Comments
 (0)