Hylograph Project Documentation

hylograph-selection

purescript-hylograph-selection

This is the core package of Hylograph, a PureScript library system for building interactive data visualizations: declarative tree construction, scales, layout algorithms, graph algorithms and force simulation. Rendering, scales and layouts are pure PureScript with no JavaScript visualization dependency. Force simulation is the one exception: its force calculations come from d3-force, run by the library’s own simulation loop (see hylograph-simulation). See hylograph.net for documentation, guides, and examples.

Declarative DOM tree construction and interpretation for PureScript. This package has no runtime dependency on D3 or any other JavaScript visualization library.

Live interactive demo can be seen as part of the suite of Hylograph library demos. Click the screenshot below for The Hylographic Fold — a seven-chapter guide explaining how HATS works, built entirely with HATS.

The Hylographic Fold Demo

Installation

spago install hylograph-selection

Overview

Build visualizations as declarative trees using HATS (Hylomorphic Abstract Tree Syntax). A HATS tree describes what to build; interpreters decide how.

import Prelude

import Data.Array (mapWithIndex)
import Data.Int (toNumber)
import Effect (Effect)
import Hylograph.HATS (Tree, ElementType(..), elem, forEach)
import Hylograph.HATS.Friendly as F
import Hylograph.HATS.InterpreterTick (rerender)

type Bar = { label :: String, value :: Number }

barChart :: Array Bar -> Tree
barChart bars =
  elem SVG [ F.viewBox 0.0 0.0 400.0 300.0 ]
    [ forEach "bars" Rect (mapWithIndex (\i bar -> { i, bar }) bars) _.bar.label \d ->
        elem Rect
          [ F.x (toNumber d.i * 50.0)
          , F.y (300.0 - d.bar.value)
          , F.width 40.0
          , F.height d.bar.value
          , F.fill "#C9A962"
          ] []
    ]

main :: Effect Unit
main = void $ rerender "#chart" $ barChart
  [ { label: "a", value: 120.0 }
  , { label: "b", value: 200.0 }
  , { label: "c", value: 80.0 }
  ]

A Tree is an ordinary data structure, so an interpreter is any function that walks it. Two are in everyday use: the DOM interpreter (rerender, which is what draws the SVG above) and the English interpreter (runEnglish, a plain-text description of the structure). Both stop at the same place. The template passed to forEach is a PureScript function, so an interpreter can run it for each datum but cannot read it: English prints Fold "bars" over 3 items from array and then (Template function defined for creating elements from data); it cannot say what a bar looks like.

Key Features

Modules

Core

Scales (pure, no D3)

Interpreters

Interactions

The Hylograph Library System

This package is the foundation. The full ecosystem:

Package Description
hylograph-selection Core: HATS tree construction, the DOM and English interpreters, scales, color schemes, coordinated highlighting, zoom, brush, pointer events. This package.
hylograph-graph Graph data structures and algorithms — shortest path (Dijkstra), BFS/DFS, connected and biconnected components, topological sort.
hylograph-layout Layout algorithms in pure PureScript — tree and cluster layouts, pack, partition, treemap, edge bundling, Sankey, chord, adjacency matrix.
hylograph-simulation Force simulation — n-body, collision, link forces, centering. The force calculations are d3-force’s; the simulation loop is the library’s own, which is what lets data enter and leave a running simulation.
hylograph-simulation-halogen Halogen adapter for simulation events, for tick-driven rendering.
hylograph-canvas Canvas 2D drawing of circles and lines, with zoom and pan. It does not interpret HATS trees.
hylograph-optics Optics (lenses, traversals) over rose trees and graphs.
hylograph-music Proof of concept: an audio interpreter that plays a HATS tree as notes.

These packages are published to the PureScript Registry and documented at hylograph.net.

License

MIT