Skip to content

Commit 64f2f0b

Browse files
committed
fix: introduce workaround for viz-network runaway canvas height issue
1 parent 4825dab commit 64f2f0b

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/GraphPlugin.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class GraphPlugin {
1515
private network: any | null;
1616
private currentTheme: string;
1717
private themeObserver: MutationObserver | null;
18+
private resizeObserver: ResizeObserver | null;
1819
private nodesDataSet: any;
1920
private edgesDataSet: any;
2021
private triples: RDFTriple[] | null;
@@ -25,6 +26,7 @@ class GraphPlugin {
2526
this.network = null;
2627
this.currentTheme = getCurrentTheme();
2728
this.themeObserver = null;
29+
this.resizeObserver = null;
2830
this.nodesDataSet = null;
2931
this.edgesDataSet = null;
3032
this.triples = null;
@@ -131,7 +133,11 @@ class GraphPlugin {
131133
this.network.on('stabilizationIterationsDone', () => {
132134
this.network.setOptions({ physics: { enabled: true } });
133135
// Fit the graph to view after layout is complete
134-
this.network.fit({ maxZoomLevel: 1000.0 });
136+
this.network.fit({ maxZoomLevel: 3.0 });
137+
138+
// Setup ResizeObserver to adjust container height based on parent
139+
// Workaround for viz-network bug: must use fixed pixel height
140+
this.setupContainerResize(container);
135141
});
136142

137143
// Setup theme change observer
@@ -205,6 +211,38 @@ class GraphPlugin {
205211
(this.network.body.container as HTMLElement).style.setProperty('--yasgui-graph-canvas-bg', color);
206212
}
207213
}
214+
215+
/**
216+
* Setup ResizeObserver to adjust container height based on parent
217+
* Workaround for viz-network bug: container must have fixed pixel height
218+
* @param container - The graph container element
219+
*/
220+
private setupContainerResize(container: HTMLElement): void {
221+
const parent = container.parentElement;
222+
if (!parent) return;
223+
224+
// Function to update container height to match parent
225+
const updateHeight = () => {
226+
const parentHeight = parent.clientHeight;
227+
if (parentHeight > 0) {
228+
container.style.height = `${parentHeight}px`;
229+
// Trigger network redraw after resize
230+
if (this.network) {
231+
this.network.fit({ maxZoomLevel: 1000.0 });
232+
}
233+
}
234+
};
235+
236+
// Initial height adjustment
237+
updateHeight();
238+
239+
// Watch for parent size changes
240+
this.resizeObserver = new ResizeObserver(() => {
241+
updateHeight();
242+
});
243+
244+
this.resizeObserver.observe(parent);
245+
}
208246

209247
/**
210248
* Get icon for plugin tab
@@ -236,6 +274,10 @@ class GraphPlugin {
236274
this.themeObserver.disconnect();
237275
this.themeObserver = null;
238276
}
277+
if (this.resizeObserver) {
278+
this.resizeObserver.disconnect();
279+
this.resizeObserver = null;
280+
}
239281
if (this.network) {
240282
this.network.destroy();
241283
this.network = null;

styles/graph-plugin.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* Graph plugin container */
22
.yasgui-graph-plugin-container {
33
width: 100%;
4-
height: 100%;
4+
height: 500px; /* Initial fixed height as workaround for viz-network bug */
55
position: relative;
66
overflow: hidden;
77
}

0 commit comments

Comments
 (0)