1
- // Initialize Cytoscape
2
- // main.js
1
+ // @ts -nocheck
3
2
import { getTooltipPosition } from "./graphUtils.js" ;
4
3
import {
5
4
deleteAllBorders ,
6
5
drawBorderAndIconForEachExplainNode ,
7
- } from "./borderDraw.js" ;
8
- // // @ts -ignore
9
- // const iconMap = window.iconMap;
10
- // @ts -ignore
6
+ } from "./borderAndIconDraw.js" ;
7
+
11
8
const tooltips = window . tooltips ;
12
- // @ts -ignore
13
9
const vscode = window . acquireVsCodeApi ( ) ;
14
- // @ts -ignore
10
+
11
+ // Initialize Cytoscape
15
12
const cy = cytoscape ( {
16
13
container : document . getElementById ( "diagramContainer" ) ,
17
- // @ts -ignore
18
14
elements : window . data ,
19
-
20
15
style : [
21
16
{
22
17
selector : "node" ,
@@ -43,95 +38,22 @@ const cy = cytoscape({
43
38
} ,
44
39
] ,
45
40
46
- // Layout options
47
41
layout : {
48
42
name : "grid" ,
49
43
padding : 50 , // Padding around the graph
50
44
spacingFactor : 0.9 , // Spacing between nodes
51
45
} ,
52
46
} ) ;
53
47
54
- // Add click event to show alert for nodes
48
+ // When clicked, we display the details for the node in the bottom tree view
55
49
cy . on ( "tap" , "node" , function ( evt ) {
56
50
const id = evt . target . id ( ) ;
57
- // @ts -ignore
58
51
vscode . postMessage ( {
59
52
command : "selected" ,
60
53
nodeId : id ,
61
54
} ) ;
62
55
} ) ;
63
56
64
- // const getCodiconClass = (label) => {
65
- // const className = iconMap[label];
66
- // return className !== undefined ? `codicon-${className}` : "";
67
- // };
68
-
69
- // cy.nodeHtmlLabel([
70
- // {
71
- // query: ".l1",
72
- // valign: "top",
73
- // halign: "center",
74
- // valignBox: "top",
75
- // halignBox: "center",
76
- // tpl: function (data) {
77
- // const className = getCodiconClass(data.label);
78
- // return `<div><div class="icon"><i class="codicon ${className}"></i></div>`;
79
- // },
80
- // },
81
- // ]);
82
-
83
- // cy.nodes().on("mouseover", (event) => {
84
- // const node = event.target;
85
- // const id = node.id();
86
- // const tooltip = tooltips[id];
87
- // const hoverDiv = document.createElement("pre");
88
- // hoverDiv.innerText = tooltip;
89
- // hoverDiv.className = "hover-box";
90
- // document.body.appendChild(hoverDiv);
91
-
92
- // function updatePosition() {
93
- // const { x, y } = node.renderedPosition(); // center of node
94
- // const containerRect = cy.container().getBoundingClientRect(); // Cytoscape canvas
95
- // const boxRect = hoverDiv.getBoundingClientRect(); // Tooltip box
96
- // const boxWidth = boxRect.width;
97
- // const boxHeight = boxRect.height;
98
-
99
- // const nodeTopY = y - node.renderedOuterHeight() / 2;
100
- // const offset = 20;
101
-
102
- // let top = nodeTopY + containerRect.top - boxHeight - offset;
103
- // let left = x + containerRect.left - boxWidth / 2;
104
-
105
- // // Constrain to visible area
106
- // const viewportWidth = window.innerWidth;
107
- // const viewportHeight = window.innerHeight;
108
-
109
- // // Keep inside horizontal bounds
110
- // if (left < 4) left = 4;
111
- // if (left + boxWidth > viewportWidth - 4) {
112
- // left = viewportWidth - boxWidth - 4;
113
- // }
114
-
115
- // // If tooltip would be cut off vertically, show it *below* the node instead
116
- // if (top < 4) {
117
- // top = y + containerRect.top + node.renderedOuterHeight() / 2;
118
- // }
119
-
120
- // hoverDiv.style.left = `${left}px`;
121
- // hoverDiv.style.top = `${top}px`;
122
- // }
123
-
124
- // updatePosition(); // initial position
125
- // cy.on("pan zoom resize", updatePosition);
126
- // node.on("position", updatePosition);
127
-
128
- // node.once("mouseout", () => {
129
- // hoverDiv.remove();
130
- // cy.off("pan zoom resize", updatePosition);
131
- // node.off("position", updatePosition);
132
- // });
133
- // });
134
-
135
57
// === Tooltip Hover Handler ===
136
58
cy . nodes ( ) . on ( "mouseover" , ( event ) => {
137
59
const node = event . target ;
0 commit comments