Hylograph.Scale
- Package
- purescript-hylograph-selection
- Repository
- afcondon/purescript-hylograph-selection
Hylograph.Scale - Type-safe scales with functional programming idioms
This module provides D3-compatible scales with PureScript type safety and functional programming abstractions. Uses d3-scale-chromatic.js via FFI.
Basic Usage
import Hylograph.Scale (linear, domain, range, apply, ticks)
-- Create a linear scale
myScale = linear # domain [0.0, 100.0] # range [0.0, 800.0]
-- Apply the scale
pixelX = apply myScale 50.0 -- Returns 400.0
-- Get tick marks
tickValues = ticks 10 myScale -- Returns nice tick values
Functional Idioms
Scales can be composed and transformed:
-- Compose scales
timeToPixel = timeScale `andThen` positionScale
-- Transform with Profunctor-like operations
celsiusScale = fahrenheitScale # contramap fahrenheitToCelsius
#Scale Source
data Scale t0 t1 t2A scale maps values from a domain to a range The phantom types track:
domain- the input typerange- the output typekind- the scale kind (Continuous, Ordinal, Band, etc.)
#Continuous Source
data ContinuousPhantom type for continuous scales (Linear, Log, Pow, etc.)
#ContinuousScale Source
type ContinuousScale = Scale Number Number ContinuousConvenient type aliases
#OrdinalScale Source
type OrdinalScale domain range = Scale domain range Ordinal#linear Source
linear :: ContinuousScaleCreate a linear scale Maps domain values linearly to range values
scale = linear # domain [0.0, 100.0] # range [0.0, 500.0]
apply scale 50.0 -- Returns 250.0
#log Source
log :: ContinuousScaleCreate a logarithmic scale Uses log transformation - domain must not include zero
scale = log # domain [1.0, 1000.0] # range [0.0, 300.0]
#pow Source
pow :: ContinuousScaleCreate a power scale with configurable exponent
scale = pow # exponent 2.0 # domain [0.0, 100.0] # range [0.0, 500.0]
#sqrt Source
sqrt :: ContinuousScaleCreate a square root scale (pow with exponent 0.5)
Useful for sizing circles by area
radiusScale = sqrt # domain [0.0, maxValue] # range [0.0, 50.0]
#symlog Source
symlog :: ContinuousScaleCreate a symlog scale (symmetric log) Handles negative values and zero gracefully
scale = symlog # constant 1.0 # domain [-100.0, 100.0] # range [0.0, 500.0]
#JSDate Source
data JSDateJavaScript Date object for time scales Compatible with native JS Date, can be created via FFI or js-date library
#Sequential Source
data SequentialPhantom type for sequential scales (color gradients)
#SequentialScale Source
type SequentialScale = Scale Number String Sequential#Quantile Source
data QuantilePhantom type for quantile scales (continuous → discrete based on quantiles)
#scaleQuantize Source
scaleQuantize :: forall r. QuantizeScale rCreate a quantize scale Maps continuous domain to discrete range (uniform intervals)
colorScale = scaleQuantize
# domain [0.0, 100.0]
# range ["low", "medium", "high"]
#scaleQuantile Source
scaleQuantile :: forall r. QuantileScale rCreate a quantile scale Maps continuous domain to discrete range based on quantiles
colorScale = scaleQuantile
# domain [0.0, 25.0, 50.0, 75.0, 100.0]
# range ["Q1", "Q2", "Q3", "Q4"]
#ordinal Source
ordinal :: forall d r. OrdinalScale d rCreate an ordinal scale Maps discrete domain values to discrete range values
colorScale = ordinal
# domain ["a", "b", "c"]
# range ["red", "green", "blue"]
#paddingInner Source
paddingInner :: forall d. Number -> BandScale d -> BandScale dSet inner padding (between bands) for band scales
#paddingOuter Source
paddingOuter :: forall d. Number -> BandScale d -> BandScale dSet outer padding (before first and after last band) for band scales
#base Source
base :: forall r. Number -> Scale Number r Continuous -> Scale Number r ContinuousSet the base for logarithmic scales (default 10)
#exponent Source
exponent :: forall r. Number -> Scale Number r Continuous -> Scale Number r ContinuousSet the exponent for power scales
#constant Source
constant :: forall r. Number -> Scale Number r Continuous -> Scale Number r ContinuousSet the constant for symlog scales
#applyScale Source
applyScale :: forall d r k. Scale d r k -> d -> rApply a scale to a value
scale = linear # domain [0.0, 100.0] # range [0.0, 500.0]
applyScale scale 50.0 -- Returns 250.0
#Interpolator Source
type Interpolator a = Number -> aAn interpolator maps [0, 1] to a value
#interpolateNumber Source
interpolateNumber :: Number -> Number -> Interpolator NumberLinear number interpolation
#interpolateRgb Source
interpolateRgb :: String -> String -> Interpolator StringRGB color interpolation
#interpolateHsl Source
interpolateHsl :: String -> String -> Interpolator String#schemeCategory10 Source
schemeCategory10 :: Array StringCategory10 color scheme (10 colors)
#schemeCategory10At Source
schemeCategory10At :: Int -> StringGet a Category10 color by index (wraps around modularly) Useful for coloring nodes by group number
fill = schemeCategory10At node.group
#schemeTableau10 Source
schemeTableau10 :: Array StringTableau10 color scheme (10 colors) Modern, accessible categorical palette
#schemeTableau10At Source
schemeTableau10At :: Int -> StringGet a Tableau10 color by index (wraps around modularly) Useful for coloring categories in visualizations
fill = schemeTableau10At categoryIndex
#schemePaired Source
schemePaired :: Array StringPaired color scheme (12 colors)
#schemePairedAt Source
schemePairedAt :: Int -> StringGet a Paired color by index (wraps around modularly)
#schemeSet1 Source
schemeSet1 :: Array StringSet1 color scheme (9 colors)
#schemeSet2 Source
schemeSet2 :: Array StringSet2 color scheme (8 colors)
#schemeSet3 Source
schemeSet3 :: Array StringSet3 color scheme (12 colors)
#schemeAccent Source
schemeAccent :: Array StringAccent color scheme (8 colors)
#schemeDark2 Source
schemeDark2 :: Array StringDark2 color scheme (8 colors)
#schemePastel1 Source
schemePastel1 :: Array StringPastel1 color scheme (9 colors)
#schemePastel2 Source
schemePastel2 :: Array StringPastel2 color scheme (8 colors)
#interpolateBlues Source
interpolateBlues :: Interpolator StringBlues single-hue sequential
#interpolateGreens Source
interpolateGreens :: Interpolator StringGreens single-hue sequential
#interpolateGreys Source
interpolateGreys :: Interpolator StringGreys single-hue sequential
#interpolateOranges Source
interpolateOranges :: Interpolator StringOranges single-hue sequential
#interpolatePurples Source
interpolatePurples :: Interpolator StringPurples single-hue sequential
#interpolateReds Source
interpolateReds :: Interpolator StringReds single-hue sequential
#interpolateViridis Source
interpolateViridis :: Interpolator StringViridis perceptually-uniform colormap
#interpolatePlasma Source
interpolatePlasma :: Interpolator StringPlasma colormap
#interpolateInferno Source
interpolateInferno :: Interpolator StringInferno colormap
#interpolateMagma Source
interpolateMagma :: Interpolator StringMagma colormap
#interpolateTurbo Source
interpolateTurbo :: Interpolator StringTurbo colormap (rainbow-like but more perceptual)
#interpolateWarm Source
interpolateWarm :: Interpolator StringWarm colormap (red to yellow)
#interpolateCool Source
interpolateCool :: Interpolator StringCool colormap (cyan to purple)
#interpolateRainbow Source
interpolateRainbow :: Interpolator StringRainbow colormap
#interpolateCividis Source
interpolateCividis :: Interpolator StringCividis colormap (colorblind-friendly)
#interpolateCubehelixDefault Source
interpolateCubehelixDefault :: Interpolator StringCubehelix default colormap
#interpolateBuGn Source
interpolateBuGn :: Interpolator StringBlue-Green sequential
#interpolateBuPu Source
interpolateBuPu :: Interpolator StringBlue-Purple sequential
#interpolateGnBu Source
interpolateGnBu :: Interpolator StringGreen-Blue sequential
#interpolateOrRd Source
interpolateOrRd :: Interpolator StringOrange-Red sequential
#interpolatePuBuGn Source
interpolatePuBuGn :: Interpolator StringPurple-Blue-Green sequential
#interpolatePuBu Source
interpolatePuBu :: Interpolator StringPurple-Blue sequential
#interpolatePuRd Source
interpolatePuRd :: Interpolator StringPurple-Red sequential
#interpolateRdPu Source
interpolateRdPu :: Interpolator StringRed-Purple sequential
#interpolateYlGnBu Source
interpolateYlGnBu :: Interpolator StringYellow-Green-Blue sequential
#interpolateYlGn Source
interpolateYlGn :: Interpolator StringYellow-Green sequential
#interpolateYlOrBr Source
interpolateYlOrBr :: Interpolator StringYellow-Orange-Brown sequential
#interpolateYlOrRd Source
interpolateYlOrRd :: Interpolator StringYellow-Orange-Red sequential
#interpolateRdYlGn Source
interpolateRdYlGn :: Interpolator StringRed-Yellow-Green diverging
#interpolateRdBu Source
interpolateRdBu :: Interpolator StringRed-Blue diverging
#interpolatePiYG Source
interpolatePiYG :: Interpolator StringPink-Yellow-Green diverging
#interpolateBrBG Source
interpolateBrBG :: Interpolator StringBrown-Blue-Green diverging
#interpolatePRGn Source
interpolatePRGn :: Interpolator StringPurple-Red-Green diverging
#interpolateSpectral Source
interpolateSpectral :: Interpolator StringSpectral diverging
#interpolateRdGy Source
interpolateRdGy :: Interpolator StringRed-Grey diverging
#interpolateRdYlBu Source
interpolateRdYlBu :: Interpolator StringRed-Yellow-Blue diverging
#interpolateSinebow Source
interpolateSinebow :: Interpolator StringSinebow cyclical colormap
- 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