diff --git a/apps/client/src/widgets/note_map.ts b/apps/client/src/widgets/note_map.ts index 98c7764bc..8eb187837 100644 --- a/apps/client/src/widgets/note_map.ts +++ b/apps/client/src/widgets/note_map.ts @@ -62,10 +62,6 @@ export default class NoteMapWidget extends NoteContextAwareWidget { this.graph = new ForceGraph(this.$container[0]) // Rendering code was here - const nodeLinkRatio = data.nodes.length / data.links.length; - const magnifiedRatio = Math.pow(nodeLinkRatio, 1.5); - const charge = -20 / magnifiedRatio; - const boundedCharge = Math.min(-3, charge); let distancevalue = 40; // default value for the link force of the nodes this.$widget.find(".fixnodes-type-switcher input").on("change", async (e) => { @@ -75,10 +71,6 @@ export default class NoteMapWidget extends NoteContextAwareWidget { this.renderData(data); }); - this.graph.d3Force("center")?.strength(0.2); - this.graph.d3Force("charge")?.strength(boundedCharge); - this.graph.d3Force("charge")?.distanceMax(1000); - this.renderData(data); } diff --git a/apps/client/src/widgets/note_map/rendering.ts b/apps/client/src/widgets/note_map/rendering.ts index 18d893434..74c883a43 100644 --- a/apps/client/src/widgets/note_map/rendering.ts +++ b/apps/client/src/widgets/note_map/rendering.ts @@ -176,6 +176,15 @@ export function setupRendering(graph: ForceGraph, { note, noteId, themeStyle, wi .linkCanvasObjectMode(() => "after"); } + // Forces + const nodeLinkRatio = notesAndRelations.nodes.length / notesAndRelations.links.length; + const magnifiedRatio = Math.pow(nodeLinkRatio, 1.5); + const charge = -20 / magnifiedRatio; + const boundedCharge = Math.min(-3, charge); + graph.d3Force("center")?.strength(0.2); + graph.d3Force("charge")?.strength(boundedCharge); + graph.d3Force("charge")?.distanceMax(1000); + // Zoom to notes if (widgetMode === "ribbon" && note?.type !== "search") { setTimeout(() => {