1- // Initialize Cytoscape
2- // main.js
1+ // @ts -nocheck
32import { getTooltipPosition } from "./graphUtils.js" ;
43import {
54 deleteAllBorders ,
65 drawBorderAndIconForEachExplainNode ,
7- } from "./borderDraw.js" ;
8- // // @ts -ignore
9- // const iconMap = window.iconMap;
10- // @ts -ignore
6+ } from "./borderAndIconDraw.js" ;
7+
118const tooltips = window . tooltips ;
12- // @ts -ignore
139const vscode = window . acquireVsCodeApi ( ) ;
14- // @ts -ignore
10+
11+ // Initialize Cytoscape
1512const cy = cytoscape ( {
1613 container : document . getElementById ( "diagramContainer" ) ,
17- // @ts -ignore
1814 elements : window . data ,
19-
2015 style : [
2116 {
2217 selector : "node" ,
@@ -43,95 +38,22 @@ const cy = cytoscape({
4338 } ,
4439 ] ,
4540
46- // Layout options
4741 layout : {
4842 name : "grid" ,
4943 padding : 50 , // Padding around the graph
5044 spacingFactor : 0.9 , // Spacing between nodes
5145 } ,
5246} ) ;
5347
54- // Add click event to show alert for nodes
48+ // When clicked, we display the details for the node in the bottom tree view
5549cy . on ( "tap" , "node" , function ( evt ) {
5650 const id = evt . target . id ( ) ;
57- // @ts -ignore
5851 vscode . postMessage ( {
5952 command : "selected" ,
6053 nodeId : id ,
6154 } ) ;
6255} ) ;
6356
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-
13557// === Tooltip Hover Handler ===
13658cy . nodes ( ) . on ( "mouseover" , ( event ) => {
13759 const node = event . target ;
0 commit comments