Allow full large graph load with dense simulation mode

This commit is contained in:
Ishaan Gupta 2026-05-29 21:06:41 +05:30
parent 22367a1725
commit 93c2b7baa2
3 changed files with 15 additions and 3 deletions

View file

@ -13,7 +13,7 @@ import { dmSansClassName } from "@/lib/fonts"
import { ShareModal } from "./share-modal"
import { shareParam } from "@/lib/search-params"
const GRAPH_MAX_NODES = 3000
const GRAPH_MAX_NODES = 15000
export const GraphLayoutView = memo(function GraphLayoutView({
onOpenDocument,

View file

@ -2,6 +2,8 @@ import * as d3 from "d3-force"
import type { DocumentNodeData, GraphEdge, GraphNode } from "../types"
import { FORCE_CONFIG } from "../constants"
const DENSE_GRAPH_STATIC_THRESHOLD = 6000
export class ForceSimulation {
private sim: d3.Simulation<GraphNode, GraphEdge> | null = null
@ -61,8 +63,17 @@ export class ForceSimulation {
this.sim.stop()
this.sim.alpha(1)
for (let i = 0; i < FORCE_CONFIG.preSettleTicks; i++) this.sim.tick()
this.sim.alphaTarget(0).restart()
const preSettleTicks =
nodes.length > DENSE_GRAPH_STATIC_THRESHOLD
? FORCE_CONFIG.densePreSettleTicks
: FORCE_CONFIG.preSettleTicks
for (let i = 0; i < preSettleTicks; i++) this.sim.tick()
if (nodes.length > DENSE_GRAPH_STATIC_THRESHOLD) {
this.stop()
} else {
this.sim.alphaTarget(0).restart()
}
} catch (e) {
console.error("ForceSimulation.init failed:", e)
this.destroy()

View file

@ -27,6 +27,7 @@ export const FORCE_CONFIG = {
velocityDecay: 0.45,
alphaTarget: 0.3,
preSettleTicks: 150,
densePreSettleTicks: 12,
}
export const GRAPH_SETTINGS = {