Module

Hylograph.Scale

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

Hylograph.Scale - Pure PureScript scales for data visualization

This module re-exports the pure implementation from Scale.Pure, categorical color palettes from Scale.ColorSchemes, color interpolation from Scale.Interpolation, and sequential/diverging color interpolators from Scale.Sequential.

No D3 or FFI dependency.

Basic Usage

import Hylograph.Scale (linear, domain, range, applyScale, ticks)

myScale = linear # domain [0.0, 100.0] # range [0.0, 800.0]
pixelX = applyScale myScale 50.0  -- Returns 400.0
tickValues = ticks 10 myScale     -- Returns nice tick values

Re-exports from Hylograph.Scale.ColorSchemes

#schemeTableau10At Source

#schemeTableau10 Source

schemeTableau10 :: Array String

Tableau 10 — the modern Tableau palette Slightly softer than Category10

#schemeSet3 Source

schemeSet3 :: Array String

Set3 — 12 light colors

#schemeSet2 Source

schemeSet2 :: Array String

Set2 — 8 pastel colors

#schemeSet1 Source

schemeSet1 :: Array String

Set1 — 9 bold colors

#schemePastel2 Source

schemePastel2 :: Array String

Pastel2 — 8 light pastel colors

#schemePastel1 Source

schemePastel1 :: Array String

Pastel1 — 9 light pastel colors

#schemePairedAt Source

#schemePaired Source

schemePaired :: Array String

Paired — 12 colors in 6 pairs (light/dark)

#schemeDark2 Source

schemeDark2 :: Array String

Dark2 — 8 dark colors

#schemeCategory10At Source

#schemeCategory10 Source

schemeCategory10 :: Array String

Tableau 10 — the default categorical palette Designed by Tableau for data visualization

#schemeAccent Source

schemeAccent :: Array String

Accent — 8 accent colors

Re-exports from Hylograph.Scale.Interpolation

#interpolateRgb Source

interpolateRgb :: String -> String -> (Number -> String)

RGB color interpolation

Interpolates between two CSS hex color strings in RGB space.

interpolateRgb "#ff0000" "#0000ff" 0.5  -- Returns "#800080"

#interpolateNumber Source

interpolateNumber :: Number -> Number -> Number -> Number

Linear number interpolation

#interpolateHsl Source

interpolateHsl :: String -> String -> (Number -> String)

HSL color interpolation

Interpolates between two CSS hex color strings in HSL space, taking the shorter hue arc.

interpolateHsl "#ff0000" "#00ff00" 0.5  -- Yellow-ish

Re-exports from Hylograph.Scale.Pure

#Scale Source

newtype Scale :: forall k. Type -> Type -> k -> Typenewtype Scale domain range kind

A pure scale is a record holding the forward mapping function, an inverse function, the current domain and range arrays, clamping state, a tick generator, and transform-specific parameters.

The phantom types mirror those in Hylograph.Scale:

  • domain - the input type (always Number for continuous scales)
  • range - the output type (always Number for continuous scales)
  • kind - the scale kind (always Continuous here)

Constructors

#Interpolator Source

type Interpolator a = Number -> a

An interpolator maps [0, 1] to a value

#ContinuousScale Source

type ContinuousScale = Scale Number Number Continuous

Convenient alias matching Hylograph.Scale.ContinuousScale

#Continuous Source

data Continuous

Phantom type for continuous scales

#ticks Source

ticks :: Int -> ContinuousScale -> Array Number

Generate nice tick positions for a scale

Uses D3's tick algorithm to find "nice" numbers (multiples of 1, 2, or 5 times a power of 10).

scale = linear # domain [0.0, 100.0] # range [0.0, 500.0]
ticks 5 scale  -- Returns [0.0, 20.0, 40.0, 60.0, 80.0, 100.0]

#tickFormat Source

tickFormat :: Int -> String -> ContinuousScale -> (Number -> String)

Get a tick formatter function

The specifier argument is accepted for API compatibility but this pure implementation uses show for formatting.

#sqrt Source

sqrt :: ContinuousScale

Create a square root scale (power scale with exponent 0.5)

Useful for sizing circles by area:

radiusScale = sqrt # domain [0.0, maxValue] # range [0.0, 50.0]

#round Source

round :: Boolean -> ContinuousScale -> ContinuousScale

Enable or disable output rounding

When enabled, output values are rounded to the nearest integer.

rounded = linear # domain [0.0, 100.0] # range [0.0, 500.0] # round true
applyScale rounded 33.3  -- Returns 167.0, not 166.5

#range Source

range :: Array Number -> ContinuousScale -> ContinuousScale

Set the range (output extent) of a scale

myScale = linear # domain [0.0, 100.0] # range [0.0, 500.0]

#pow Source

pow :: ContinuousScale

Create a power scale with configurable exponent (default exponent 1.0)

scale = pow # exponent 2.0 # domain [0.0, 10.0] # range [0.0, 100.0]

#niceCount Source

niceCount :: Int -> ContinuousScale -> ContinuousScale

Extend the domain to nice round values with a specified tick count hint

niceScale = linear # domain [3.0, 97.0] # niceCount 5

#nice Source

nice :: ContinuousScale -> ContinuousScale

Extend the domain to nice round values

Uses 10 as the default tick count hint for computing step size.

niceScale = linear # domain [3.0, 97.0] # nice
-- Domain becomes approximately [0.0, 100.0]

#map Source

map :: forall b. (Number -> b) -> ContinuousScale -> (Number -> b)

Transform the output after applying the scale (covariant/functor-like)

baseScale = linear # domain [0.0, 100.0] # range [0.0, 500.0]
offsetScale = map (_ + 50.0) baseScale
offsetScale 0.0  -- Returns 50.0

#log Source

log :: ContinuousScale

Create a logarithmic scale (default base 10)

Domain must not include zero.

scale = log # domain [1.0, 1000.0] # range [0.0, 300.0]

#linear Source

linear :: ContinuousScale

Create a linear scale with default domain [0, 1] and range [0, 1]

scale = linear # domain [0.0, 100.0] # range [0.0, 500.0]
applyScale scale 50.0  -- Returns 250.0

#invert Source

invert :: ContinuousScale -> Number -> Maybe Number

Invert a continuous scale (range value back to domain value)

Returns Nothing if the inversion is not defined (e.g. division by zero).

scale = linear # domain [0.0, 100.0] # range [0.0, 500.0]
invert scale 250.0  -- Returns Just 50.0

#exponent Source

exponent :: Number -> ContinuousScale -> ContinuousScale

Set the exponent for a power scale

squareScale = pow # exponent 2.0 # domain [0.0, 10.0] # range [0.0, 100.0]

#domain Source

domain :: Array Number -> ContinuousScale -> ContinuousScale

Set the domain (input extent) of a scale

myScale = linear # domain [0.0, 100.0] # range [0.0, 500.0]

#dimap Source

dimap :: forall a b. (a -> Number) -> (Number -> b) -> ContinuousScale -> (a -> b)

Transform both input and output (profunctor-like)

transformed = scale # dimap preprocess postprocess

#copy Source

copy :: ContinuousScale -> ContinuousScale

Create a copy of a scale (identity operation for pure data, included for API compatibility with the D3 FFI module)

#contramap Source

contramap :: forall a. (a -> Number) -> ContinuousScale -> (a -> Number)

Transform the input before applying the scale (contravariant mapping)

fahrenheitScale = linear # domain [32.0, 212.0] # range [0.0, 100.0]
celsiusScale = contramap (\c -> c * 9.0 / 5.0 + 32.0) fahrenheitScale
celsiusScale 100.0  -- Returns 100.0

#clamp Source

clamp :: Boolean -> ContinuousScale -> ContinuousScale

Enable or disable clamping

When enabled, output values are constrained to the range even for out-of-domain inputs.

clamped = linear # domain [0.0, 100.0] # range [0.0, 500.0] # clamp true
applyScale clamped 200.0  -- Returns 500.0, not 1000.0

#base Source

base :: Number -> ContinuousScale -> ContinuousScale

Set the base for a logarithmic scale (default 10)

scale = log # base 2.0 # domain [1.0, 1024.0] # range [0.0, 10.0]

#applyScale Source

applyScale :: ContinuousScale -> Number -> Number

Apply a scale to a domain value, producing a range value

scale = linear # domain [0.0, 100.0] # range [0.0, 500.0]
applyScale scale 50.0  -- Returns 250.0

#andThen Source

andThen :: ContinuousScale -> ContinuousScale -> (Number -> Number)

Compose two scales: apply the first, then the second

normalize = linear # domain [0.0, 100.0] # range [0.0, 1.0]
toPixels  = linear # domain [0.0, 1.0]   # range [0.0, 500.0]
combined  = normalize `andThen` toPixels
combined 50.0  -- Returns 250.0

Re-exports from Hylograph.Scale.Sequential

#interpolateYlOrRd Source

#interpolateYlOrBr Source

#interpolateYlGnBu Source

#interpolateYlGn Source

#interpolateWarm Source

#interpolateViridis Source

#interpolateTurbo Source

#interpolateSpectral Source

#interpolateSinebow Source

#interpolateReds Source

#interpolateRdYlGn Source

#interpolateRdYlBu Source

#interpolateRdPu Source

#interpolateRdGy Source

#interpolateRdBu Source

#interpolateRainbow Source

#interpolatePurples Source

#interpolatePuRd Source

#interpolatePuBuGn Source

#interpolatePuBu Source

#interpolatePlasma Source

#interpolatePiYG Source

#interpolatePRGn Source

#interpolateOranges Source

#interpolateOrRd Source

#interpolateMagma Source

#interpolateInferno Source

#interpolateGreys Source

#interpolateGreens Source

#interpolateGnBu Source

#interpolateCubehelixDefault Source

#interpolateCool Source

#interpolateCividis Source

#interpolateBuPu Source

#interpolateBuGn Source

#interpolateBrBG Source

#interpolateBlues Source

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.ColorSchemes
Hylograph.Scale.FP
Hylograph.Scale.Interpolation
Hylograph.Scale.Pure
Hylograph.Scale.Sequential
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