module Graphics.Gnuplot.Private.FrameOptionSet where
import qualified Graphics.Gnuplot.Private.FrameOption as Option
import Graphics.Gnuplot.Utility (formatBool, )
import qualified Data.Map as Map
import Data.Maybe.HT (toMaybe, )
import Data.Maybe (mapMaybe, )
type Plain = Map.Map Option.T [String]
newtype T graph =
Cons {decons :: Plain}
deflt :: Plain
deflt =
Map.fromList $
(Option.keyShow, []) :
(Option.sizeRatio, ["noratio"]) :
(Option.xLabelText, []) :
(Option.yLabelText, []) :
(Option.zLabelText, []) :
(Option.xRangeBounds, ["[*:*]"]) :
(Option.yRangeBounds, ["[*:*]"]) :
(Option.zRangeBounds, ["[*:*]"]) :
(Option.xFormat, []) :
(Option.yFormat, []) :
(Option.zFormat, []) :
(Option.xTickLabels, []) :
(Option.yTickLabels, []) :
(Option.zTickLabels, []) :
(Option.gridXTicks, ["noxtics"]) :
(Option.gridYTicks, ["noytics"]) :
(Option.gridZTicks, ["noztics"]) :
(Option.styleFillSolid, ["0"]) :
(Option.styleFillBorder, []) :
(Option.styleHistogram, ["clustered"]) :
(Option.boxwidth, []) :
[]
initial :: Plain
initial =
flip Map.union deflt $
Map.fromList $
(Option.xData, []) :
(Option.yData, []) :
(Option.zData, []) :
[]
add :: Option.T -> [String] -> T graph -> T graph
add opt args (Cons m) =
Cons (Map.insert opt args m)
remove :: Option.T -> T graph -> T graph
remove opt (Cons m) =
Cons (Map.delete opt m)
diffToString :: Plain -> Plain -> [String]
diffToString m0 m1 =
mapMaybe
(\(Option.Cons opt _, (old,new)) ->
toMaybe (old/=new) $
maybe
("unset " ++ opt)
(\args -> "set " ++ opt ++ concatMap (' ':) args)
new) $
Map.toList $
Map.unionWith
(\(old,_) (_,new) -> (old,new))
(fmap (\x -> (Just x, Nothing)) m0)
(fmap (\x -> (Nothing, Just x)) m1)
boolean :: Option.T -> Bool -> T graph -> T graph
boolean opt on =
if on
then add opt []
else remove opt
addBool :: Option.T -> Bool -> T graph -> T graph
addBool opt@(Option.Cons _ state) arg =
add opt [formatBool state arg]