-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
150 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ import ReactFlow, { | |
useOnSelectionChange, | ||
Panel, | ||
useUpdateNodeInternals, | ||
Controls, | ||
} from "reactflow"; | ||
import "reactflow/dist/style.css"; | ||
import { Transition } from "@headlessui/react"; | ||
|
@@ -160,11 +161,33 @@ const GraphProvided: FC<GraphProvidedProps> = ({ | |
|
||
// Regularly update the node internals to make sure edges are consistent | ||
const updateNodeInternals = useUpdateNodeInternals(); | ||
const prevNodeWidths = useRef<Map<string, number | null | undefined>>( | ||
new Map(), | ||
); | ||
useEffect(() => { | ||
nodes.forEach((node) => { | ||
updateNodeInternals(node.id); | ||
if (prevNodeWidths.current.get(node.id) !== node.width) { | ||
prevNodeWidths.current.set(node.id, node.width); | ||
updateNodeInternals(node.id); | ||
} | ||
}); | ||
}, [nodes.length]); | ||
}, [nodes]); | ||
|
||
// For the first 3 seconds after mounting, we want to updateNodeInternals for all nodes every 100ms | ||
const [firstUpdate, setFirstUpdate] = useState<boolean>(true); | ||
useEffect(() => { | ||
if (firstUpdate) { | ||
const interval = setInterval(() => { | ||
nodes.forEach((node) => { | ||
updateNodeInternals(node.id); | ||
}); | ||
}, 100); | ||
setTimeout(() => { | ||
clearInterval(interval); | ||
setFirstUpdate(false); | ||
}, 10000); | ||
} | ||
}, [firstUpdate]); | ||
|
||
// Record Optimization ------------------------------------------------------- | ||
|
||
|
@@ -479,13 +502,19 @@ const GraphProvided: FC<GraphProvidedProps> = ({ | |
selectionMode={SelectionMode.Partial} | ||
zoomOnDoubleClick={true} | ||
className="h-full w-full" | ||
maxZoom={1.5} | ||
minZoom={0.25} | ||
> | ||
<img | ||
className="-z-10 m-auto w-full scale-150 animate-pulse opacity-40" | ||
aria-hidden="true" | ||
src="https://tailwindui.com/img/[email protected]" | ||
/> | ||
|
||
<Controls | ||
position="top-right" | ||
showFitView={false} | ||
showInteractive={false} | ||
/> | ||
<Background /> | ||
<Panel position="top-left"> | ||
<Legend /> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters