Skip to content

Commit 5c2b682

Browse files
committed
fit on first mount
1 parent e67205c commit 5c2b682

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

ell-studio/package-lock.json

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ell-studio/src/components/depgraph/DependencyGraph.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,27 @@ function LMPNode({ data }) {
4545
);
4646
}
4747

48-
4948
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);
5251
const [initialised, { toggle, isRunning }] = useLayoutedElements();
5352
const [didInitialSimulation, setDidInitialSimulation] = useState(false);
53+
const { fitView } = useReactFlow();
5454

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
5656
useEffect(() => {
5757
if (initialised && !didInitialSimulation) {
5858
setDidInitialSimulation(true);
5959
toggle();
60+
61+
fitView({ duration: 500, padding: 0.1 });
6062
setTimeout(() => {
6163
toggle();
64+
// Fit view after the simulation has run
65+
fitView({ duration: 500, padding: 0.1 });
6266
}, 1000);
6367
}
64-
}, [initialised, didInitialSimulation]);
68+
}, [initialised, didInitialSimulation, toggle, fitView]);
6569

6670
const nodeTypes = useMemo(() => ({ lmp: LMPNode }), []);
6771

0 commit comments

Comments
 (0)