newmana / chroma-elm / 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 Chroma.Types.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 : Chroma.Types.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 : Chroma.Types.Mode -> Basics.Float -> Chroma.Types.ExtColor -> Chroma.Types.ExtColor -> Chroma.Types.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 : Chroma.Types.Mode -> Basics.Float -> String -> String -> Result String Chroma.Types.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 : Chroma.Types.Mode -> List.Nonempty.Nonempty Chroma.Types.ExtColor -> Result String Chroma.Types.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 : Chroma.Types.Mode -> List.Nonempty.Nonempty String -> Result String Chroma.Types.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

blend : Chroma.Blend.BlendMode -> Chroma.Types.ExtColor -> Chroma.Types.ExtColor -> Chroma.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 : Chroma.Blend.BlendMode -> String -> String -> Result String Chroma.Types.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 : Chroma.Types.ExtColor -> Chroma.Types.ExtColor -> Basics.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 Basics.Float

WCGA contrast ratio between two colors.

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

distance : Chroma.Types.Mode -> Chroma.Types.ExtColor -> Chroma.Types.ExtColor -> Basics.Float

Calculate the distance for a given color space.

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

distance255 : Chroma.Types.ExtColor -> Chroma.Types.ExtColor -> Basics.Float

Calculate the distance in RGB 255 color space.

Chroma.distance255 (Types.RGBAColor W3CX11.red) (Types.RGBAColor W3CX11.blue)
--> 360.62445840513925 : Float

limits : Chroma.Limits.Limits.LimitMode -> Basics.Int -> List.Nonempty.Nonempty Basics.Float -> List.Nonempty.Nonempty Basics.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 : List.Nonempty.Nonempty Chroma.Types.ExtColor -> ( Chroma.Scale.Data, Basics.Float -> Chroma.Types.ExtColor )

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

scaleF : (Basics.Float -> Chroma.Types.ExtColor) -> ( Chroma.Scale.Data, Basics.Float -> Chroma.Types.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 : Basics.Int -> List.Nonempty.Nonempty Chroma.Types.ExtColor -> ( Chroma.Scale.Data, List.Nonempty.Nonempty Chroma.Types.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 : Basics.Int -> (Basics.Float -> Chroma.Types.ExtColor) -> ( Chroma.Scale.Data, List.Nonempty.Nonempty Chroma.Types.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 : List.Nonempty.Nonempty Basics.Float -> List.Nonempty.Nonempty Chroma.Types.ExtColor -> ( Chroma.Scale.Data, Basics.Float -> Chroma.Types.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 : List.Nonempty.Nonempty Basics.Float -> (Basics.Float -> Chroma.Types.ExtColor) -> ( Chroma.Scale.Data, Basics.Float -> Chroma.Types.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 : Basics.Int -> Chroma.Scale.Data -> ( Chroma.Scale.Data, Basics.Float -> Chroma.Types.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 : Basics.Float -> List.Nonempty.Nonempty Chroma.Types.ExtColor -> ( Chroma.Scale.Data, Basics.Float -> Chroma.Types.ExtColor )

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

paddingBoth : ( Basics.Float, Basics.Float ) -> List.Nonempty.Nonempty Chroma.Types.ExtColor -> ( Chroma.Scale.Data, Basics.Float -> Chroma.Types.ExtColor )

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

Color Scales Helpers

scaleDefault : ( Chroma.Scale.Data, Basics.Float -> Chroma.Types.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 : Chroma.Scale.Data -> ( Chroma.Scale.Data, Basics.Float -> Chroma.Types.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 : Chroma.Scale.Data -> Basics.Int -> ( Chroma.Scale.Data, List.Nonempty.Nonempty Chroma.Types.ExtColor )

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

domainWith : Chroma.Scale.Data -> List.Nonempty.Nonempty Basics.Float -> ( Chroma.Scale.Data, Basics.Float -> Chroma.Types.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 : List.Nonempty.Nonempty Basics.Float -> Chroma.Scale.Data -> ( Chroma.Scale.Data, Basics.Float -> Chroma.Types.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 : Chroma.Scale.Data -> Basics.Float -> ( Chroma.Scale.Data, Basics.Float -> Chroma.Types.ExtColor )

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

paddingBothWith : Chroma.Scale.Data -> ( Basics.Float, Basics.Float ) -> ( Chroma.Scale.Data, Basics.Float -> Chroma.Types.ExtColor )

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