module Graphics.Gnuplot.Private.LineSpecification where

import qualified Graphics.Gnuplot.Private.ColorSpecification as Color
import Data.Maybe (catMaybes, )
import Graphics.Gnuplot.Utility (quote, )


{-
The Int types would be better enumerations
but their interpretations depend on the gnuplot output type. :-(
-}

data T =
   Cons
      { T -> Maybe Int
lineStyle_ :: Maybe Int
      , T -> Maybe Int
lineType_  :: Maybe Int
      , T -> Maybe Double
lineWidth_ :: Maybe Double
      , T -> Maybe T
lineColor_ :: Maybe Color.T
      , T -> Maybe Int
pointType_ :: Maybe Int
      , T -> Maybe Double
pointSize_ :: Maybe Double
      , T -> Maybe String
title_     :: Maybe String
      }

deflt :: T
deflt :: T
deflt =
   Cons :: Maybe Int
-> Maybe Int
-> Maybe Double
-> Maybe T
-> Maybe Int
-> Maybe Double
-> Maybe String
-> T
Cons
      { lineStyle_ :: Maybe Int
lineStyle_ = Maybe Int
forall a. Maybe a
Nothing
      , lineType_ :: Maybe Int
lineType_  = Maybe Int
forall a. Maybe a
Nothing
      , lineWidth_ :: Maybe Double
lineWidth_ = Maybe Double
forall a. Maybe a
Nothing
      , lineColor_ :: Maybe T
lineColor_ = Maybe T
forall a. Maybe a
Nothing
      , pointType_ :: Maybe Int
pointType_ = Maybe Int
forall a. Maybe a
Nothing
      , pointSize_ :: Maybe Double
pointSize_ = Maybe Double
forall a. Maybe a
Nothing
      , title_ :: Maybe String
title_     = Maybe String
forall a. Maybe a
Nothing
      }

lineStyle :: Int -> T -> T
lineStyle :: Int -> T -> T
lineStyle Int
x T
ls = T
ls{lineStyle_ :: Maybe Int
lineStyle_ = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
x}

lineType :: Int -> T -> T
lineType :: Int -> T -> T
lineType Int
x T
ls = T
ls{lineType_ :: Maybe Int
lineType_ = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
x}

lineWidth :: Double -> T -> T
lineWidth :: Double -> T -> T
lineWidth Double
x T
ls = T
ls{lineWidth_ :: Maybe Double
lineWidth_ = Double -> Maybe Double
forall a. a -> Maybe a
Just Double
x}

lineColor :: Color.T -> T -> T
lineColor :: T -> T -> T
lineColor T
x T
ls = T
ls{lineColor_ :: Maybe T
lineColor_ = T -> Maybe T
forall a. a -> Maybe a
Just T
x}

pointType :: Int -> T -> T
pointType :: Int -> T -> T
pointType Int
x T
ls = T
ls{pointType_ :: Maybe Int
pointType_ = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
x}

pointSize :: Double -> T -> T
pointSize :: Double -> T -> T
pointSize Double
x T
ls = T
ls{pointSize_ :: Maybe Double
pointSize_ = Double -> Maybe Double
forall a. a -> Maybe a
Just Double
x}

title :: String -> T -> T
title :: String -> T -> T
title String
x T
ls = T
ls{title_ :: Maybe String
title_ = String -> Maybe String
forall a. a -> Maybe a
Just String
x}


toString :: T -> String
toString :: T -> String
toString T
linespec =
   let showField :: String -> (a -> String) -> (T -> Maybe a) -> Maybe [String]
       showField :: String -> (a -> String) -> (T -> Maybe a) -> Maybe [String]
showField String
s a -> String
f T -> Maybe a
access = (a -> [String]) -> Maybe a -> Maybe [String]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\a
a -> [String
s, a -> String
f a
a]) (Maybe a -> Maybe [String]) -> Maybe a -> Maybe [String]
forall a b. (a -> b) -> a -> b
$ T -> Maybe a
access T
linespec
   in  [String] -> String
unwords ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$ [[String]] -> [String]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[String]] -> [String]) -> [[String]] -> [String]
forall a b. (a -> b) -> a -> b
$ [Maybe [String]] -> [[String]]
forall a. [Maybe a] -> [a]
catMaybes ([Maybe [String]] -> [[String]]) -> [Maybe [String]] -> [[String]]
forall a b. (a -> b) -> a -> b
$
       String -> (Int -> String) -> (T -> Maybe Int) -> Maybe [String]
forall a.
String -> (a -> String) -> (T -> Maybe a) -> Maybe [String]
showField String
"linestyle" Int -> String
forall a. Show a => a -> String
show  T -> Maybe Int
lineStyle_ Maybe [String] -> [Maybe [String]] -> [Maybe [String]]
forall a. a -> [a] -> [a]
:
       String -> (Int -> String) -> (T -> Maybe Int) -> Maybe [String]
forall a.
String -> (a -> String) -> (T -> Maybe a) -> Maybe [String]
showField String
"linetype"  Int -> String
forall a. Show a => a -> String
show  T -> Maybe Int
lineType_  Maybe [String] -> [Maybe [String]] -> [Maybe [String]]
forall a. a -> [a] -> [a]
:
       String
-> (Double -> String) -> (T -> Maybe Double) -> Maybe [String]
forall a.
String -> (a -> String) -> (T -> Maybe a) -> Maybe [String]
showField String
"linewidth" Double -> String
forall a. Show a => a -> String
show  T -> Maybe Double
lineWidth_ Maybe [String] -> [Maybe [String]] -> [Maybe [String]]
forall a. a -> [a] -> [a]
:
       String -> (T -> String) -> (T -> Maybe T) -> Maybe [String]
forall a.
String -> (a -> String) -> (T -> Maybe a) -> Maybe [String]
showField String
"linecolor" T -> String
Color.toString T -> Maybe T
lineColor_ Maybe [String] -> [Maybe [String]] -> [Maybe [String]]
forall a. a -> [a] -> [a]
:
       String -> (Int -> String) -> (T -> Maybe Int) -> Maybe [String]
forall a.
String -> (a -> String) -> (T -> Maybe a) -> Maybe [String]
showField String
"pointtype" Int -> String
forall a. Show a => a -> String
show  T -> Maybe Int
pointType_ Maybe [String] -> [Maybe [String]] -> [Maybe [String]]
forall a. a -> [a] -> [a]
:
       String
-> (Double -> String) -> (T -> Maybe Double) -> Maybe [String]
forall a.
String -> (a -> String) -> (T -> Maybe a) -> Maybe [String]
showField String
"pointsize" Double -> String
forall a. Show a => a -> String
show  T -> Maybe Double
pointSize_ Maybe [String] -> [Maybe [String]] -> [Maybe [String]]
forall a. a -> [a] -> [a]
:
       String
-> (String -> String) -> (T -> Maybe String) -> Maybe [String]
forall a.
String -> (a -> String) -> (T -> Maybe a) -> Maybe [String]
showField String
"title"     String -> String
quote T -> Maybe String
title_     Maybe [String] -> [Maybe [String]] -> [Maybe [String]]
forall a. a -> [a] -> [a]
:
       []