Skip to content

Commit

Permalink
fit on first mount
Browse files Browse the repository at this point in the history
  • Loading branch information
MadcowD committed Aug 6, 2024
1 parent e67205c commit 5c2b682
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
8 changes: 0 additions & 8 deletions ell-studio/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions ell-studio/src/components/depgraph/DependencyGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,27 @@ function LMPNode({ data }) {
);
}


const LayoutFlow = ({ initialNodes, initialEdges }) => {
const [nodes, _, onNodesChange] = useNodesState(initialNodes);
const [edges, __, onEdgesChange] = useEdgesState(initialEdges);
const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes);
const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges);
const [initialised, { toggle, isRunning }] = useLayoutedElements();
const [didInitialSimulation, setDidInitialSimulation] = useState(false);
const { fitView } = useReactFlow();

// Start the simulation automatically when the initialized is good & run it for like 1second
// Start the simulation automatically when initialized and run it for 1 second
useEffect(() => {
if (initialised && !didInitialSimulation) {
setDidInitialSimulation(true);
toggle();

fitView({ duration: 500, padding: 0.1 });
setTimeout(() => {
toggle();
// Fit view after the simulation has run
fitView({ duration: 500, padding: 0.1 });
}, 1000);
}
}, [initialised, didInitialSimulation]);
}, [initialised, didInitialSimulation, toggle, fitView]);

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

Expand Down

0 comments on commit 5c2b682

Please sign in to comment.