diff --git a/ivette/src/frama-c/plugins/dive/index.tsx b/ivette/src/frama-c/plugins/dive/index.tsx index ca43a336e5fc655a2d2bab6736ae3fac2733c60f..ce655035adcb472795cbae837ab3e8c86af99ca5 100644 --- a/ivette/src/frama-c/plugins/dive/index.tsx +++ b/ivette/src/frama-c/plugins/dive/index.tsx @@ -136,14 +136,18 @@ class Dive { this.cy.on('click', 'node', (event) => this.clickNode(event.target)); this.cy.on('double-click', '$node > node', // compound nodes (event) => this.doubleClickNode(event.target)); + + // Set zoom limits const panzoomDefaults = { minZoom: this.cy.minZoom(), maxZoom: this.cy.maxZoom(), }; (this.cy as CytoscapeExtended).panzoom(panzoomDefaults); + // Default layout this.layout = 'dagre'; + // Contextual menu if (!this.headless) { this.cy.scratch('cxtmenu')?.destroy?.(); // Remove previous menu this.cy.scratch('cxtmenu', (this.cy as CytoscapeExtended).cxtmenu({ @@ -152,6 +156,30 @@ class Dive { })); } + // Node width hack + const padding = 10; + const min = 50; + /* eslint-disable @typescript-eslint/no-explicit-any */ + if (this.cy.style() && !this.headless) { + const canvas = document.querySelector('canvas[data-id="layer2-node"]'); + if (canvas instanceof HTMLCanvasElement) { + const context = canvas.getContext('2d'); + if (context) { + (this.cy.style() as any).selector('node').style('width', + (node: any) => { + const fStyle = node.pstyle('font-style').strValue; + const weight = node.pstyle('font-weight').strValue; + const size = node.pstyle('font-size').pfValue; + const family = node.pstyle('font-family').strValue; + context.font = `${fStyle} ${weight} ${size}px ${family}`; + const width = context.measureText(node.data('label')).width; + return `${Math.max(min, width + padding)}px`; + }); + } + } + } + /* eslint-enable @typescript-eslint/no-explicit-any */ + this.refresh(); } @@ -219,6 +247,7 @@ class Dive { if (!container) return []; + // eslint-disable-next-line @typescript-eslint/no-explicit-any const ref = (node as any).popperRef(); const common = { getReferenceClientRect: ref.getBoundingClientRect, diff --git a/ivette/src/frama-c/plugins/dive/style.json b/ivette/src/frama-c/plugins/dive/style.json index 1b1b8a69f7bd093f61c8a08d811ed30cb703b141..84d6611dee4a6c681a1a60f10845117e700dbbcd 100644 --- a/ivette/src/frama-c/plugins/dive/style.json +++ b/ivette/src/frama-c/plugins/dive/style.json @@ -9,7 +9,6 @@ "text-outline-width": 2, "text-outline-color": "#666", "text-valign" : "center", - "width": "label", "padding" : "6px", "border-width": 1, "text-wrap" : "wrap"