From 119c47b8adb94982c587d1c57aa66742e82b0ae8 Mon Sep 17 00:00:00 2001 From: Doug Martin Date: Thu, 3 Oct 2024 06:11:33 -0400 Subject: [PATCH] fix: Working reset fix [PT-187399412] - On reset the graph is now initially hidden and set to empty, then after a timeout set to the initial graph and redrawn and then shown - The old graph node x,y is now not updated - The selected node (if any) is unset --- src/components/app.tsx | 10 +++++++--- src/components/graph.tsx | 9 ++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/components/app.tsx b/src/components/app.tsx index 11eb567..596d1ab 100644 --- a/src/components/app.tsx +++ b/src/components/app.tsx @@ -534,16 +534,20 @@ export const App = () => { setSequenceGroups([]); setFastSimulation(defaultFastSimulation); setGraphOpacity(0); - setGraph(initialGraph ? {...initialGraph} : {nodes: [], edges: []}); + setSelectedNodeId(); + setGraph({nodes: [], edges: []}); setResetViewAt(Date.now()); setTimeout(() => { + if (initialGraph) { + setGraph(initialGraph); + } setFitViewAt(Date.now()); setGraphOpacity(1); - }, 0); + }, 1); }, onClose: () => setConfirmModal(undefined) }); - }, [initialGraph, setGraph]); + }, [initialGraph, setGraph, setSelectedNodeId]); const handleReturnToMainMenu = () => { setConfirmModal({ diff --git a/src/components/graph.tsx b/src/components/graph.tsx index b93298e..290b06d 100644 --- a/src/components/graph.tsx +++ b/src/components/graph.tsx @@ -391,13 +391,16 @@ export const Graph = (props: Props) => { const {minRadius, maxRadius, minStroke, maxStroke} = settings; graph.nodes.forEach((node, index) => { + const oldD3Node = d3Graph.nodes.find(n => n.id === node.id); + const x = oldD3Node?.x ?? node.x ?? 0; + const y = oldD3Node?.y ?? node.y ?? 0; + const d3Node: D3Node = { index, id: node.id, - x: node.x ?? 0, - y: node.y ?? 0, + x, + y, label: node.label, - // radius: 15 + (5 * (node.label.length - 1)) + (5 * node.value), radius: minRadius + ((maxRadius - minRadius) * (node.value / totalNodeValue)), loops: false, loopWeight: 0,