Hylograph.ForceEngine.Links
- Package
- purescript-hylograph-simulation
- Repository
- afcondon/purescript-hylograph-simulation
Link Operations for Force Simulations
Functions for working with links in force-directed graphs:
- Swizzling: converting index-based links to node-reference links
- Filtering: selecting links for node subsets
These operations are essential for:
- Rendering (need node references to read x,y positions)
- GUP patterns (filtering to visible nodes)
- Dynamic graph updates
PERFORMANCE: Hot-path functions use FFI-backed O(1) Set/Map lookups instead of O(n) array scans to handle 1000+ node graphs at 60fps.
#swizzleLinks Source
swizzleLinks :: forall node rawLink swizzled. Array node -> Array { source :: Int, target :: Int | rawLink } -> (node -> node -> Int -> { source :: Int, target :: Int | rawLink } -> swizzled) -> Array swizzledConvert raw links (integer indices) to swizzled links (node references)
Expects link.source and link.target to be valid array indices into the
nodes array. Links with out-of-bounds indices are silently dropped.
Note: If your link indices are semantic (node.index field values) rather than
array positions, use swizzleLinksByIndex instead, which looks up nodes by
their .index field.
The transform function allows you to build the output link record, copying extra fields from the raw link as needed.
Example:
let swizzled = swizzleLinks nodes rawLinks \src tgt i link ->
{ source: src, target: tgt, index: i, value: link.value }
#swizzleLinksByIndex Source
swizzleLinksByIndex :: forall node rawLink swizzled. (node -> Int) -> Array node -> Array { source :: Int, target :: Int | rawLink } -> (node -> node -> Int -> { source :: Int, target :: Int | rawLink } -> swizzled) -> Array swizzledSwizzle links by looking up nodes by their index field
USE THIS when working with a FILTERED node subset where array positions
don't match node.index values. Looks up nodes by their .index field
and silently drops links where either endpoint is not found.
PERFORMANCE: Uses FFI-backed IntMap for O(1) lookups instead of O(n) find.
This is essential for GUP patterns where you show only a subset of nodes.
Example:
let visibleNodes = filter isVisible allNodes
swizzled = swizzleLinksByIndex _.index visibleNodes links \src tgt i link ->
{ source: src, target: tgt, index: i, value: link.value }
#filterLinksToSubset Source
filterLinksToSubset :: forall node linkData. (node -> Int) -> Array node -> Array { source :: Int, target :: Int | linkData } -> Array { source :: Int, target :: Int | linkData }Filter links to only those where both endpoints are in the node subset
PERFORMANCE: Uses FFI-backed IntSet for O(1) membership instead of O(n) elem.
Use this before swizzling when you want to show links only between
visible/selected nodes. Pairs naturally with swizzleLinksByIndex.
Example:
let visibleNodes = filter isVisible allNodes
visibleLinks = filterLinksToSubset _.index visibleNodes allLinks
swizzled = swizzleLinksByIndex _.index visibleNodes visibleLinks transform
#buildIntSet Source
buildIntSet :: Array Int -> IntSetBuild an IntSet from an array of integers - O(n)
#buildIntMap Source
buildIntMap :: forall node. (node -> Int) -> Array node -> IntMap nodeBuild an IntMap from nodes using an index accessor
- Modules
- Hylograph.
Config. Apply - Hylograph.
Config. Force - Hylograph.
Config. Scene - Hylograph.
ForceEngine - Hylograph.
ForceEngine. Core - Hylograph.
ForceEngine. Demo - Hylograph.
ForceEngine. Events - Hylograph.
ForceEngine. Links - Hylograph.
ForceEngine. Registry - Hylograph.
ForceEngine. Render - Hylograph.
ForceEngine. Setup - Hylograph.
ForceEngine. Setup. WASM - Hylograph.
ForceEngine. Simulation - Hylograph.
ForceEngine. Types - Hylograph.
ForceEngine. WASM - Hylograph.
ForceEngine. WASMEngine - Hylograph.
Scene. Engine - Hylograph.
Scene. Handle - Hylograph.
Scene. Rules - Hylograph.
Scene. Types - Hylograph.
Simulation - Hylograph.
Simulation. Emitter - Hylograph.
Simulation. HATS - Hylograph.
Simulation. Scene - Hylograph.
Transition. Consumers - Hylograph.
Transition. Example