Skip to content

Commit 24731ed

Browse files
committed
feat: auto fit to screen after drawin the graph
1 parent 165373d commit 24731ed

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/GraphPlugin.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,11 @@ class GraphPlugin {
127127
// Apply background color to canvas
128128
this.applyCanvasBackground(themeColors.background);
129129

130-
// Disable physics after stabilization (performance optimization)
130+
// Disable physics after stabilization and fit to view
131131
this.network.on('stabilizationIterationsDone', () => {
132132
this.network.setOptions({ physics: { enabled: true } });
133+
// Fit the graph to view after layout is complete
134+
this.network.fit({ maxZoomLevel: 1000.0 });
133135
});
134136

135137
// Setup theme change observer
@@ -150,12 +152,10 @@ class GraphPlugin {
150152
fitButton.textContent = 'Zoom to Fit';
151153
fitButton.onclick = () => {
152154
if (this.network) {
153-
this.network.fit({ animation: { duration: 300, easingFunction: 'easeInOutQuad' } });
155+
this.network.fit({ maxZoomLevel: 1000.0, animation: { duration: 300, easingFunction: 'easeInOutQuad' } });
154156
}
155157
};
156158
controls.appendChild(fitButton);
157-
158-
this.network.fit();
159159

160160
} catch (error) {
161161
console.error('Error rendering graph:', error);

0 commit comments

Comments
 (0)