Skip to content

@graphty/layout / index / ForceAtlas2Simulation

Class: ForceAtlas2Simulation ​

Defined in: simulation/forceatlas2.ts:464

The steppable CPU ForceAtlas2 (design 9.3): load() a snapshot and the owner's scene-unit array, step() it in place until settled, pin with setFixed(), drag with setPosition(). Synchronous; f64 scratch, f32 output.

Implements ​

Constructors ​

Constructor ​

new ForceAtlas2Simulation(options?): ForceAtlas2Simulation

Defined in: simulation/forceatlas2.ts:500

Resolves the options (FA2_DEFAULTS applied, ranges validated: design 7.14) without touching a graph.

Parameters ​

options? ​

ForceAtlas2SimulationOptions

the FA2 options of design 9.3 plus compat ("paper" by default, D5)

Returns ​

ForceAtlas2Simulation

Accessors ​

iterationsDone ​

Get Signature ​

get iterationsDone(): number

Defined in: simulation/forceatlas2.ts:527

Iterations run since load() or the last reheat() (the budget of design 7.17).

Returns ​

number

the count


settled ​

Get Signature ​

get settled(): boolean

Defined in: simulation/forceatlas2.ts:512

iterationsDone >= maxIter || settledCount >= settleWindow once loaded (design 7.17); an empty graph is settled at once; false before load() and after dispose().

Returns ​

boolean

whether step() would do nothing

Implementation of ​

LayoutSimulation.settled

Methods ​

dispose() ​

dispose(): void

Defined in: simulation/forceatlas2.ts:705

Releases the scratch arrays and ends stepping; idempotent.

Returns ​

void

Implementation of ​

LayoutSimulation.dispose


load() ​

load(snapshot, positions): void

Defined in: simulation/forceatlas2.ts:542

Takes the snapshot and the owner's array (design 7.19 load): validates, resolves the mass (a role-mass column, else outDegree + 1: design 7.14, D28) and the weights, seeds the non-finite rows of the owner's array in place (seedPositions with the seed option, the GPU simulation's rule), converts the scene-unit rows into the f64 layout-unit array (v - center) / scale (z forced to 0 in 2D), resets the speed controller (speed = speedEfficiency = swing = traction = 1: the one place that does, D8), clears the fixed mask when n changed (design 7.12), and reheats.

Parameters ​

snapshot ​

GraphSnapshot

an undirected snapshot (both arcs of every edge present)

positions ​

F32

the owner's stride-3 scene-unit array, length 3 x nodeCount, read AND written in place (non-finite rows are seeded)

Returns ​

void

Implementation of ​

LayoutSimulation.load


reheat() ​

reheat(): void

Defined in: simulation/forceatlas2.ts:694

reheat() of D8: iterationsDone = 0, settledCount = 0 (and, in networkx mode, swing = traction = 1 as the oracle has it).

Returns ​

void


setFixed() ​

setFixed(mask): void

Defined in: simulation/forceatlas2.ts:630

Copies the mask words (design 7.12): the mask must hold ceil(n / 32) words; reheat() iff some bit below n went 1 -> 0 (an unpin); adding pins never reheats.

Parameters ​

mask ​

U32

the NodeMask (LSB-first words, the bool-column bit layout)

Returns ​

void

Implementation of ​

LayoutSimulation.setFixed


setPosition() ​

setPosition(index, x, y, z): void

Defined in: simulation/forceatlas2.ts:672

A drag (design 7.12): writes the three scene-unit floats into the owner's array at once, converts them into the layout-unit position (z forced to 0 in 2D), then reheat() -- the settle window and the iteration budget only; the speed controller keeps its state (D8).

Parameters ​

index ​

number

the node index (< n)

x ​

number

scene x

y ​

number

scene y

z ​

number

scene z (not integrated in 2D)

Returns ​

void

Implementation of ​

LayoutSimulation.setPosition


step() ​

step(iterations?): void

Defined in: simulation/forceatlas2.ts:601

Runs up to iterations iterations (design 7.19 step): returns at once when settled, stops early when the budget or the settle window is reached mid-batch, then writes every FREE node's scene position back into the owner's array (layout * scale + center, z = center.z in 2D).

Parameters ​

iterations? ​

number = ...

k (default options.iterationsPerStep, default 1)

Returns ​

void

Implementation of ​

LayoutSimulation.step