Module

Hylograph.TreeDSL

Package
purescript-hylograph-selection
Repository
afcondon/purescript-hylograph-selection

PSD3.TreeDSL - Finally Tagless Tree Building

This module provides the extensible, typeclass-based API for building visualization trees. Unlike the concrete Tree ADT, this approach allows extensions without modifying the core library.

Design

TreeDSL is a typeclass parameterized by a type constructor tree:

class TreeDSL tree where
  named :: ElementType -> String -> Array (Attribute d) -> tree d
  ...

Different implementations can provide different behaviors:

  • Tree (from PSD3.AST) - builds a concrete AST for later interpretation
  • Direct DOM interpreter - renders immediately
  • Mermaid interpreter - generates diagram code

Extension

New features are added via subclasses:

class TreeDSL tree <= ShapeTreeDSL tree where
  fromSpec :: (d -> ShapeSpec d) -> tree d

Extensions don't require modifying the core TreeDSL class.

#TreeDSL Source

class TreeDSL :: (Type -> Type) -> Constraintclass TreeDSL (tree :: Type -> Type)  where

The core tree-building DSL.

tree is a type constructor: tree :: Type -> Type where the parameter is the datum type.

Implementations include:

  • Tree from PSD3.AST (builds a data structure)
  • Direct interpreters (could render immediately)
  • Analysis interpreters (could extract metadata)

Members

  • named :: forall datum. ElementType -> String -> Array (Attribute datum) -> tree datum

    Create a named element.

    Named elements can be retrieved after rendering. This is the workhorse for building visualization structure.

    Example:

    named SVG "svg" [width 800.0, height 600.0]
    
  • elem :: forall datum. ElementType -> Array (Attribute datum) -> tree datum

    Create an anonymous element.

    Anonymous elements won't appear in the returned selections. Use for structural elements that don't need later access.

    Example:

    elem Group [class_ "container"]
    
  • withChild :: forall datum. tree datum -> tree datum -> tree datum

    Add a single child to a tree.

    Example:

    parent `withChild` child
    
  • withChildren :: forall datum. tree datum -> Array (tree datum) -> tree datum

    Add multiple children to a tree.

    Example:

    parent `withChildren` [child1, child2, child3]
    
  • withBehaviors :: forall datum. tree datum -> Array (Behavior datum) -> tree datum

    Attach behaviors (zoom, drag, click handlers) to a tree.

    Example:

    svg `withBehaviors` [Zoom config, Drag SimpleDrag]
    
  • joinData :: forall datum. String -> String -> Array datum -> (datum -> tree datum) -> tree datum

    Create a data join.

    The template function builds a subtree for each datum. The join becomes a named selection representing the collection.

    Example:

    joinData "circles" "circle" dataPoints $ \d ->
      elem Circle [cx d.x, cy d.y, radius 5.0]
    
  • nestedJoin :: forall outerDatum innerDatum. String -> String -> Array outerDatum -> (outerDatum -> Array innerDatum) -> (innerDatum -> tree innerDatum) -> tree outerDatum

    Create a nested data join with type decomposition.

    Allows the datum type to change during decomposition. Essential for nested structures like tables.

    Example:

    nestedJoin "rows" "tr" tableData (_.cells) $ \cell ->
      elem Td [textContent cell.value]
    
  • updateJoin :: forall datum. String -> String -> Array datum -> (datum -> tree datum) -> { enter :: Maybe (PhaseBehavior datum), exit :: Maybe (PhaseBehavior datum), keyFn :: Maybe (datum -> String), update :: Maybe (PhaseBehavior datum) } -> tree datum

    Create an update join with GUP (enter/update/exit) behaviors.

    Declaratively specifies animations and transitions for each phase.

    Example:

    updateJoin "nodes" "g" nodes template
      { enter: Just { attrs: [opacity 0.0], transition: Just fadeIn }
      , update: Just { attrs: [], transition: Just move }
      , exit: Just { attrs: [opacity 0.0], transition: Just fadeOut }
      , keyFn: Just _.id
      }
    
  • updateNestedJoin :: forall outerDatum innerDatum. String -> String -> Array outerDatum -> (outerDatum -> Array innerDatum) -> (innerDatum -> tree innerDatum) -> GUPBehaviors innerDatum -> tree outerDatum

    Create an update nested join with type decomposition and GUP.

    Combines nestedJoin and updateJoin - the recommended pattern for most dynamic visualizations.

  • conditionalRender :: forall datum. Array { predicate :: datum -> Boolean, spec :: datum -> tree datum } -> tree datum

    Conditional rendering based on predicates.

    Enables chimeric visualizations - different visual representations for different data shapes.

    Example:

    conditionalRender
      [ { predicate: isCluster, spec: clusterViz }
      , { predicate: isLeaf, spec: leafViz }
      ]
    
  • localCoordSpace :: forall datum. { scaleX :: datum -> Number, scaleY :: datum -> Number } -> tree datum -> tree datum

    Create a local coordinate space for embedded visualizations.

    The child tree renders in its own coordinate system.

#conditionalRenderOr Source

conditionalRenderOr :: forall tree datum. TreeDSL tree => Array { predicate :: datum -> Boolean, spec :: datum -> tree datum } -> (datum -> tree datum) -> tree datum

Conditional render with a fallback for unmatched cases.

#localCoordSpaceFixed Source

localCoordSpaceFixed :: forall tree datum. TreeDSL tree => Number -> Number -> tree datum -> tree datum

Local coordinate space with fixed dimensions.

#PhaseBehavior Source

type PhaseBehavior datum = { attrs :: Array (Attribute datum), transition :: Maybe TransitionConfig }

GUP phase behavior specification (re-exported from AST for convenience)

#GUPBehaviors Source

type GUPBehaviors datum = { enter :: Maybe (PhaseBehavior datum), exit :: Maybe (PhaseBehavior datum), update :: Maybe (PhaseBehavior datum) }

Complete GUP behavior specification

#(>:) Source

Operator alias for Hylograph.TreeDSL.withChild (left-associative / precedence 6)

#(+:) Source

Operator alias for Hylograph.TreeDSL.beside (left-associative / precedence 5)

#beside Source

beside :: forall tree datum. tree datum -> tree datum -> Array (tree datum)

Combine two trees as siblings (for use with withChildren).

#siblings Source

siblings :: forall tree datum. Array (tree datum) -> Array (tree datum)

Identity function for grouping siblings.

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