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
schemeTableau10At :: Int -> String#schemeTableau10 Source
schemeTableau10 :: Array StringTableau 10 — the modern Tableau palette Slightly softer than Category10
#schemeSet3 Source
schemeSet3 :: Array StringSet3 — 12 light colors
#schemeSet2 Source
schemeSet2 :: Array StringSet2 — 8 pastel colors
#schemeSet1 Source
schemeSet1 :: Array StringSet1 — 9 bold colors
#schemePastel2 Source
schemePastel2 :: Array StringPastel2 — 8 light pastel colors
#schemePastel1 Source
schemePastel1 :: Array StringPastel1 — 9 light pastel colors
#schemePairedAt Source
schemePairedAt :: Int -> String#schemePaired Source
schemePaired :: Array StringPaired — 12 colors in 6 pairs (light/dark)
#schemeDark2 Source
schemeDark2 :: Array StringDark2 — 8 dark colors
#schemeCategory10At Source
schemeCategory10At :: Int -> String#schemeCategory10 Source
schemeCategory10 :: Array StringTableau 10 — the default categorical palette Designed by Tableau for data visualization
#schemeAccent Source
schemeAccent :: Array StringAccent — 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 -> NumberLinear 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 -> aAn interpolator maps [0, 1] to a value
#ContinuousScale Source
type ContinuousScale = Scale Number Number ContinuousConvenient alias matching Hylograph.Scale.ContinuousScale
#Continuous Source
data ContinuousPhantom type for continuous scales
#ticks Source
ticks :: Int -> ContinuousScale -> Array NumberGenerate 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 :: ContinuousScaleCreate 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 -> ContinuousScaleEnable 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 -> ContinuousScaleSet the range (output extent) of a scale
myScale = linear # domain [0.0, 100.0] # range [0.0, 500.0]
#pow Source
pow :: ContinuousScaleCreate 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 -> ContinuousScaleExtend 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 -> ContinuousScaleExtend 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 :: ContinuousScaleCreate 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 :: ContinuousScaleCreate 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 NumberInvert 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 -> ContinuousScaleSet 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 -> ContinuousScaleSet 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 -> ContinuousScaleCreate 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 -> ContinuousScaleEnable 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 -> ContinuousScaleSet 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 -> NumberApply 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
interpolateYlOrRd :: Number -> String#interpolateYlOrBr Source
interpolateYlOrBr :: Number -> String#interpolateYlGnBu Source
interpolateYlGnBu :: Number -> String#interpolateYlGn Source
interpolateYlGn :: Number -> String#interpolateWarm Source
interpolateWarm :: Number -> String#interpolateViridis Source
interpolateViridis :: Number -> String#interpolateTurbo Source
interpolateTurbo :: Number -> String#interpolateSpectral Source
interpolateSpectral :: Number -> String#interpolateSinebow Source
interpolateSinebow :: Number -> String#interpolateReds Source
interpolateReds :: Number -> String#interpolateRdYlGn Source
interpolateRdYlGn :: Number -> String#interpolateRdYlBu Source
interpolateRdYlBu :: Number -> String#interpolateRdPu Source
interpolateRdPu :: Number -> String#interpolateRdGy Source
interpolateRdGy :: Number -> String#interpolateRdBu Source
interpolateRdBu :: Number -> String#interpolateRainbow Source
interpolateRainbow :: Number -> String#interpolatePurples Source
interpolatePurples :: Number -> String#interpolatePuRd Source
interpolatePuRd :: Number -> String#interpolatePuBuGn Source
interpolatePuBuGn :: Number -> String#interpolatePuBu Source
interpolatePuBu :: Number -> String#interpolatePlasma Source
interpolatePlasma :: Number -> String#interpolatePiYG Source
interpolatePiYG :: Number -> String#interpolatePRGn Source
interpolatePRGn :: Number -> String#interpolateOranges Source
interpolateOranges :: Number -> String#interpolateOrRd Source
interpolateOrRd :: Number -> String#interpolateMagma Source
interpolateMagma :: Number -> String#interpolateInferno Source
interpolateInferno :: Number -> String#interpolateGreys Source
interpolateGreys :: Number -> String#interpolateGreens Source
interpolateGreens :: Number -> String#interpolateGnBu Source
interpolateGnBu :: Number -> String#interpolateCool Source
interpolateCool :: Number -> String#interpolateCividis Source
interpolateCividis :: Number -> String#interpolateBuPu Source
interpolateBuPu :: Number -> String#interpolateBuGn Source
interpolateBuGn :: Number -> String#interpolateBrBG Source
interpolateBrBG :: Number -> String#interpolateBlues Source
interpolateBlues :: Number -> String- 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