Package

purescript-hylograph-selection

Repository
afcondon/purescript-hylograph-selection
License
MIT AND ISC
Uploaded by
pacchettibotti
Published on
2026-02-16T16:42:17Z

Tree Builder Demo

Type-safe D3 selection and attribute library for PureScript.

Overview

A declarative, type-safe approach to D3.js visualization in PureScript. Instead of imperative D3 method chaining, you build a HATS tree that describes your visualization, then render it.

Installation

spago install hylograph-selection

Key Concepts

HATS (Hylomorphic Abstract Tree Syntax)

Build visualizations as data structures using HATS:

import Hylograph.HATS as H
import Hylograph.HATS.Friendly as HF
import Hylograph.Expr.Friendly (width, height, cx, cy, r, fill, num, text)
import Hylograph.HATS.InterpreterTick (rerender)

myViz :: H.Tree
myViz =
  HF.svg [ width $ num 400.0, height $ num 300.0 ]
    [ HF.circle
        [ cx $ num 200.0
        , cy $ num 150.0
        , r $ num 50.0
        , fill $ text "steelblue"
        ]
    ]

main :: Effect Unit
main = void $ rerender "#chart" myViz

Data-Driven Rendering

Generate elements from data with Array.map:

barChart :: Array Number -> H.Tree
barChart dataset =
  HF.svg [ width $ num 400.0, height $ num 300.0 ]
    (dataset # Array.mapWithIndex \i val ->
      HF.rect
        [ x $ num (toNumber i * 50.0)
        , y $ num (300.0 - val)
        , width $ num 40.0
        , height $ num val
        , fill $ text "steelblue"
        ])

Interpreters

  • D3 Interpreter (Hylograph.HATS.InterpreterTick) - Renders to DOM
  • English Interpreter - Describes the tree in plain English
  • Mermaid Interpreter - Generates Mermaid diagrams
  • SemiQuine Interpreter - Generates PureScript code
  • MetaHATS Interpreter - Meta-visualization of tree structure

Modules

Core

  • Hylograph.HATS - Tree types and constructors
  • Hylograph.HATS.Friendly - User-friendly element helpers (svg, circle, rect, etc.)
  • Hylograph.HATS.InterpreterTick - DOM rendering (rerender, rerenderInto)
  • Hylograph.Render - Selection-based rendering utilities

Expressions

  • Hylograph.Expr.Friendly - Attribute helpers (width, cx, fill, num, text, etc.)
  • Hylograph.Expr.Attr - Low-level attribute types
  • Hylograph.Expr.Sugar - Convenience functions

Interpreters

  • Hylograph.Interpreter.D3 - D3.js selection operations
  • Hylograph.Interpreter.English - Plain English description
  • Hylograph.Interpreter.Mermaid - Mermaid diagram generation
  • Hylograph.Interpreter.SemiQuine - Code generation
  • Hylograph.Interpreter.MetaHATS - Tree meta-visualization

Interactions

  • Hylograph.Interaction.Zoom - Zoom behavior
  • Hylograph.Interaction.Brush - Brush selection
  • Hylograph.Interaction.Pointer - Pointer events
  • Hylograph.Interaction.Coordinated - Coordinated highlighting

Utilities

  • Hylograph.Scale - D3-style scales
  • Hylograph.Transform - SVG transforms
  • Hylograph.Tooltip - Tooltip helpers

Part of Hylograph

  • hylograph-selection - D3 selection library (this package)
  • hylograph-graph - Graph data structures
  • hylograph-layout - Layout algorithms
  • hylograph-simulation - Force simulation

Uses tree-rose for rose tree data structures.

License

MIT

Modules
Data.DependencyGraph
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.Element.Operations
Hylograph.Internal.Element.Types
Hylograph.Internal.FFI
Hylograph.Internal.Transition.FFI
Hylograph.Internal.Transition.Manager
Hylograph.Internal.Transition.Scene
Hylograph.Internal.Transition.Types
Hylograph.Internal.Types
Hylograph.Interpreter.English
Hylograph.Interpreter.Mermaid
Hylograph.Interpreter.MetaHATS
Hylograph.Interpreter.SemiQuine
Hylograph.Interpreter.SemiQuine.TreeToCode
Hylograph.Interpreter.SemiQuine.Types
Hylograph.Scale
Hylograph.Scale.FP
Hylograph.Shape.Arc
Hylograph.Shape.Pie
Hylograph.Shape.Polygon
Hylograph.Tooltip
Hylograph.Transform
Hylograph.Unified
Hylograph.Unified.Attribute
Hylograph.Unified.DataDSL
Hylograph.Unified.Display
Hylograph.Unified.Sugar
Dependencies