DataViz.Layout.StateMachine
- Package
- purescript-hylograph-layout
- Repository
- afcondon/purescript-hylograph-layout
DataViz.Layout.StateMachine
State machine layout for visualization. Provides types and layout algorithms for rendering state machine diagrams with states as circles/ovals and transitions as curved arrows.
Example usage:
import DataViz.Layout.StateMachine (layout, StateMachine)
myMachine :: StateMachine Unit Unit
myMachine =
{ states:
[ { id: "s0", label: "Start", isInitial: true, isFinal: false, extra: unit }
, { id: "s1", label: "Running", isInitial: false, isFinal: false, extra: unit }
, { id: "s2", label: "Done", isInitial: false, isFinal: true, extra: unit }
]
, transitions:
[ { from: "s0", to: "s1", label: "begin", extra: unit }
, { from: "s1", to: "s1", label: "tick", extra: unit }
, { from: "s1", to: "s2", label: "finish", extra: unit }
]
}
rendered = layout myMachine
-- rendered.states contains positioned states
-- rendered.transitions contains arrow paths
Re-exports from DataViz.Layout.StateMachine.Layout
#LayoutConfig Source
type LayoutConfig = { arrowOffset :: Number, edgeCurvature :: Number, initialArrowLength :: Number, labelOffset :: Number, layoutRadius :: Number, margin :: Number, minPairedCurvature :: Number, parallelSeparation :: Number, selfLoopRadius :: Number, stateRadiusX :: Number, stateRadiusY :: Number }Configuration for state machine layout
#layoutWithConfig Source
layoutWithConfig :: forall se te. LayoutConfig -> (LayoutConfig -> Array (State se) -> Array (LayoutState se)) -> StateMachine se te -> StateMachineLayout se teLayout with custom configuration and layout strategy
#layout Source
layout :: forall se te. StateMachine se te -> StateMachineLayout se teLayout a state machine with default configuration using circular layout
#gridLayout Source
gridLayout :: forall extra. LayoutConfig -> Array (State extra) -> Array (LayoutState extra)Grid layout: arrange states in rows
#defaultConfig Source
defaultConfig :: LayoutConfigDefault layout configuration
#circularLayout Source
circularLayout :: forall extra. LayoutConfig -> Array (State extra) -> Array (LayoutState extra)Circular layout: arrange states in a circle
Re-exports from DataViz.Layout.StateMachine.Path
#transitionPathD Source
transitionPathD :: TransitionPath -> StringGenerate SVG path d attribute for a transition arrow Uses quadratic bezier curve
#stateFinalRing Source
stateFinalRing :: StatePosition -> Number -> { cx :: Number, cy :: Number, rx :: Number, ry :: Number }Get the inner ring for a final state (double circle effect) Returns slightly smaller ellipse attributes
#stateEllipse Source
stateEllipse :: StatePosition -> { cx :: Number, cy :: Number, rx :: Number, ry :: Number }Get ellipse attributes for a state Returns { cx, cy, rx, ry } ready for SVG ellipse element
#selfLoopPathD Source
selfLoopPathD :: TransitionPath -> StringGenerate SVG path for a self-loop Uses an SVG arc for a clean circular loop The arc radius is computed from the distance between start and control points
Re-exports from DataViz.Layout.StateMachine.Tree
#treeStrategy Source
treeStrategy :: forall extra. Induced String -> LayoutConfig -> Array (State extra) -> Array (LayoutState extra)A positioning pass for layoutWithConfig, driven by an induced tree.
The tree is keyed by state id, because that is what State carries and what
the caller will have built the graph from.
Re-exports from DataViz.Layout.StateMachine.Types
#Transition Source
type Transition extra = { extra :: extra, from :: String, label :: String, to :: String }A transition between states
The extra field carries whatever the caller needs to keep attached to the
edge itself — the triggering event, a guard, a refusal reason — so that a
renderer can style or annotate an arrow without a side table keyed by
from/to/label.
#StatePosition Source
type StatePosition = { cx :: Number, cy :: Number, rx :: Number, ry :: Number }Computed position for a state
#StateMachineLayout Source
type StateMachineLayout stateExtra transitionExtra = { height :: Number, initialArrow :: { angle :: Number, x :: Number, y :: Number }, originX :: Number, originY :: Number, states :: Array (LayoutState stateExtra), transitions :: Array (LayoutTransition transitionExtra), width :: Number }Complete layout output ready for rendering
originX/originY are the top-left of the drawing, which is NOT always
(0, 0): a self-loop or a transition label can sit left of or above the
leftmost state, and a viewBox pinned to the origin clips them. Renderers
should use all four as the viewBox.
#StateMachine Source
type StateMachine stateExtra transitionExtra = { states :: Array (State stateExtra), transitions :: Array (Transition transitionExtra) }Complete state machine definition
#LayoutTransition Source
type LayoutTransition extra = { path :: TransitionPath, transition :: Transition extra }A transition with computed layout
#LayoutState Source
type LayoutState extra = { position :: StatePosition, state :: State extra }A state with computed layout
- Modules
- DataViz.
Layout. Adjacency - DataViz.
Layout. Adjacency. Layout - DataViz.
Layout. Adjacency. Types - DataViz.
Layout. BlockCutTree - DataViz.
Layout. Chord - DataViz.
Layout. Chord. Layout - DataViz.
Layout. Chord. Types - DataViz.
Layout. Hierarchy. Cluster - DataViz.
Layout. Hierarchy. Core - DataViz.
Layout. Hierarchy. EdgeBundle - DataViz.
Layout. Hierarchy. EdgeBundle. Bilink - DataViz.
Layout. Hierarchy. EdgeBundle. BundleCurve - DataViz.
Layout. Hierarchy. EdgeBundle. Hierarchy - DataViz.
Layout. Hierarchy. EdgeBundle. RadialCluster - DataViz.
Layout. Hierarchy. EdgeBundle. Types - DataViz.
Layout. Hierarchy. Link - DataViz.
Layout. Hierarchy. Pack - DataViz.
Layout. Hierarchy. Partition - DataViz.
Layout. Hierarchy. Tree - DataViz.
Layout. Hierarchy. TreeStyle - DataViz.
Layout. Hierarchy. Treemap - DataViz.
Layout. Hierarchy. Types - DataViz.
Layout. Pattern - DataViz.
Layout. Pattern. Adapters - DataViz.
Layout. Pattern. Types - DataViz.
Layout. Sankey. CSV - DataViz.
Layout. Sankey. Compute - DataViz.
Layout. Sankey. ComputeWithSteps - DataViz.
Layout. Sankey. Lanes - DataViz.
Layout. Sankey. Path - DataViz.
Layout. Sankey. Types - DataViz.
Layout. StateMachine - DataViz.
Layout. StateMachine. Layout - DataViz.
Layout. StateMachine. Path - DataViz.
Layout. StateMachine. Tree - DataViz.
Layout. StateMachine. Types - DataViz.
Layout. TidyDag