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:
Treefrom 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 datumelem :: forall datum. ElementType -> Array (Attribute datum) -> tree datumCreate 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 datumAdd a single child to a tree.
Example:
parent `withChild` childwithChildren :: forall datum. tree datum -> Array (tree datum) -> tree datumAdd multiple children to a tree.
Example:
parent `withChildren` [child1, child2, child3]withBehaviors :: forall datum. tree datum -> Array (Behavior datum) -> tree datumAttach 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 datumCreate 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 outerDatumCreate 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 datumCreate 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 outerDatumCreate an update nested join with type decomposition and GUP.
Combines
nestedJoinandupdateJoin- the recommended pattern for most dynamic visualizations.conditionalRender :: forall datum. Array { predicate :: datum -> Boolean, spec :: datum -> tree datum } -> tree datumConditional 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 datumCreate 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 datumConditional render with a fallback for unmatched cases.
#localCoordSpaceFixed Source
localCoordSpaceFixed :: forall tree datum. TreeDSL tree => Number -> Number -> tree datum -> tree datumLocal 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
- 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
Create a named element.
Named elements can be retrieved after rendering. This is the workhorse for building visualization structure.
Example: