diff --git a/packages/demo-app-ts/src/demos/topologyPackageDemo/TopologyPackage.tsx b/packages/demo-app-ts/src/demos/topologyPackageDemo/TopologyPackage.tsx index 3ae58cf5..d72a43ec 100644 --- a/packages/demo-app-ts/src/demos/topologyPackageDemo/TopologyPackage.tsx +++ b/packages/demo-app-ts/src/demos/topologyPackageDemo/TopologyPackage.tsx @@ -59,6 +59,26 @@ const TopologyViewComponent: React.FunctionComponent setSelectedIds(ids); }); + React.useEffect(() => { + let resizeTimeout: NodeJS.Timeout; + + if (selectedIds[0]) { + const selectedNode = controller.getNodeById(selectedIds[0]); + if (selectedNode) { + // Use a timeout in order to allow the side panel to be shown and window size recomputed + resizeTimeout = setTimeout(() => { + controller.getGraph().panIntoView(selectedNode, { offset: 20, minimumVisible: 100 }); + resizeTimeout = null; + }, 500); + } + } + return () => { + if (resizeTimeout) { + clearTimeout(resizeTimeout); + } + }; + }, [selectedIds, controller]); + React.useEffect(() => { controller.addEventListener(GRAPH_POSITION_CHANGE_EVENT, graphPositionChangeListener); controller.addEventListener(GRAPH_LAYOUT_END_EVENT, layoutEndListener);