From 845c76fc428ff1082a677dc341d5eeaed4dafdab Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 4 Oct 2025 13:37:36 +0300 Subject: [PATCH] chore(react): bring back fixing nodes --- apps/client/src/widgets/note_map.ts | 17 +-------------- apps/client/src/widgets/note_map/NoteMap.tsx | 23 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/apps/client/src/widgets/note_map.ts b/apps/client/src/widgets/note_map.ts index 36b4ec98e..e6d6acc70 100644 --- a/apps/client/src/widgets/note_map.ts +++ b/apps/client/src/widgets/note_map.ts @@ -15,8 +15,7 @@ const esc = utils.escapeHtml; const TPL = /*html*/`
-
- +
@@ -70,22 +69,8 @@ export default class NoteMapWidget extends NoteContextAwareWidget { const ForceGraph = (await import("force-graph")).default; this.graph = new ForceGraph(this.$container[0]) - //Code to fixate nodes when dragged - .onNodeDragEnd((node) => { - if (this.fixNodes) { - node.fx = node.x; - node.fy = node.y; - } else { - node.fx = undefined; - node.fy = undefined; - } - }) - // Rendering code was here - - - const nodeLinkRatio = data.nodes.length / data.links.length; const magnifiedRatio = Math.pow(nodeLinkRatio, 1.5); const charge = -20 / magnifiedRatio; diff --git a/apps/client/src/widgets/note_map/NoteMap.tsx b/apps/client/src/widgets/note_map/NoteMap.tsx index 87462499c..6f20afa8f 100644 --- a/apps/client/src/widgets/note_map/NoteMap.tsx +++ b/apps/client/src/widgets/note_map/NoteMap.tsx @@ -26,6 +26,7 @@ export default function NoteMap({ note, widgetMode, parentRef }: NoteMapProps) { const graphRef = useRef>>(); const containerSize = useElementSize(parentRef); + const [ fixNodes, setFixNodes ] = useState(false); // Build the note graph instance. useEffect(() => { @@ -80,6 +81,19 @@ export default function NoteMap({ note, widgetMode, parentRef }: NoteMapProps) { graphRef.current.width(containerSize.width).height(containerSize.height); }, [ containerSize?.width, containerSize?.height ]); + // Fixing nodes when dragged. + useEffect(() => { + graphRef.current?.onNodeDragEnd((node) => { + if (fixNodes) { + node.fx = node.x; + node.fy = node.y; + } else { + node.fx = undefined; + node.fy = undefined; + } + }) + }, [ fixNodes ]); + return (
@@ -87,6 +101,15 @@ export default function NoteMap({ note, widgetMode, parentRef }: NoteMapProps) {
+
+ setFixNodes(!fixNodes)} + /> +
+