Hylograph.Scene.Rules
- Package
- purescript-hylograph-simulation
- Repository
- afcondon/purescript-hylograph-simulation
Scene Rules
Common rule builders and transforms for scene orchestration.
Rules are applied with first-match-wins semantics (CSS-like cascade). Each rule has a selector (predicate) and a transform function.
This module provides:
- Rule builders for creating rules
- Common transforms (pin, unpin, setGridXY)
- Rule application functions
#pinAtCurrent Source
pinAtCurrent :: forall r. { fx :: Nullable Number, fy :: Nullable Number, x :: Number, y :: Number | r } -> { fx :: Nullable Number, fy :: Nullable Number, x :: Number, y :: Number | r }Pin a node at its current position.
Sets fx = x, fy = y so the node won't move during simulation.
Type signature uses row polymorphism - works with any node type that has the required fields.
#applyRules Source
applyRules :: forall node. Array (NodeRule node) -> Array node -> Array nodeApply rules to an array of nodes (first matching rule wins).
For each node, finds the first rule whose selector matches, then applies that rule's transform. If no rule matches, the node is returned unchanged.
This is CSS-like cascade semantics - rule order matters.
#applyFirstMatch Source
applyFirstMatch :: forall node. Array (NodeRule node) -> node -> nodeApply the first matching rule to a single node.
Returns the node unchanged if no rule matches.
Re-exports from Hylograph.Scene.Types
#NodeRule Source
type NodeRule node = { apply :: node -> node, name :: String, select :: node -> Boolean }A rule that selects nodes and applies a transform.
Rules are applied with first-match-wins semantics (like CSS cascade). If multiple rules match a node, only the first one applies.
Example:
pinPackages :: NodeRule MyNode
pinPackages =
{ name: "pinPackages"
, select: \n -> n.nodeType == Package
, apply: \n -> n { fx = notNull n.x, fy = notNull n.y }
}
- 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