Module

Color.Scale

This module defines color scales. A color scale is a continuum of colors that is defined on the closed interval [0, 1]. It is defined by the two colors at each endpoint (0 and 1) and possibly additional color stops in between. If a color scale is sampled between two color stops, the specified color space is used for linear interpolation (see mix).

#ColorStop

data ColorStop

A point on the color scale.

#colorStop

colorStop :: Color -> Number -> ColorStop

Create a color stop from a given Color and a number between 0 and 1. If the number is outside this range, it is clamped.

#stopRatio

#stopColor

#ColorScale

data ColorScale

A color scale is represented by a list of ColorStops and a ColorSpace that is used for interpolation between the stops.

#colorScale

colorScale :: ColorSpace -> Color -> List ColorStop -> Color -> ColorScale

Create a color scale. The color space is used for interpolation between different stops. The first Color defines the left end (color at ratio 0.0), the list of stops defines possible intermediate steps and the second Color argument defines the right end point (color at ratio 1.0).

#ColorStops

data ColorStops

Represents all ColorStops in a color scale. The first Color defines the left end (color at ratio 0.0), the list of stops defines possible intermediate steps and the second Color argument defines the right end point (color at ratio 1.0).

Constructors

#combineStops'

combineStops' :: Number -> Number -> ColorStops -> ColorStops -> ColorStops

Like combineStops, but the width of the "transition zone" can be specified as the first argument.

Example:

redToBlue `combineStops epsilon x` orangeToGray

Here, the color at x will be orange and color at x - epsilon will be blue. If we want the color at x to be blue, combineStops' epsilon (x + epsilon) could be used.

#combineStops

combineStops :: Number -> ColorStops -> ColorStops -> ColorStops

Concatenates two color scales. The first argument specifies the transition point as a number between zero and one. The color right at the transition point is the first color of the second color scale.

Example:

redToBlue `combineStops 0.4` orangeToGray

#reverseStops

reverseStops :: ColorStops -> ColorStops

Takes ColorStops and returns reverses it

#uniformScale

uniformScale :: forall f. Foldable f => ColorSpace -> Color -> f Color -> Color -> ColorScale

Create a uniform color scale from a list of colors that will be evenly spaced on the scale.

#uniformScale'

uniformScale' :: forall f. Foldable f => Color -> f Color -> Color -> ColorStops

Create ColorStops from a list of colors such that they will be evenly spaced on the scale.

#addStop

addStop :: ColorScale -> Color -> Number -> ColorScale

Add a stop to a color scale.

#addStop'

addStop' :: ColorStops -> Color -> Number -> ColorStops

Add a stop to a list of ColorStops.

#sample

sample :: ColorScale -> Number -> Color

Get the color at a specific point on the color scale by linearly interpolating between its colors (see mix and mkSimpleSampler).

#cubehelixSample

cubehelixSample :: ColorStops -> Number -> Color

Get the color at a specific point on the color scale, using the cubehelix interpolation (see mixCubehelix and mkSimpleSampler).

#mkSimpleSampler

mkSimpleSampler :: Interpolator -> ColorStops -> Number -> Color

Get the color at a specific point on the color scale (number between 0 and 1). If the number is smaller than 0, the color at 0 is returned. If the number is larger than 1, the color at 1 is returned.

#colors

colors :: ColorScale -> Int -> List Color

A list of colors that is sampled from a color scale. The number of colors can be specified.

#colors'

colors' :: (Number -> Color) -> Int -> List Color

Takes a sampling function and returns a list of colors that is sampled via that function. The number of colors can be specified.

#modify

modify :: (Number -> Color -> Color) -> ColorScale -> ColorScale

Modify the color scale by applying the given function to each color stop. The first argument is the position of the color stop.

#modify'

modify' :: (Number -> Color -> Color) -> ColorStops -> ColorStops

Modify a list of ColorStops by applying the given function to each color stop. The first argument is the position of the color stop.

#grayscale

grayscale :: ColorScale

A scale of colors from black to white.

#hot

hot :: ColorScale

A color scale that represents 'hot' colors.

#cool

cool :: ColorScale

A color scale that represents 'cool' colors.

#spectrum

spectrum :: ColorScale

A spectrum of fully saturated hues (HSL color space).

#spectrumLCh

spectrumLCh :: ColorScale

A perceptually-uniform spectrum of all hues (LCh color space).

#blueToRed

blueToRed :: ColorScale

A perceptually-uniform, diverging color scale from blue to red, similar to the ColorBrewer scale 'RdBu'.

#yellowToRed

yellowToRed :: ColorScale

A perceptually-uniform, multi-hue color scale from yellow to red, similar to the ColorBrewer scale YlOrRd.

#cubehelix

cubehelix :: ColorScale

The standard cubehelix color scale.

#minColorStops

minColorStops :: Int -> (ColorStops -> Number -> Color) -> ColorStops -> ColorStops

Takes number of stops ColorStops should contain, function to generate missing colors and ColorStops itself.

#cssColorStops

cssColorStops :: ColorScale -> String

A CSS representation of the color scale in the form of a comma-separated list of color stops. This list can be used in a linear-gradient or a similar construct.

Note that CSS uses the RGB space for color interpolation. Consequently, if the color scale is in RGB mode, this is just a list of all defined color stops.

For other color spaces, the color scale is sampled at (at least) 10 different points. This should give a reasonable approximation to the true gradient in the specified color space.

#cssColorStopsRGB

cssColorStopsRGB :: ColorStops -> String

Underling function of cssColorStops.

Modules