Module

Hylograph.Unified.Examples

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

PSD3.Unified.Examples - Examples of the Unified DSL

This module demonstrates how to use the unified DSL and shows that old and new styles work together seamlessly.

Highlights

  1. DataDSL: Unified computations for spreadsheet and viz
  2. Display: Profunctor-based non-destructive formatting
  3. AST Joins: Data binding patterns for visualization

#DataPoint Source

type DataPoint = { category :: String, value :: Number, x :: Number, y :: Number }

#QuarterData Source

type QuarterData = { expenses :: Number, quarter :: String, revenue :: Number }

#newStyleCircle Source

newStyleCircle :: DataPoint -> Array (Attribute DataPoint)

New-style visualization using Display profunctor

#newStyleCircleFormatted Source

newStyleCircleFormatted :: DataPoint -> Array (Attribute DataPoint)

With more sophisticated formatting

#computeGrowth Source

computeGrowth :: forall repr. DataDSL repr => repr (Array Number) -> repr (Array Number)

A computation that works in BOTH spreadsheet and visualization contexts

#averageAboveThreshold Source

averageAboveThreshold :: forall repr. DataDSL repr => Number -> repr (Array Number) -> repr Number

Another unified computation: filter and average

#computeProfit Source

computeProfit :: forall repr. DataDSL repr => repr (Array QuarterData) -> repr (Array Number)

Quarterly profit computation

#totalProfit Source

totalProfit :: forall repr. DataDSL repr => repr (Array QuarterData) -> repr Number

Total profit (works in sheet or viz)

#percentDisplay Source

percentDisplay :: Display Number String

Percentage display: 0.156 -> "15.6%"

#currencyDisplay Source

currencyDisplay :: Display Number String

Currency display: 1234.56 -> "$1,234.56"

#profitDisplay Source

profitDisplay :: Display Number String

Profit display (with sign): -100 -> "(100)", 100 -> "100"

#compactDisplay Source

compactDisplay :: Display Number String

Compact display for large numbers: 1500000 -> "1.5M"

#showAsPercent Source

showAsPercent :: Number -> String

Using displays

#showAsCurrency Source

#quarterGrowthDisplay Source

quarterGrowthDisplay :: Display QuarterData String

Adapt percentage display to work with QuarterData

#revenueDisplay Source

revenueDisplay :: Display QuarterData String

Adapt to extract different fields

#newStyleViz Source

newStyleViz :: Array DataPoint -> Tree DataPoint

A visualization using the new style throughout

#myComputation Source

myComputation :: forall repr. DataDSL repr => repr (Array Number) -> repr Number

Define computation abstractly

#useInViz Source

useInViz :: Array Number -> Number

Use in visualization context (via EvalD)

#formatLabel Source

formatLabel :: QuarterData -> String

Example of creating a label with display formatting

#formatGrowthLabel Source

formatGrowthLabel :: QuarterData -> String

Or with percentage growth:

#simpleJoinExample Source

simpleJoinExample :: Array DataPoint -> Tree DataPoint

Simple data join

Use joinData for one-shot renders where elements don't update. For dynamic updates, use updateJoin with a keyFn.

#joinWithGUPExample Source

joinWithGUPExample :: Array DataPoint -> Tree DataPoint

Join with GUP (General Update Pattern) - enter/update/exit

For dynamic updates, use updateJoin with a keyFn to identify elements. The keyFn extracts a unique string identifier from each datum.

#SceneData Source

type SceneData = { points :: Array DataPoint, title :: String }

Scene data with nested structure

#nestedJoinExample Source

nestedJoinExample :: SceneData -> Tree SceneData

Nested join with type decomposition

The scene data contains an array of points. nestedJoin extracts the inner array for joining.

Use this for one-shot renders with type decomposition. For dynamic updates with decomposition, use updateNestedJoin.

#fullJoinExample Source

fullJoinExample :: SceneData -> Tree SceneData

Full join: decomposition + GUP

This is the most powerful combination - handles:

  • Type-changing decomposition (SceneData -> Array DataPoint)
  • Enter/update/exit behaviors with transitions
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