Option A: incremental anchored force layout, persisted server-side
The layout now EVOLVES instead of reshuffling on every extraction. A pure
core module (src/core/layout.ts) warm-starts forceAtlas2 from the positions
ledger (data/graph/positions.json, read-modify-write like sources.json,
updatedAt stamp for future live-physics conflict handling), re-blends every
previously-positioned node toward its anchor each iteration (retention 0.85
- old placements stay recognizable, strong forces still win), seeds new
nodes near their positioned neighbors, and seeds orphans on the rim outside
the core so they read as unconnected knowledge.
- Port/store: GraphStore.readPositions/writePositions; snapshot carries
positions when the ledger exists (optional - fresh graphs unchanged).
- Extraction pipeline settles synchronously after every merge (chat and
notes paths), before usage persist - the next /api/graph fetch already
reflects new nodes.
- View: the ledger IS the layout; the local one-shot FA2 pass survives
only as a fallback when no ledger exists.
- scripts/replay-layout.ts: simulates organic growth by replaying the
current 338-node graph one imported file at a time (real import order,
edges activate when both endpoints exist). Real run: 338 positions in
0.3s, 90-degree-0 orphans collecting at mean r=338 vs connected r=194.
- Also restores the cluster region fills (hull background colors) that
6692b19 had removed on a misreading of "no glow".
Live-verified: fit zoom derives from the ledger bbox, pickAt aligns with
ledger positions at every probe, hover/click/detail-card work, 408/408
tests, typecheck/lint/build green.
Future live physics stays cheap by design: the same pure function is the
merge-time settler and the future client simulator; a pinned node is just
an anchor with full retention.
This commit is contained in:
@@ -327,12 +327,30 @@ export function GraphView() {
|
||||
};
|
||||
}, []);
|
||||
|
||||
// Build the graphology graph and lay it out ONCE per snapshot: seeded
|
||||
// start positions, one synchronous forceAtlas2 pass, then freeze. The
|
||||
// renderer only ever receives the frozen positions as data — layout is
|
||||
// never recomputed for a settings tweak or a refetch of identical data.
|
||||
// Layout (Option A): the positions ledger (written by the server's
|
||||
// incremental settle after every merge) IS the layout — the renderer
|
||||
// receives it as frozen data. The local one-shot forceAtlas2 pass runs
|
||||
// ONLY as a fallback when the ledger is absent (a graph never merged
|
||||
// through the pipeline, e.g. tests or a fresh install).
|
||||
useEffect(() => {
|
||||
if (!snapshot || snapshot.nodes.length === 0) return;
|
||||
// The ledger path: every positioned node uses its resting position;
|
||||
// nodes the ledger doesn't know yet (raced mid-settle) fall through
|
||||
// to seeded scatter below.
|
||||
const ledger = snapshot.positions;
|
||||
if (ledger) {
|
||||
const positions = new Map<string, { x: number; y: number }>();
|
||||
for (const node of snapshot.nodes) {
|
||||
const p = ledger[node.id];
|
||||
if (p) positions.set(node.id, { x: p.x, y: p.y });
|
||||
}
|
||||
if (positions.size > 0) {
|
||||
posRef.current = positions;
|
||||
return () => {
|
||||
posRef.current = null;
|
||||
};
|
||||
}
|
||||
}
|
||||
const graph = new Graph();
|
||||
for (const node of snapshot.nodes) {
|
||||
// Seeded start positions (FA2 requires non-zero x/y) keep the
|
||||
|
||||
Reference in New Issue
Block a user