@@ -45,23 +45,27 @@ function LMPNode({ data }) {
45
45
) ;
46
46
}
47
47
48
-
49
48
const LayoutFlow = ( { initialNodes, initialEdges } ) => {
50
- const [ nodes , _ , onNodesChange ] = useNodesState ( initialNodes ) ;
51
- const [ edges , __ , onEdgesChange ] = useEdgesState ( initialEdges ) ;
49
+ const [ nodes , setNodes , onNodesChange ] = useNodesState ( initialNodes ) ;
50
+ const [ edges , setEdges , onEdgesChange ] = useEdgesState ( initialEdges ) ;
52
51
const [ initialised , { toggle, isRunning } ] = useLayoutedElements ( ) ;
53
52
const [ didInitialSimulation , setDidInitialSimulation ] = useState ( false ) ;
53
+ const { fitView } = useReactFlow ( ) ;
54
54
55
- // Start the simulation automatically when the initialized is good & run it for like 1second
55
+ // Start the simulation automatically when initialized and run it for 1 second
56
56
useEffect ( ( ) => {
57
57
if ( initialised && ! didInitialSimulation ) {
58
58
setDidInitialSimulation ( true ) ;
59
59
toggle ( ) ;
60
+
61
+ fitView ( { duration : 500 , padding : 0.1 } ) ;
60
62
setTimeout ( ( ) => {
61
63
toggle ( ) ;
64
+ // Fit view after the simulation has run
65
+ fitView ( { duration : 500 , padding : 0.1 } ) ;
62
66
} , 1000 ) ;
63
67
}
64
- } , [ initialised , didInitialSimulation ] ) ;
68
+ } , [ initialised , didInitialSimulation , toggle , fitView ] ) ;
65
69
66
70
const nodeTypes = useMemo ( ( ) => ( { lmp : LMPNode } ) , [ ] ) ;
67
71
0 commit comments