Module

Hylograph.Unified.Display

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

Hylograph.Unified.Display - Profunctor-based Display Transformations

Non-destructive display formatting as composable typed pipelines.

Core Insight

Display transformations are typed morphisms that compose:

f :: a -> b
g :: b -> c
f >>> g :: a -> c

The key property is non-destructiveness: the underlying value is preserved; only the presentation changes.

Profunctor Structure

Display a b is a profunctor:

  • Contravariant in a (input type)
  • Covariant in b (output type)

This enables:

  • lmapD f: Change input type (e.g., extract field from record)
  • rmapD g: Change output type (e.g., further transform result)
  • Composition via >>>

Usage

-- Define reusable displays
percentageD :: Display Number String
percentageD = scaleD 100.0 >>> roundD 1 >>> showNumD >>> suffixD "%"

-- Adapt to different sources
rateDisplay :: Display { rate :: Number } String
rateDisplay = lmapD _.rate percentageD

-- Use in spreadsheet
cellValue = format percentageD computedValue

-- Use in visualization label
labelText = runDisplay percentageD dataPoint.value

#Display Source

newtype Display a b

Display transformation from type a to type b

This is essentially a newtype around a -> b, but with a semantic meaning: it's a non-destructive presentation transformation.

The profunctor structure (contravariant in a, covariant in b) enables flexible composition and adaptation.

Constructors

#runDisplay Source

runDisplay :: forall a b. Display a b -> a -> b

Run a display transformation

#idD Source

idD :: forall a. Display a a

Identity display (does nothing)

#composeD Source

composeD :: forall a b c. Display a b -> Display b c -> Display a c

Compose two displays (left to right)

f >>> g means: first apply f, then apply g

#(>>>) Source

Operator alias for Hylograph.Unified.Display.composeD (left-associative / precedence 9)

#lmapD Source

lmapD :: forall a a' b. (a' -> a) -> Display a b -> Display a' b

Contravariant map: change input type

Given a way to get a from a', adapt a Display a b to Display a' b

Example:

percentageD :: Display Number String
lmapD _.rate percentageD :: Display { rate :: Number } String

#rmapD Source

rmapD :: forall a b b'. (b -> b') -> Display a b -> Display a b'

Covariant map: change output type

Given a way to transform b to b', adapt a Display a b to Display a b'

#dimapD Source

dimapD :: forall a a' b b'. (a' -> a) -> (b -> b') -> Display a b -> Display a' b'

Profunctor dimap: change both types

#roundD Source

roundD :: Int -> Display Number Number

Round to N decimal places

Example: roundD 2 makes 3.14159 display as 3.14

#scaleD Source

scaleD :: Number -> Display Number Number

Scale by a factor

Example: scaleD 100.0 for percentages (0.5 -> 50.0)

#clampD Source

clampD :: Number -> Number -> Display Number Number

Clamp to range [lo, hi]

#absD Source

absD :: Display Number Number

Absolute value

#floorD Source

floorD :: Display Number Number

Floor (round down)

#ceilD Source

ceilD :: Display Number Number

Ceiling (round up)

#showNumD Source

showNumD :: Display Number String

Default numeric display (smart formatting)

  • Integers display without decimal point
  • Floats display with minimal precision (trimmed trailing zeros)

#fixedD Source

fixedD :: Int -> Display Number String

Fixed decimal places

Example: fixedD 2 makes 3.1 display as 3.10

#sciD Source

sciD :: Int -> Display Number String

Scientific notation

Example: sciD 2 makes 1234.5 display as 1.23e3

#intD Source

intD :: Display Number String

Integer display (truncates decimal part)

#prefixD Source

prefixD :: String -> Display String String

Add prefix

Example: prefixD "$" makes 100 display as $100

#suffixD Source

suffixD :: String -> Display String String

Add suffix

Example: suffixD "%" makes 50 display as 50%

#padLeftD Source

padLeftD :: Int -> Char -> Display String String

Pad left to width with character

#padRightD Source

padRightD :: Int -> Char -> Display String String

Pad right to width with character

#upperD Source

upperD :: Display String String

Convert to uppercase

#lowerD Source

lowerD :: Display String String

Convert to lowercase

#trimD Source

trimD :: Display String String

Trim whitespace

#percentageD Source

percentageD :: Display Number String

Percentage display: 0.156 -> "15.6%"

#currencyD Source

currencyD :: Display Number String

Currency display (USD): 1234.56 -> "$1,234.56"

#currencyWithSymbol Source

currencyWithSymbol :: String -> Display Number String

Currency with custom symbol

#thousandsD Source

thousandsD :: Display String String

Add thousands separators: 1234567 -> "1,234,567"

#signedD Source

signedD :: Display Number String

Signed display: negative in parentheses (accounting style)

Example: -100 -> "(100)", 100 -> "100"

#compactD Source

compactD :: Display Number String

Compact display for large numbers

Example: 1500000 -> "1.5M", 1500 -> "1.5K"

#boolD Source

boolD :: Display Boolean String

Boolean display: true -> "true", false -> "false"

#yesNoD Source

yesNoD :: Display Boolean String

Boolean display: true -> "Yes", false -> "No"

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