Hylograph.Expr.Animation
- Package
- purescript-hylograph-selection
- Repository
- afcondon/purescript-hylograph-selection
Animation DSL
A fluent API for creating animated attributes that compose with the existing Hylograph expression system. Animated attributes define start and end values with timing configuration, and are rendered using pure PureScript transitions (no D3 dependency).
Quick Start
import Hylograph.Expr.Animation
-- Animate from 0 to the datum's x value over 500ms
cx $ animated $ animatedFrom (num 0.0) $ animatedTo (field @"x")
# withDuration 500.0
# withEasing QuadOut
-- Shorthand for common patterns
[ fadeIn
, animated $ animatedTo (field @"radius") # withDuration 300.0
]
Design
The animation DSL uses a builder pattern:
animatedTocreates a builder targeting an attribute valueanimatedFromoptionally sets the starting value- Config modifiers (
withDuration,withEasing,withDelay) adjust timing animatedconverts the builder to anAttribute
The DSL integrates with the expression system (EvalD), so you can use
field @"x", num 5.0, arithmetic expressions, etc.
#AnimatedBuilder Source
type AnimatedBuilder datum = { config :: AnimationConfig, fromValue :: Maybe (AnimatedValue datum), name :: String, toValue :: AnimatedValue datum }Builder for animated attributes
Accumulates the animation specification before converting to Attribute.
Use animatedTo to create, config modifiers to adjust, and animated to finalize.
#AnimatedPathBuilder Source
type AnimatedPathBuilder datum = { config :: AnimationConfig, fromValues :: Array (AnimatedValue datum), generator :: Array Number -> String, toValues :: Array (AnimatedValue datum) }Builder for animated path attributes
Tracks the from/to values for path components and the generator function. Used for animating paths like linkVertical where we interpolate coordinates and regenerate the path string on each frame.
#animatedTo Source
animatedTo :: forall datum. String -> EvalD datum Number -> AnimatedBuilder datumCreate an animated attribute builder targeting a value
The attribute name is required. The target value can be:
- A constant:
animatedTo "opacity" (num 1.0) - A field:
animatedTo "cx" (field @"x") - An expression:
animatedTo "cx" (field @"x"timesN20.0)
opacity $ animated $ animatedTo (num 1.0)
# withDuration 500.0
#animatedToIndexed Source
animatedToIndexed :: forall datum. String -> (datum -> Int -> Number) -> AnimatedBuilder datumCreate an indexed animated attribute builder (uses datum and element index for target)
animated $ animatedToIndexed "cx" (\d i -> d.x + toNumber i * spacing)
#animatedFrom Source
animatedFrom :: forall datum. EvalD datum Number -> AnimatedBuilder datum -> AnimatedBuilder datumSet the starting value for an animation
Without animatedFrom, the animation reads the current DOM value as start.
With animatedFrom, the animation uses the specified value.
-- Animate from 0 to 1
opacity $ animated $ animatedFrom (num 0.0) $ animatedTo (num 1.0)
-- Animate from current DOM value to target (no animatedFrom)
opacity $ animated $ animatedTo (field @"targetOpacity")
#animatedFromStatic Source
animatedFromStatic :: forall datum. Number -> AnimatedBuilder datum -> AnimatedBuilder datumSet a static starting value for an animation
animated $ animatedFromStatic 0.0 $ animatedTo "opacity" (num 1.0)
#animatedFromIndexed Source
animatedFromIndexed :: forall datum. (datum -> Int -> Number) -> AnimatedBuilder datum -> AnimatedBuilder datumSet an indexed starting value for an animation (uses datum and element index)
animated $ animatedFromIndexed (\d i -> d.baseX + toNumber i * 10.0) $ animatedTo "cx" (field @"x")
#animatedLinkVertical Source
animatedLinkVertical :: forall datum. { fromSourceX :: EvalD datum Number, fromSourceY :: EvalD datum Number, fromTargetX :: EvalD datum Number, fromTargetY :: EvalD datum Number } -> { toSourceX :: EvalD datum Number, toSourceY :: EvalD datum Number, toTargetX :: EvalD datum Number, toTargetY :: EvalD datum Number } -> AnimatedPathBuilder datumCreate an animated vertical link path
Animates from current positions to new positions, regenerating the cubic bezier path on each frame. Used for tree visualizations.
animatedLinkVertical
{ fromSourceX: field @"sourceX", fromSourceY: field @"sourceY"
, fromTargetX: field @"targetX", fromTargetY: field @"targetY" }
{ toSourceX: field @"newSourceX", toSourceY: field @"newSourceY"
, toTargetX: field @"newTargetX", toTargetY: field @"newTargetY" }
# pathWithDuration 500.0
#animatedLinkHorizontal Source
animatedLinkHorizontal :: forall datum. { fromSourceX :: EvalD datum Number, fromSourceY :: EvalD datum Number, fromTargetX :: EvalD datum Number, fromTargetY :: EvalD datum Number } -> { toSourceX :: EvalD datum Number, toSourceY :: EvalD datum Number, toTargetX :: EvalD datum Number, toTargetY :: EvalD datum Number } -> AnimatedPathBuilder datumCreate an animated horizontal link path
Same as animatedLinkVertical but for horizontal (left-to-right) trees.
#pathWithDuration Source
pathWithDuration :: forall datum. Number -> AnimatedPathBuilder datum -> AnimatedPathBuilder datumSet the animation duration for a path animation
#pathWithEasing Source
pathWithEasing :: forall datum. EasingType -> AnimatedPathBuilder datum -> AnimatedPathBuilder datumSet the easing function for a path animation
#pathWithDelay Source
pathWithDelay :: forall datum. Number -> AnimatedPathBuilder datum -> AnimatedPathBuilder datumSet the delay for a path animation
#animatedPathAttr Source
animatedPathAttr :: forall datum. AnimatedPathBuilder datum -> Attribute datumConvert an AnimatedPathBuilder to an Attribute
This creates an AnimatedCompound attribute that will interpolate all path coordinates and regenerate the path string on each animation frame.
#withDuration Source
withDuration :: forall datum. Number -> AnimatedBuilder datum -> AnimatedBuilder datumSet the animation duration in milliseconds
animated $ animatedTo (num 1.0) # withDuration 500.0
#withEasing Source
withEasing :: forall datum. EasingType -> AnimatedBuilder datum -> AnimatedBuilder datumSet the easing function
animated $ animatedTo (num 1.0)
# withEasing ElasticOut
#withDelay Source
withDelay :: forall datum. Number -> AnimatedBuilder datum -> AnimatedBuilder datumSet the delay before animation starts (in milliseconds)
animated $ animatedTo (num 1.0)
# withDelay 200.0 -- Wait 200ms before starting
#withStagger Source
withStagger :: forall datum. Number -> AnimatedBuilder datum -> AnimatedBuilder datumSet staggered delay based on element index
Creates an indexed animation where each element's delay is: baseDelay + (index * staggerDelay)
animated $ animatedTo (num 1.0)
# withStagger 50.0 -- Each element starts 50ms after the previous
#animated Source
animated :: forall datum. AnimatedBuilder datum -> Attribute datumConvert an AnimatedBuilder to an Attribute
This is the final step after building the animation specification.
myAttr = animated $ animatedFrom (num 0.0) $ animatedTo (num 1.0)
# withDuration 500.0
# withEasing QuadOut
#animatedAttr Source
animatedAttr :: forall datum. String -> AnimatedBuilder datum -> Attribute datumCreate an animated attribute with explicit name (alternative syntax)
animatedAttr "opacity" $ animatedFrom (num 0.0) $ animatedTo (num 1.0)
Re-exports from Hylograph.Internal.Attribute
#EasingType Source
data EasingTypeEnumeration of easing types for animations
Note: This mirrors Hylograph.Transition.Easing.EasingType but is defined here to avoid circular dependencies. The Manager module will convert between them.
Constructors
LinearQuadInQuadOutQuadInOutCubicInCubicOutCubicInOutSinInSinOutSinInOutExpInExpOutExpInOutCircleInCircleOutCircleInOutBackInBackOutBackInOutElasticInElasticOutElasticInOutBounceInBounceOutBounceInOut
Instances
- Modules
- Data.
DependencyGraph - Hylograph.
AST - Hylograph.
Axis. Axis - Hylograph.
Brush - Hylograph.
Brush. FFI - Hylograph.
Brush. Types - Hylograph.
Classify - Hylograph.
Data. Graph - Hylograph.
Data. Graph. Algorithms - Hylograph.
Data. Node - Hylograph.
Data. Tree - Hylograph.
Expr. Animation - Hylograph.
Expr. Attr - Hylograph.
Expr. Datum - Hylograph.
Expr. Expr - Hylograph.
Expr. Friendly - Hylograph.
Expr. Integration - Hylograph.
Expr. Interpreter. CodeGen - Hylograph.
Expr. Interpreter. Eval - Hylograph.
Expr. Interpreter. Meta - Hylograph.
Expr. Interpreter. PureSVG - Hylograph.
Expr. Interpreter. SVG - Hylograph.
Expr. Path - Hylograph.
Expr. Path. Generators - Hylograph.
Expr. Sugar - Hylograph.
Expr. Units - Hylograph.
HATS - Hylograph.
HATS. Friendly - Hylograph.
HATS. InterpreterTick - Hylograph.
HATS. Transitions - Hylograph.
Interaction. Brush - Hylograph.
Interaction. Coordinated - Hylograph.
Interaction. Pointer - Hylograph.
Interaction. Zoom - Hylograph.
Internal. Attribute - Hylograph.
Internal. Behavior. FFI - Hylograph.
Internal. Behavior. Types - Hylograph.
Internal. Capabilities. Selection - Hylograph.
Internal. Capabilities. Transition - Hylograph.
Internal. FFI - Hylograph.
Internal. Selection. Join - Hylograph.
Internal. Selection. Operations - Hylograph.
Internal. Selection. Operations. Conversions - Hylograph.
Internal. Selection. Operations. Helpers - Hylograph.
Internal. Selection. Operations. Selection - Hylograph.
Internal. Selection. Query - Hylograph.
Internal. Selection. Types - Hylograph.
Internal. Transition. FFI - Hylograph.
Internal. Transition. Manager - Hylograph.
Internal. Transition. Scene - Hylograph.
Internal. Transition. Types - Hylograph.
Internal. Types - Hylograph.
Interpreter. D3 - Hylograph.
Interpreter. English - Hylograph.
Interpreter. Mermaid - Hylograph.
Interpreter. MetaAST - Hylograph.
Interpreter. SemiQuine - Hylograph.
Interpreter. SemiQuine. TreeToCode - Hylograph.
Interpreter. SemiQuine. Types - Hylograph.
Render - Hylograph.
Scale - Hylograph.
Scale. FP - Hylograph.
Shape. Arc - Hylograph.
Shape. Pie - Hylograph.
Shape. Polygon - Hylograph.
Tooltip - Hylograph.
Transform - Hylograph.
TreeDSL - Hylograph.
TreeDSL. ShapeTree - Hylograph.
Unified - Hylograph.
Unified. Attribute - Hylograph.
Unified. DataDSL - Hylograph.
Unified. Display - Hylograph.
Unified. Examples - Hylograph.
Unified. Join - Hylograph.
Unified. Sugar