chart-svg-0.6.0.0: Charting library targetting SVGs.
Safe HaskellSafe-Inferred
LanguageGHC2021

Data.Colour

Description

Colour representations and combinations.

Synopsis

Colour

data Colour Source #

Colour type for the library, wrapping Color.

Instances

Instances details
Generic Colour Source # 
Instance details

Defined in Data.Colour

Associated Types

type Rep Colour :: Type -> Type #

Methods

from :: Colour -> Rep Colour x #

to :: Rep Colour x -> Colour #

Show Colour Source # 
Instance details

Defined in Data.Colour

Eq Colour Source # 
Instance details

Defined in Data.Colour

Methods

(==) :: Colour -> Colour -> Bool #

(/=) :: Colour -> Colour -> Bool #

Uniform Colour Source # 
Instance details

Defined in Data.Colour

Methods

uniformM :: StatefulGen g m => g -> m Colour #

type Rep Colour Source # 
Instance details

Defined in Data.Colour

type Rep Colour = D1 ('MetaData "Colour" "Data.Colour" "chart-svg-0.6.0.0-HjsGv1l8hv76XDZORokPY6" 'True) (C1 ('MetaCons "Colour'" 'PrefixI 'True) (S1 ('MetaSel ('Just "color'") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Color (Alpha RGB) Double))))

pattern Colour :: Double -> Double -> Double -> Double -> Colour Source #

Constructor pattern.

Colour red green blue alpha

validColour :: Colour -> Bool Source #

Is Colour in-gamut?

>>> validColour (Colour 1 1 1.01 1)
False

validate :: Colour -> Maybe Colour Source #

Validate that the Colout is in-gamut.

>>> validate (Colour 1 1 1.01 1)
Nothing

trimColour :: Colour -> Colour Source #

Trim colour back to gamut.

>>> trimColour (Colour 1 1 1.01 1)
Colour 1.00 1.00 1.00 1.00

showRGBA :: Colour -> ByteString Source #

CSS-style representation

showRGB :: Colour -> ByteString Source #

CSS-style representation

showOpacity :: Colour -> ByteString Source #

CSS-style representation

opac' :: Lens' Colour Double Source #

lens for opacity (or alpha channel)

opac :: Colour -> Double Source #

Opacity or alpha

hex :: Colour -> Text Source #

Convert to CSS hex representation.

rgb :: Colour -> Colour -> Colour Source #

Sets RGB color but not opacity

toHex :: Colour -> Text Source #

Convert from Colour to CSS hex (#xxxxxx)

fromHex :: Text -> Either Text (Color RGB Double) Source #

Convert CSS hex to Colour

unsafeFromHex :: Text -> Color RGB Double Source #

Convert CSS hex to Colour, unsafely.

Palette colours

palette :: Int -> Colour Source #

Select a Colour from the palette

>>> palette 0
Colour 0.02 0.73 0.80 1.00

paletteO :: Int -> Double -> Colour Source #

Select a Colour from the palette with a specified opacity

>>> paletteO 0 0.5
Colour 0.02 0.73 0.80 0.50

transparent :: Colour Source #

Zero-opacity black

>>> transparent
Colour 0.00 0.00 0.00 0.00

black :: Colour Source #

black

>>> black
Colour 0.00 0.00 0.00 1.00

white :: Colour Source #

white

>>> white
Colour 0.99 0.99 0.99 1.00

light :: Colour Source #

light

For lighter huds against a dark background ...

colourHudOptions light defaultHudOptions
>>> light
Colour 0.94 0.94 0.94 1.00

dark :: Colour Source #

dark

dark is hardcoded in most of the default options.

>>> dark
Colour 0.05 0.05 0.05 1.00

grey :: Double -> Double -> Colour Source #

Grey(scale) colour inputting lightness and opacity.

>>> grey 0.5 0.4
Colour 0.50 0.50 0.50 0.40

LCH model

newtype LCH a Source #

LCH colour representation

oklab is a colour space being written into CSS specifications, that attempts to be ok at human-consistent colour representation. See:

The type is represented by three elements:

L: Lightness ranging from 0 (LCH 0 _ _ is black) to 1 (LCH 1 _ _ is white)

C: Chromacity, which ranges from 0 to around 0.32 or so.

H: Hue, which ranges from 0 to 360

Constructors

LCH' 

Fields

Instances

Instances details
Functor LCH Source # 
Instance details

Defined in Data.Colour

Methods

fmap :: (a -> b) -> LCH a -> LCH b #

(<$) :: a -> LCH b -> LCH a #

IsList (LCH a) Source # 
Instance details

Defined in Data.Colour

Associated Types

type Item (LCH a) #

Methods

fromList :: [Item (LCH a)] -> LCH a #

fromListN :: Int -> [Item (LCH a)] -> LCH a #

toList :: LCH a -> [Item (LCH a)] #

Show a => Show (LCH a) Source # 
Instance details

Defined in Data.Colour

Methods

showsPrec :: Int -> LCH a -> ShowS #

show :: LCH a -> String #

showList :: [LCH a] -> ShowS #

Eq a => Eq (LCH a) Source # 
Instance details

Defined in Data.Colour

Methods

(==) :: LCH a -> LCH a -> Bool #

(/=) :: LCH a -> LCH a -> Bool #

type Item (LCH a) Source # 
Instance details

Defined in Data.Colour

type Item (LCH a) = Item (Array '[3] a)

pattern LCH :: a -> a -> a -> LCH a Source #

LCH colour pattern

lLCH' :: Lens' (LCH Double) Double Source #

Lightness lens for LCH

cLCH' :: Lens' (LCH Double) Double Source #

Chromacity lens for LCH

hLCH' :: Lens' (LCH Double) Double Source #

Hue lens for LCH

data LCHA Source #

LCHA representation, including an alpha channel.

Constructors

LCHA' 

Fields

Instances

Instances details
Show LCHA Source # 
Instance details

Defined in Data.Colour

Methods

showsPrec :: Int -> LCHA -> ShowS #

show :: LCHA -> String #

showList :: [LCHA] -> ShowS #

Eq LCHA Source # 
Instance details

Defined in Data.Colour

Methods

(==) :: LCHA -> LCHA -> Bool #

(/=) :: LCHA -> LCHA -> Bool #

pattern LCHA :: Double -> Double -> Double -> Double -> LCHA Source #

LCHA pattern

lch' :: Lens' LCHA (LCH Double) Source #

LCH lens for LCHA

alpha' :: Lens' LCHA Double Source #

Alpha lens for LCHA

newtype RGB3 a Source #

A type to represent the RGB triple, useful as an intermediary between Colour and LCHA

Constructors

RGB3' 

Fields

Instances

Instances details
Functor RGB3 Source # 
Instance details

Defined in Data.Colour

Methods

fmap :: (a -> b) -> RGB3 a -> RGB3 b #

(<$) :: a -> RGB3 b -> RGB3 a #

IsList (RGB3 a) Source # 
Instance details

Defined in Data.Colour

Associated Types

type Item (RGB3 a) #

Methods

fromList :: [Item (RGB3 a)] -> RGB3 a #

fromListN :: Int -> [Item (RGB3 a)] -> RGB3 a #

toList :: RGB3 a -> [Item (RGB3 a)] #

Show a => Show (RGB3 a) Source # 
Instance details

Defined in Data.Colour

Methods

showsPrec :: Int -> RGB3 a -> ShowS #

show :: RGB3 a -> String #

showList :: [RGB3 a] -> ShowS #

Eq a => Eq (RGB3 a) Source # 
Instance details

Defined in Data.Colour

Methods

(==) :: RGB3 a -> RGB3 a -> Bool #

(/=) :: RGB3 a -> RGB3 a -> Bool #

Uniform (RGB3 Double) Source # 
Instance details

Defined in Data.Colour

Methods

uniformM :: StatefulGen g m => g -> m (RGB3 Double) #

type Item (RGB3 a) Source # 
Instance details

Defined in Data.Colour

type Item (RGB3 a) = Item (Array '[3] a)

pattern RGB3 :: a -> a -> a -> RGB3 a Source #

The RGB3 pattern

rgbd' :: Iso' (RGB3 Double) (RGB3 Word8) Source #

Lens for conversion between Double and Word8 RGB triples.

rgb32colour' :: Iso' (RGB3 Double, Double) Colour Source #

Lens for conversion between an (RGB3, alpha) pair and Colour

newtype LAB a Source #

LAB colour representation. a is green-red and b is blue-yellow

Constructors

LAB' 

Fields

Instances

Instances details
Functor LAB Source # 
Instance details

Defined in Data.Colour

Methods

fmap :: (a -> b) -> LAB a -> LAB b #

(<$) :: a -> LAB b -> LAB a #

IsList (LAB a) Source # 
Instance details

Defined in Data.Colour

Associated Types

type Item (LAB a) #

Methods

fromList :: [Item (LAB a)] -> LAB a #

fromListN :: Int -> [Item (LAB a)] -> LAB a #

toList :: LAB a -> [Item (LAB a)] #

Show a => Show (LAB a) Source # 
Instance details

Defined in Data.Colour

Methods

showsPrec :: Int -> LAB a -> ShowS #

show :: LAB a -> String #

showList :: [LAB a] -> ShowS #

Eq a => Eq (LAB a) Source # 
Instance details

Defined in Data.Colour

Methods

(==) :: LAB a -> LAB a -> Bool #

(/=) :: LAB a -> LAB a -> Bool #

type Item (LAB a) Source # 
Instance details

Defined in Data.Colour

type Item (LAB a) = Item (Array '[3] a)

pattern LAB :: a -> a -> a -> LAB a Source #

LAB pattern

lcha2colour' :: Iso' LCHA Colour Source #

LCHA to Colour lens

>>> c0 = Colour 0.78 0.36 0.02 1.00
>>> view (re lcha2colour') c0
LCHA' {_lch = LCH' {lchArray = [0.5969891006896103, 0.15793931531669247, 49.191113810479784]}, _alpha = 1.0}
>>> view (re lcha2colour' % lcha2colour') c0
Colour 0.78 0.36 0.02 1.00
>>> c1 = Colour 0.49 0.14 0.16 1
>>> view (re lcha2colour') c1
LCHA' {_lch = LCH' {lchArray = [0.40115567099848914, 0.12279066817938503, 21.51476756026837]}, _alpha = 1.0}
>>> view (re lcha2colour' % lcha2colour') c1
Colour 0.49 0.14 0.16 1.00

xy2ch' :: Iso' (Double, Double) (Double, Double) Source #

Lens between generic XY color representations and CH ones, which are polar versions of the XY.

mixins

mix :: Double -> Colour -> Colour -> Colour Source #

Mix 2 colours, using the oklch model.

This may not always be what you expect. One example is mixing black and another colour:

>>> mix 0.8 (Colour 0 0 0 1) (Colour 0.2 0.6 0.8 0.5)
Colour -0.09 0.48 0.45 0.60

The mix has gone out of gamut because we are swishing through hue mixes.

In this case, settting the hue on the black colour within the LCH contruct helps:

>>> betterblack = set (lch' % hLCH') (view hue' (Colour 0.2 0.6 0.8 0.5)) (review lcha2colour' black)
>>> view lcha2colour' $ mixLCHA 0.8 betterblack (review lcha2colour' $ Colour 0.2 0.6 0.8 0.5)
Colour 0.14 0.44 0.59 0.60

mixTrim :: Double -> Colour -> Colour -> Colour Source #

Mix 2 colours, using the oklch model, trimming the reult back to in-gamut.

>>> mixTrim 0.8 (Colour 0 0 0 1) (Colour 0.2 0.6 0.8 0.5)
Colour 0.00 0.48 0.45 0.60

mixLCHA :: Double -> LCHA -> LCHA -> LCHA Source #

Mix two LCHA specified colours.

mixes :: Double -> [Colour] -> Colour Source #

Interpolate across a list of Colours, with input being in Range 0 1

>>> mixes 0 [black, (Colour 0.2 0.6 0.8 0.5), white]
Colour 0.00 0.00 0.00 1.00
>>> mixes 1 [black, (Colour 0.2 0.6 0.8 0.5), white]
Colour 0.99 0.99 0.99 1.00
>>> mixes 0.6 [black, (Colour 0.2 0.6 0.8 0.5), white]
Colour 0.42 0.67 0.86 0.60

greyed :: Colour -> Colour Source #

Convert a colour to grayscale with the same lightness.

>>> greyed (Colour 0.4 0.7 0.8 0.4)
Colour 0.65 0.65 0.65 0.40

lightness' :: Lens' Colour Double Source #

Lightness lens

>>> over lightness' (*0.8) (Colour 0.4 0.7 0.8 0.4)
Colour 0.22 0.52 0.62 0.40

chroma' :: Lens' Colour Double Source #

Chromacity lens

>>> over chroma' (*0.8) (Colour 0.4 0.7 0.8 0.4)
Colour 0.46 0.69 0.77 0.40

hue' :: Lens' Colour Double Source #

Hue lens

>>> over hue' (+180) (Colour 0.4 0.7 0.8 0.4)
Colour 0.83 0.58 0.49 0.40

showSwatch :: Text -> Colour -> Text Source #

Html element to display colours

>>> showSwatch "swatch" dark
"<div class=swatch style=\"background:rgba(5%, 5%, 5%, 1.00);\">swatch</div>"

showSwatches :: Text -> Text -> [(Text, Colour)] -> Text Source #

Show multiple colors with embedded text.

rvRGB3 :: [RGB3 Double] Source #

Random list of RGB3s

rvColour :: [Colour] Source #

Random list of Colours

paletteR :: [Colour] Source #

Random Colours with an opacity of 1 that are not too extreme in terms of lightness or chromacity.