Module

Hylograph.Unified.DataDSL

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

PSD3.Unified.DataDSL - Unified Data Operations

This module provides a unified finally-tagless DSL for data operations that works across both visualization (PSD3) and spreadsheet contexts.

Core Insight

D3's data joins and spreadsheet formulas are fundamentally the same:

  • selection.data(arr).join("rect")mapA template (source arr)
  • =SUM(A1:A10)foldA (+) 0 (source range)

By abstracting these operations into a type class, we enable:

  1. Same computation definition for viz AND spreadsheet
  2. Multiple interpreters (Eval, Deps, Pretty, CodeGen)
  3. Type-safe composition across contexts

Relationship to Existing PSD3 Classes

DataDSL extends and unifies the existing expression classes:

  • NumExprDataDSL (num, add, sub, mul, div)
  • BoolExprDataDSL (bool, and, or, not, ifThenElse)
  • CompareExprDataDSL (lt, lte, gt, gte, eqNum)

Plus NEW array/data operations:

  • source, mapA, foldA, filterA, flatMapA

Usage

-- Define computation once
growthRates :: forall repr. DataDSL repr => repr (Array Number) -> repr (Array Number)
growthRates = mapA (\x -> x * 1.1)

-- Use in visualization
myViz = join (growthRates data) \rate -> elem Rect [height (rate * 10)]

-- Use in spreadsheet
myCell = format percentageD (avgA (growthRates data))

#DataDSL Source

class DataDSL :: (Type -> Type) -> Constraintclass DataDSL (repr :: Type -> Type)  where

The unified data operations type class

This class captures the fundamental operations on data that are shared between visualization and spreadsheet contexts.

Key insight: These operations are exactly what D3 data joins do, and also what spreadsheet formulas do. They're the same thing!

Members

#TrigDSL Source

class TrigDSL :: (Type -> Type) -> Constraintclass (DataDSL repr) <= TrigDSL repr  where

Trigonometric operations - extension for visualization-specific math

Separated from DataDSL because spreadsheets rarely need trig, but polar/radial visualizations (chord diagrams, pie charts) do.

polarX :: forall repr. DataDSL repr => TrigDSL repr => repr Number -> repr Number -> repr Number
polarX r angle = r `mul` cos angle

Members

#sumA Source

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

Sum numeric array

Spreadsheet equivalent: =SUM(range)

#avgA Source

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

Average of numeric array

Spreadsheet equivalent: =AVERAGE(range)

#countA Source

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

Count elements

Spreadsheet equivalent: =COUNT(range)

#maxA Source

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

Maximum value

Spreadsheet equivalent: =MAX(range)

#minA Source

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

Minimum value

Spreadsheet equivalent: =MIN(range)

#productA Source

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

Product of numeric array

Spreadsheet equivalent: =PRODUCT(range)

#absA Source

absA :: forall repr. DataDSL repr => repr Number -> repr Number

Absolute value

Spreadsheet equivalent: =ABS(x)

#negateA Source

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

Negate all values in array

Spreadsheet equivalent: =MAP(range, x => -x)

#DataSource Source

data DataSource a

Data source - where data enters the computation pipeline

This is the "join point" - analogous to D3's selection.data()

Constructors

#CellAddr Source

type CellAddr = { col :: Int, row :: Int }

Cell address for spreadsheet sources

#TypedCell Source

newtype TypedCell :: forall k. k -> Typenewtype TypedCell a

Type-safe cell reference with phantom type tracking the value type

Constructors

Re-exports from Hylograph.Expr.Expr

#BoolExpr Source

class BoolExpr :: (Type -> Type) -> Constraintclass BoolExpr repr 

Boolean expressions

#CompareExpr Source

class CompareExpr :: (Type -> Type) -> Constraintclass CompareExpr repr 

Comparison expressions (produce Boolean from Numbers)

#NumExpr Source

class NumExpr :: (Type -> Type) -> Constraintclass NumExpr repr 

Numeric expressions

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