Module

Hylograph.Render

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

Hylograph.Render - Core rendering API for visualization ASTs

This module provides the essential functions for rendering AST specifications to the DOM via D3.js.

Usage

import Hylograph.AST as A
import Hylograph.Render (runD3, select, renderTree)

main :: Effect Unit
main = void $ runD3 do
  container <- select "#chart"
  renderTree container myAST

#runD3 Source

runD3 :: D3M ~> Effect

Run a D3 computation (alias for runD3v2M)

#D3M Source

type D3M = D3v2M

Type alias for the D3 monad

#D3Selection Source

type D3Selection = D3v2Selection_

Type alias for D3 selections

#selectChildInheriting Source

selectChildInheriting :: forall parent datum. String -> D3v2Selection_ SBoundOwns parent datum -> D3v2M (D3v2Selection_ SBoundOwns Element datum)

Select child elements, inheriting parent's data Alias for selectChildInheritingD3v2 for convenient import

Re-exports from Hylograph.Internal.Capabilities.Selection

#clear Source

clear :: forall sel m. SelectionM sel m => String -> m Unit

Clear all children from an element

Selects the element and removes all its children. Useful for clearing a container before rendering new content.

Example:

clear "#viz"
svg <- appendChild SVG [...] container

#renderData Source

renderData :: forall sel m f parent datum. SelectionM sel m => Foldable f => Ord datum => ElementType -> f datum -> String -> sel SEmpty parent datum -> Maybe (datum -> Array (Attribute datum)) -> Maybe (datum -> Array (Attribute datum)) -> Maybe (datum -> Array (Attribute datum)) -> m (sel SBoundOwns Element datum)

High-level data rendering (recommended for most use cases)

Manages the entire enter-update-exit cycle automatically. Users provide Maybe callbacks for each phase.

This is the user-friendly API that prevents sequencing errors by handling enter/update/exit internally.

Example:

circles <- renderData Circle [1, 2, 3] "circle" svg
  (Just \d -> [fill "green", cx (\_ -> d * 100.0)])  -- Enter
  (Just \d -> [fill "orange"])                        -- Update
  Nothing                                             -- Exit (just remove)

#renderTree Source

renderTree :: forall sel m parent parentDatum datum. SelectionM sel m => Ord datum => sel SEmpty parent parentDatum -> Tree datum -> m (Map String (sel SBoundOwns Element datum))

Declarative tree rendering (high-level API)

Renders an entire tree structure at once, returning a map of named selections. This is the declarative alternative to imperative appendChild chains.

Example:

import Hylograph.AST as T

tree =
  T.named "svg" SVG [width 800] `T.withChildren`
    [ T.named "zoom" Group [class_ "zoom"] `T.withChild`
        T.named "nodes" Group [class_ "nodes"]
    ]

container <- select "#viz"
selections <- renderTree container tree

-- Access named selections
case Map.lookup "svg" selections of
  Just svg -> ...
  Nothing -> ...

#select Source

select :: forall sel m datum. SelectionM sel m => String -> m (sel SEmpty Element datum)

Select a single element by CSS selector

Returns an empty selection (no data bound). The datum type is polymorphic and will be inferred from usage. This is typically the starting point for data binding.

#selectAll Source

selectAll :: forall sel m state parent parentDatum datum. SelectionM sel m => String -> sel state parent parentDatum -> m (sel SEmpty Element datum)

Select all elements matching selector within a parent selection

Returns an empty selection of the matched elements. The datum type is polymorphic and will be inferred from usage.

#selectAllWithData Source

selectAllWithData :: forall sel m state parent parentDatum datum. SelectionM sel m => String -> sel state parent parentDatum -> m (sel SBoundOwns Element datum)

Select all elements matching selector and extract their bound data

Use this when selecting child elements that have inherited data from their parent. This is necessary when you want to use the selection with transitions that need access to the bound data (like withTransitionStaggered).

Example:

groups <- selectSimulationGroups
circles <- selectAllWithData "circle" groups.nodes
withTransitionStaggered config delayFn circles [fill colorByDepth]

#setAttrs Source

setAttrs :: forall sel m datum. SelectionM sel m => Array (Attribute datum) -> sel SBoundOwns Element datum -> m (sel SBoundOwns Element datum)

Set attributes on a bound selection

Updates existing elements with new attribute values. Returns the updated selection.

Re-exports from Hylograph.Interpreter.D3

#D3v2Selection_ Source

newtype D3v2Selection_ (state :: Type) (parent :: Type) (datum :: Type)

Selection type for D3v2 interpreter

This is just a newtype wrapper around Hylograph.Internal.Selection.Types.Selection to distinguish it from other interpreter's selection types.

Instances

  • SelectionM D3v2Selection_ D3v2M

    SelectionM instance for D3v2 interpreter

    Delegates all operations to Hylograph.Internal.Selection.Operations, which uses the phantom types with unsafePartial for safe pattern matching.

  • TransitionM D3v2Selection_ D3v2M

    TransitionM instance for D3v2 interpreter

    Implements animated transitions using D3's transition engine. Applies transitions to each element in the bound selection.

#D3v2M Source

newtype D3v2M a

The D3v2 interpreter monad (without simulation state)

Wraps Effect to allow for DOM manipulation.

Instances

#selectChildInheritingD3v2 Source

selectChildInheritingD3v2 :: forall parent datum. String -> D3v2Selection_ SBoundOwns parent datum -> D3v2M (D3v2Selection_ SBoundOwns Element datum)

Select child elements, inheriting parent's data (D3v2 version)

Wrapper around Operations.selectChildInheriting that works with D3v2Selection_.

#runD3v2M Source

runD3v2M :: D3v2M ~> Effect

Run the D3v2 interpreter

#reselectD3v2 Source

reselectD3v2 :: forall datum datumOut. String -> Map String (D3v2Selection_ SBoundOwns Element datum) -> Effect (D3v2Selection_ SEmpty Element datumOut)

Helper function for reselecting from D3v2 renderTree results

This wraps the reselect function from Operations to work with D3v2Selection_ newtype.

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