module Graphics.Gnuplot.Private.ColorSpecification where

import Graphics.Gnuplot.Utility (quote, )
import Data.List.HT (padLeft, )
import Data.Word (Word8, )
import Numeric (showHex, )


data T =
     Name String
   | RGB8 {T -> Word8
red, T -> Word8
green, T -> Word8
blue :: Word8}
   | PaletteFrac Double


toString :: T -> String
toString :: T -> String
toString T
c =
   case T
c of
      Name String
name -> String
"rgbcolor " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
quote String
name
      RGB8 Word8
r Word8
g Word8
b ->
         String
"rgbcolor #" String -> String -> String
forall a. [a] -> [a] -> [a]
++
         (Word8 -> String) -> [Word8] -> String
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Char -> Int -> String -> String
forall a. a -> Int -> [a] -> [a]
padLeft Char
'0' Int
2 (String -> String) -> (Word8 -> String) -> Word8 -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Word8 -> String -> String) -> String -> Word8 -> String
forall a b c. (a -> b -> c) -> b -> a -> c
flip Word8 -> String -> String
forall a. (Integral a, Show a) => a -> String -> String
showHex String
"") [Word8
r,Word8
g,Word8
b]
      PaletteFrac Double
frac -> String
"palette frac " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Double -> String
forall a. Show a => a -> String
show Double
frac