newmana/chroma-elm/18.1.0

NOTE: the latest version is 18.2.1

Chroma.Chroma

The attempt here is to provide something similar to Chroma.js but also has more features and is idiomatic Elm.

Color

chroma : String -> Result String ExtColor

Given a valid hex string (8, 6 or 3) or W3CX11 Color name and produce an RGB Color.

Chroma.chroma "magenta"
--> Ok (RGBAColor (RgbaSpace 1 0 1 1)) : Result String Types.ExtColor


Chroma.chroma "#c0c0c0"
--> Ok (RGBAColor (RgbaSpace 0.7529411764705882 0.7529411764705882 0.7529411764705882 1)) : Result String Types.ExtColor
name : ExtColor -> Result String String

Given a color turn it into a W3CX11 Color name or fall back to an RGB string.

Types.RGBAColor (Color.rgb255 255 0 255) |> Chroma.name
--> Ok "magenta" : Result String String
mix : Mode -> Float -> ExtColor -> ExtColor -> ExtColor

Mix two colors, first converting them to the same color space and then interpolate them with the given ratio.

Chroma.mix Types.RGBA 0.25 (Types.RGBAColor W3CX11.red) (Types.RGBAColor W3CX11.blue)
--> RGBAColor (RgbaSpace 0.75 0 0.25 1) : Types.ExtColor
mixChroma : Mode -> Float -> String -> String -> Result String ExtColor

Mix two colors defined as a string, first converting them to the same color space mode and then interpolate with the given ratio.

Chroma.mixChroma Types.RGBA 0.25 "red" "blue"
--> Ok (RGBAColor (RgbaSpace 0.75 0 0.25 1)) : Result String Types.ExtColor
average : Mode -> Nonempty ExtColor -> Result String ExtColor

Find the average of a non-empty list of colors, first converting them to the same color space.

Only supports RGBA, CYMK and LAB.

Chroma.average Types.RGBA (Nonempty.Nonempty (Types.RGBAColor W3CX11.red) [(Types.RGBAColor W3CX11.blue)])
--> Ok (RGBAColor (RgbaSpace 0.5 0 0.5 1)) : Result String Types.ExtColor
averageChroma : Mode -> Nonempty String -> Result String ExtColor

Find the average of a non-empty list of colors defined as strings, first converting them to the same color space.

Only supports RGBA, CYMK and LAB.

Chroma.averageChroma Types.RGBA (Nonempty.Nonempty "red" ["blue"])
--> Ok (RGBAColor (RgbaSpace 0.5 0 0.5 1)) : Result String Types.ExtColor

Combine two colors using the given blend modes.

Chroma.blend Blend.Burn (Types.RGBAColor W3CX11.red) (Types.RGBAColor W3CX11.blue)
--> RGBAColor (RgbaSpace 0 0 1 1) : Types.ExtColor
blendChroma : BlendMode -> String -> String -> Result String ExtColor

Combine two colors, defined as strings, using the given blend modes.

Chroma.blendChroma Blend.Darken "cyan" "magenta"
--> Ok (RGBAColor (RgbaSpace 0 0 1 1)) : Result String Types.ExtColor
contrast : ExtColor -> ExtColor -> Float

WCGA contrast ratio between two colors.

Chroma.contrast (Types.RGBAColor W3CX11.pink) (Types.RGBAColor W3CX11.hotpink)
--> 1.7214765344592284 : Float
contrastChroma : String -> String -> Result String Float

WCGA contrast ratio between two colors.

Chroma.contrastChroma "pink" "hotpink"
--> Ok 1.7214765344592284 : Result String Float
distance : Mode -> ExtColor -> ExtColor -> Float

Calculate the distance for a given color space.

Chroma.distance Types.RGBA (Types.RGBAColor W3CX11.red) (Types.RGBAColor W3CX11.blue)
--> 1.4142135623730951 : Float

Calculate the distance in RGB 255 color space.

Chroma.distance255 (Types.RGBAColor W3CX11.red) (Types.RGBAColor W3CX11.blue)
--> 360.62445840513925 : Float
limits : LimitMode -> Int -> Nonempty Float -> Nonempty Float

Create breaks/classes based on the data given.

Supports: CkMeans (a variant of kmeans), Equal, Head/Tail, Jenks, Logarithmic, and Quantile.

Chroma.limits Limits.Equal 5 (Nonempty.Nonempty 0 [ 10 ])
--> Nonempty 0 [2,4,6,8,10] : Nonempty.Nonempty Float


Chroma.limits Limits.CkMeans 3 (Nonempty.Nonempty 1 [ 2, 1, 4, 3, 5, 2, 5, 4 ])
--> Nonempty 1 [2,4] : Nonempty.Nonempty Float

Color Scales

scale : Nonempty ExtColor -> ( Data, Float -> ExtColor )

Return a configuration and a function from a float to a color based on default values and a list of colors.

scaleF : (Float -> ExtColor) -> ( Data, Float -> ExtColor )

Return a configuration and a function from a float to a color based on default values and a function given a value from 0 -> 1 produces a new color.

colors : Int -> Nonempty ExtColor -> ( Data, Nonempty ExtColor )

Return a configuration and a list of colors based on the number of equal distance buckets to create and a list of colors.

colorsF : Int -> (Float -> ExtColor) -> ( Data, Nonempty ExtColor )

Return a configuration and a list of colors based on the number of equal distance buckets to create and a function given a value from 0 -> 1 produces a new color.

domain : Nonempty Float -> Nonempty ExtColor -> ( Data, Float -> ExtColor )

Return a new configuration and a function from a float to a color based on a new domain and list of colors. The list of colors must be the same length as the domain or only the first and last values will be used.

domainF : Nonempty Float -> (Float -> ExtColor) -> ( Data, Float -> ExtColor )

Return a new configuration and a function from a float to a color based on a new domain and a function given a value from 0 -> 1 produces a new color.

classes : Int -> Data -> ( Data, Float -> ExtColor )

Return a new configuration and a function from a float to a color using the default configuration, the given colors and the total number of colors (bins) to return.

padding : Float -> Nonempty ExtColor -> ( Data, Float -> ExtColor )

Remove a fraction of the color gradient (0 -> 1). Applies to both sides equally.

paddingBoth : ( Float, Float ) -> Nonempty ExtColor -> ( Data, Float -> ExtColor )

Remove a fraction of the color gradient (0 -> 1).

Color Scales Helpers

scaleDefault : ( Data, Float -> ExtColor )

Return a configuration and a function from a float to a color based on the default values - colors White to Black, domain 0 - 1.

scaleWith : Data -> ( Data, Float -> ExtColor )

Return a new configuration and a function from a float to a color based on the given configuration values and the given colors.

colorsWith : Data -> Int -> ( Data, Nonempty ExtColor )

Return the data with the given colors and a new list of colors.

domainWith : Data -> Nonempty Float -> ( Data, Float -> ExtColor )

Return a new configuration and a function from a float to a color based on an existing configuration and a new domain. If using a list of colors, they must be the same length as the domain or only the first and last values will be used.

classesWithArray : Nonempty Float -> Data -> ( Data, Float -> ExtColor )

Return a new configuration and a function from a float to a color based on the given configuration values, the given colors and a predefined set of breaks/classes.

paddingWith : Data -> Float -> ( Data, Float -> ExtColor )

Remove a fraction of the color gradient (0 -> 1). Applies both sides equally.

paddingBothWith : Data -> ( Float, Float ) -> ( Data, Float -> ExtColor )

Remove a fraction of the color gradient (0 -> 1).