gnuplot 0.5.0.2 → 0.5.1
raw patch · 19 files changed
+182/−113 lines, 19 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Graphics.Gnuplot.Advanced: plotDefault :: C gfx => gfx -> IO ExitCode
+ Graphics.Gnuplot.Frame.OptionSet: grid :: C graph => Bool -> T graph -> T graph
+ Graphics.Gnuplot.Frame.OptionSet: gridXTicks :: C graph => Bool -> T graph -> T graph
+ Graphics.Gnuplot.Frame.OptionSet: gridYTicks :: C graph => Bool -> T graph -> T graph
+ Graphics.Gnuplot.Frame.OptionSet: gridZTicks :: (C x, C y, C z) => Bool -> T (T x y z) -> T (T x y z)
Files
- gnuplot.cabal +11/−11
- src/Demo.hs +19/−19
- src/Graphics/Gnuplot/Advanced.hs +23/−7
- src/Graphics/Gnuplot/Frame.hs +1/−4
- src/Graphics/Gnuplot/Frame/OptionSet.hs +27/−1
- src/Graphics/Gnuplot/MultiPlot.hs +4/−4
- src/Graphics/Gnuplot/Plot/ThreeDimensional.hs +2/−1
- src/Graphics/Gnuplot/Private/Display.hs +3/−0
- src/Graphics/Gnuplot/Private/Frame.hs +1/−7
- src/Graphics/Gnuplot/Private/FrameOption.hs +4/−0
- src/Graphics/Gnuplot/Private/FrameOptionSet.hs +3/−0
- src/Graphics/Gnuplot/Private/Graph3D.hs +15/−0
- src/Graphics/Gnuplot/Private/Plot.hs +24/−16
- src/Graphics/Gnuplot/Private/Terminal.hs +0/−5
- src/Graphics/Gnuplot/Simple.hs +37/−32
- src/Graphics/Gnuplot/Terminal/PNG.hs +1/−2
- src/Graphics/Gnuplot/Terminal/WXT.hs +1/−2
- src/Graphics/Gnuplot/Terminal/X11.hs +1/−2
- src/Graphics/Gnuplot/Utility.hs +5/−0
gnuplot.cabal view
@@ -1,5 +1,5 @@ Name: gnuplot-Version: 0.5.0.2+Version: 0.5.1 License: BSD3 License-File: LICENSE Author: Henning Thielemann <haskell@henning-thielemann.de>@@ -46,7 +46,7 @@ data/runtime.data Source-Repository this- Tag: 0.5.0.2+ Tag: 0.5.1 Type: darcs Location: http://code.haskell.org/gnuplot/ @@ -75,19 +75,19 @@ Library Build-Depends:- array >= 0.1 && <0.5,- containers >= 0.1 && <0.6,- utility-ht >= 0.0.1 && < 0.1,- monoid-transformer >= 0.0.2 && <0.1+ array >=0.1 && <0.5,+ containers >=0.1 && <0.6,+ utility-ht >=0.0.1 && <0.1,+ monoid-transformer >=0.0.2 && <0.1 If flag(splitBase) Build-Depends:- process >= 1.0 && < 1.2,- time >= 1.1 && < 1.5,- old-locale >= 1.0 && < 1.1,- base >= 2 && <5+ process >=1.0 && <1.2,+ time >=1.1 && <1.5,+ old-locale >=1.0 && <1.1,+ base >=2 && <5 Else Build-Depends:- base >= 1.0 && < 2+ base >=1.0 && <2 GHC-Options: -Wall
src/Demo.hs view
@@ -1,7 +1,6 @@ module Main where -import qualified Graphics.Gnuplot.Advanced as Plot-import qualified Graphics.Gnuplot.Terminal.X11 as X11+import qualified Graphics.Gnuplot.Advanced as GP import qualified Graphics.Gnuplot.MultiPlot as MultiPlot @@ -27,7 +26,8 @@ import System.FilePath ((</>), ) import Data.Array (listArray, )-import Data.Monoid (mappend, mconcat, )+import Data.Foldable (foldMap, )+import Data.Monoid (mappend, ) simple2d :: Plot2D.T Double Double@@ -71,8 +71,7 @@ [("220", 0), ("320", 1), ("420", 2), ("520", 3), ("620", 4), ("720", 5)] $ Opts.yRange2d (0,3000) $ Opts.deflt) $- mconcat $- map (\(title,dat) ->+ foldMap (\(title,dat) -> fmap (Graph2D.lineSpec (LineSpec.title title LineSpec.deflt)) $ Plot2D.list Graph2D.histograms dat) $ ("1.0011", [102, 213, 378, 408, 840, 920]) :@@ -89,8 +88,8 @@ Opts.xRange2d domain $ Opts.yRange2d (-1.5,1.5) $ Opts.deflt- in Frame.cons frameOpts $ mconcat $- map (\(name,f) ->+ in Frame.cons frameOpts $+ foldMap (\(name,f) -> fmap (Graph2D.lineSpec (LineSpec.title name $ LineSpec.deflt)) $@@ -150,7 +149,8 @@ wave3d = let meshNodes = linearScale 20 (-2,2) in Frame.cons- (Opts.xRange3d (-2.5,2.5) $+ (Opts.grid True $+ Opts.xRange3d (-2.5,2.5) $ Opts.yRange3d (-2.5,2.5) $ defltOpts) $ Plot3D.surface@@ -182,16 +182,16 @@ main :: IO () main = sequence_ $- Plot.plot X11.cons simple2d :- Plot.plot X11.cons list2d :- Plot.plot X11.cons candle2d :- Plot.plot X11.cons histogram2d :- Plot.plot X11.cons names2d :- Plot.plot X11.cons overlay2d :- (Plot.plot X11.cons . flip file2d "runtime.data"+ GP.plotDefault simple2d :+ GP.plotDefault list2d :+ GP.plotDefault candle2d :+ GP.plotDefault histogram2d :+ GP.plotDefault names2d :+ GP.plotDefault overlay2d :+ (GP.plotDefault . flip file2d "runtime.data" =<< fmap (</> "data") Path.getDataDir) :- Plot.plot X11.cons mixed2d :- Plot.plot X11.cons size2d :- Plot.plot X11.cons wave3d :- Plot.plot X11.cons multiplot :+ GP.plotDefault mixed2d :+ GP.plotDefault size2d :+ GP.plotDefault wave3d :+ GP.plotDefault multiplot : []
src/Graphics/Gnuplot/Advanced.hs view
@@ -71,6 +71,7 @@ -} module Graphics.Gnuplot.Advanced ( plot,+ plotDefault, ) where import qualified Graphics.Gnuplot.Private.FrameOptionSet as OptionSet@@ -78,11 +79,11 @@ import qualified Graphics.Gnuplot.Private.Terminal as Terminal import qualified Graphics.Gnuplot.Execute as Exec- import System.Exit (ExitCode, )-import Data.Monoid (Monoid, mempty, )+ import qualified Data.Monoid.State as State-import Data.List (intersperse, )+import Data.Monoid (Monoid, mempty, )+import Graphics.Gnuplot.Utility (semiColonConcat, ) -- * User front-end@@ -99,22 +100,37 @@ plot :: (Terminal.C terminal, Display.C gfx) => terminal -> gfx -> IO ExitCode-plot term gfx =+plot term =+ plotCore (formatTerminal term :)++{- |+Plot using the default gnuplot terminal.+-}+plotDefault ::+ (Display.C gfx) =>+ gfx -> IO ExitCode+plotDefault =+ plotCore id++plotCore ::+ (Display.C gfx) =>+ ([String] -> [String]) -> gfx -> IO ExitCode+plotCore term gfx = let body = State.evaluate (0, OptionSet.initial) $ Display.runScript $ Display.toScript gfx in do mapM_ Display.writeData (Display.files body) Exec.simple- (formatTerminal term : Display.commands body)- ["-persist"]+ (term $ Display.commands body)+ ["--persist"] formatTerminal :: (Terminal.C terminal) => terminal -> String formatTerminal term = let (Terminal.Cons options commands) = Terminal.canonical term- in concat $ intersperse "; " $+ in semiColonConcat $ ("set terminal " ++ unwords options) : commands
src/Graphics/Gnuplot/Frame.hs view
@@ -9,9 +9,7 @@ import qualified Graphics.Gnuplot.Private.GraphEmpty as Empty import qualified Graphics.Gnuplot.Private.Graph as Graph -import qualified Data.Monoid.State as State - cons :: OptionSet.T graph -> Plot.T graph -> Frame.T graph cons = Frame.Cons @@ -19,5 +17,4 @@ simple = cons OptionSet.deflt empty :: Frame.T Empty.T-empty =- simple (Plot.Cons (State.pure []))+empty = simple $ Plot.pure []
src/Graphics/Gnuplot/Frame/OptionSet.hs view
@@ -21,6 +21,10 @@ xTicks3d, yTicks3d, zTicks3d,+ grid,+ gridXTicks,+ gridYTicks,+ gridZTicks, xFormat, yFormat, zFormat,@@ -45,7 +49,7 @@ import Graphics.Gnuplot.Private.FrameOptionSet (T, ) -import Graphics.Gnuplot.Utility (quote, )+import Graphics.Gnuplot.Utility (quote, formatBool, ) import qualified Data.List as List @@ -214,6 +218,28 @@ showString " " . atomText pos) labels]+++grid :: Graph.C graph => Bool -> T graph -> T graph+grid b =+ gridTicks Option.gridXTicks b .+ gridTicks Option.gridYTicks b .+ gridTicks Option.gridZTicks b++gridXTicks :: Graph.C graph => Bool -> T graph -> T graph+gridXTicks = gridTicks Option.gridXTicks++gridYTicks :: Graph.C graph => Bool -> T graph -> T graph+gridYTicks = gridTicks Option.gridYTicks++gridZTicks ::+ (Atom.C x, Atom.C y, Atom.C z) =>+ Bool -> T (Graph3D.T x y z) -> T (Graph3D.T x y z)+gridZTicks = gridTicks Option.gridZTicks++gridTicks :: Graph.C graph => Option.T -> Bool -> T graph -> T graph+gridTicks opt@(Option.Cons _ name) b =+ OptionSet.add opt [formatBool name b] boxwidthRelative ::
src/Graphics/Gnuplot/MultiPlot.hs view
@@ -14,8 +14,8 @@ import qualified Graphics.Gnuplot.Private.Display as Display import qualified Graphics.Gnuplot.Private.Graph as Graph -import qualified Data.Monoid.State as State import Data.Monoid (mconcat, )+import Data.Foldable (foldMap, ) import Data.Array (Array, elems, bounds, ) import Data.Ix (Ix, rangeSize, )@@ -77,12 +77,12 @@ instance Display.C T where toScript mp = mconcat $- (Display.Script $ State.pure $+ (Display.pure $ Display.Body [] ["set multiplot layout " ++ show (numRows mp) ++ ", " ++ show (numColumns mp) ++- maybe "" ((" title " ++) . quote) (title_ mp)]) :+ foldMap ((" title " ++) . quote) (title_ mp)]) : (map scriptFromPart $ parts mp) ++- (Display.Script $ State.pure $+ (Display.pure $ Display.Body [] ["unset multiplot"]) : []
src/Graphics/Gnuplot/Plot/ThreeDimensional.hs view
@@ -23,7 +23,8 @@ {- |-Plots can be assembled using 'mappend' or 'mconcat'.+Plots can be assembled using 'mappend' or 'mconcat'+or several functions from "Data.Foldable". -} type T x y z = Plot.T (Graph.T x y z)
src/Graphics/Gnuplot/Private/Display.hs view
@@ -12,6 +12,9 @@ runScript :: State.T (Int, OptionSet) Body } +pure :: Body -> Script+pure = Script . State.pure+ data Body = Body { files :: [File],
src/Graphics/Gnuplot/Private/Frame.hs view
@@ -6,7 +6,6 @@ import qualified Graphics.Gnuplot.Private.Display as Display import qualified Graphics.Gnuplot.Private.Graph as Graph -import qualified Data.Monoid.State as State import Data.Monoid (Monoid, mappend, ) @@ -18,11 +17,6 @@ instance Graph.C graph => Display.C (T graph) where toScript frame =- (Display.Script $- State.Cons $ \(n, opts0) ->- let opts1 = OptionSet.decons $ option frame- in (Display.Body [] $- OptionSet.diffToString opts0 opts1,- (n, opts1)))+ (Plot.optionsToScript $ option frame) `mappend` (Plot.toScript $ plot frame)
src/Graphics/Gnuplot/Private/FrameOption.hs view
@@ -69,6 +69,10 @@ yTickLabels :: T; yTickLabels = yTicks "labels" zTickLabels :: T; zTickLabels = zTicks "labels" +gridXTicks :: T; gridXTicks = grid "xtics"+gridYTicks :: T; gridYTicks = grid "ytics"+gridZTicks :: T; gridZTicks = grid "ztics"+ boxwidth :: T; boxwidth = Cons "boxwidth" "" styleFillSolid :: T; styleFillSolid = Cons "style fill" "solid"
src/Graphics/Gnuplot/Private/FrameOptionSet.hs view
@@ -46,6 +46,9 @@ (Option.xTickLabels, []) : (Option.yTickLabels, []) : (Option.zTickLabels, []) :+ (Option.gridXTicks, ["noxtics"]) :+ (Option.gridYTicks, ["noytics"]) :+ (Option.gridZTicks, ["noztics"]) : (Option.styleFillSolid, ["0"]) : (Option.styleFillBorder, []) : (Option.styleHistogram, ["clustered"]) :
src/Graphics/Gnuplot/Private/Graph3D.hs view
@@ -71,5 +71,20 @@ typ :: Type -> T x y z -> T x y z typ t gr = gr{type_ = t} +{-+for 3D plots not all line attributes are supported like:+ pointsize+ pointtype++pm3d and impulses allow:+ linestyle+ linewidth+ linecolor+ linetype+ title++FIXME:+Do we need a separate LineSpec3D type or a type parameter for LineSpec?+-} lineSpec :: LineSpec.T -> T x y z -> T x y z lineSpec ls gr = gr{lineSpec_ = ls}
src/Graphics/Gnuplot/Private/Plot.hs view
@@ -1,21 +1,26 @@ module Graphics.Gnuplot.Private.Plot where -import qualified Data.Monoid.State as State-import Data.Monoid (Monoid, mempty, mappend, )- import qualified Graphics.Gnuplot.Private.Display as Display import qualified Graphics.Gnuplot.Private.FrameOptionSet as OptionSet import qualified Graphics.Gnuplot.Private.Graph as Graph import Graphics.Gnuplot.Utility (quote, commaConcat, ) +import qualified Data.Foldable as Fold+import qualified Data.Monoid.State as State+import Data.Monoid (Monoid, mempty, mappend, )+ import Data.Maybe (mapMaybe, ) {- |-Plots can be assembled using 'mappend' or 'mconcat'.+Plots can be assembled using 'mappend' or 'mconcat'+or several functions from "Data.Foldable". -} newtype T graph = Cons (State.T Int [File graph]) +pure :: [File graph] -> T graph+pure = Cons . State.pure+ {- Could also be implemented with Control.Monad.Trans.State: mappend = liftA2 mappend@@ -34,7 +39,7 @@ fromGraphs :: FilePath -> [graph] -> T graph fromGraphs name gs =- Cons (State.pure [File name Nothing gs])+ pure [File name Nothing gs] data File graph =@@ -46,7 +51,7 @@ writeData :: File graph -> IO () writeData (File fn cont _) =- maybe (return ()) (writeFile fn) cont+ Fold.mapM_ (writeFile fn) cont tmpFileStem :: FilePath@@ -88,18 +93,21 @@ [plotCmd p undefined ++ " " ++ commaConcat graphs], (n1, opts)) +optionsToScript :: Graph.C graph => OptionSet.T graph -> Display.Script+optionsToScript opts =+ Display.Script $+ State.Cons $ \(n, opts0) ->+ let opts1 = OptionSet.decons opts+ in (Display.Body [] $+ OptionSet.diffToString opts0 opts1,+ (n, opts1))++defltOpts :: Graph.C graph => T graph -> OptionSet.T graph+defltOpts _ = Graph.defltOptions+ instance Graph.C graph => Display.C (T graph) where toScript plot =- (Display.Script $- State.Cons $ \(n, opts0) ->- let defltOpts :: Graph.C graph => T graph -> OptionSet.T graph- defltOpts _ = Graph.defltOptions- opts1 = OptionSet.decons (defltOpts plot)- in (Display.Body [] $- OptionSet.diffToString opts0 opts1,- (n, opts1)))- `mappend`- toScript plot+ optionsToScript (defltOpts plot) `mappend` toScript plot plotCmd :: Graph.C graph =>
src/Graphics/Gnuplot/Private/Terminal.hs view
@@ -11,8 +11,3 @@ deflt :: T deflt = Cons ["x11"] []---formatBool :: String -> Bool -> String-formatBool name b =- if b then name else "no"++name
src/Graphics/Gnuplot/Simple.hs view
@@ -51,8 +51,8 @@ import qualified Graphics.Gnuplot.Plot.ThreeDimensional as Plot3D import qualified Graphics.Gnuplot.Private.LineSpecification as LineSpec import qualified Graphics.Gnuplot.Private.Graph2D as Graph2D-import qualified Graphics.Gnuplot.Private.Graph3D as Graph3D import qualified Graphics.Gnuplot.Private.Graph2DType as GraphType+import qualified Graphics.Gnuplot.Private.Graph as Graph import qualified Graphics.Gnuplot.Private.Plot as Plot import qualified Graphics.Gnuplot.Value.Tuple as Tuple@@ -69,12 +69,11 @@ import System.Cmd (rawSystem, ) import Graphics.Gnuplot.Utility- (quote, commaConcat, showTriplet, linearScale, )+ (quote, commaConcat, semiColonConcat, showTriplet, linearScale, ) import qualified Data.Monoid.State as State+import Data.Foldable (foldMap, ) import Data.Maybe (listToMaybe, mapMaybe, isNothing, ) import Data.List.HT (dropWhileRev, )-import Data.List (intersperse, )-import Data.Monoid (mconcat, ) -- * User front-end@@ -207,14 +206,14 @@ (Tuple.C a) => [Attribute] -> [[a]] -> IO () plotLists attrs xss =- plot2d attrs (mconcat $ map list xss)+ plot2d attrs (foldMap list xss) plotListsStyle :: (Tuple.C a) => [Attribute] -> [(PlotStyle, [a])] -> IO () plotListsStyle attrs =- plot2d attrs . mconcat .- map (\(style,xs) -> setPlotStyle style $ list xs)+ plot2d attrs .+ foldMap (\(style,xs) -> setPlotStyle style $ list xs) {- | > plotFunc [] (linearScale 1000 (-10,10)) sin@@ -244,7 +243,7 @@ (Tuple.C a) => [Attribute] -> [[(a,a)]] -> IO () plotPaths attrs xss =- plot2d attrs (mconcat $ map list xss)+ plot2d attrs (foldMap list xss) plotPathStyle :: (Tuple.C a) =>@@ -256,8 +255,8 @@ (Tuple.C a) => [Attribute] -> [(PlotStyle, [(a,a)])] -> IO () plotPathsStyle attrs =- plot2d attrs . mconcat .- map (\(style,xs) -> setPlotStyle style $ list xs)+ plot2d attrs .+ foldMap (\(style,xs) -> setPlotStyle style $ list xs) {- | > plotParamFunc [] (linearScale 1000 (0,2*pi)) (\t -> (sin (2*t), cos t))@@ -275,8 +274,8 @@ (Atom.C a, Tuple.C a) => [Attribute] -> [a] -> [a -> (a,a)] -> IO () plotParamFuncs attrs args fs =- plot2d attrs (mconcat $- map (Plot2D.parameterFunction GraphType.lines args) fs)+ plot2d attrs $+ foldMap (Plot2D.parameterFunction GraphType.lines args) fs plotDots ::@@ -307,6 +306,8 @@ {- | > let xs = [-2,-1.8..2::Double] in plotMesh3d [] [] (do x <- xs; return (do y <- xs; return (x,y,cos(x*x+y*y))))++> let phis = linearScale 30 (-pi, pi :: Double) in plotMesh3d [] [] (do phi <- phis; return (do psi <- phis; let r = 5 + sin psi in return (r * cos phi, r * sin phi, cos psi))) -} plotMesh3d :: (Atom.C x, Atom.C y, Atom.C z,@@ -365,8 +366,7 @@ "set " ++ attribute ++ " " ++ unwords parameters attrToProg (Terminal (Terminal.Cons options commands)) =- concat $- intersperse "; " $+ semiColonConcat $ ("set terminal " ++ unwords options) : commands attrToProg (EPS filename) =@@ -479,14 +479,11 @@ -plot2d :: [Attribute] -> Plot2D.T x y -> IO ()-plot2d attrs (Plot.Cons mp) =- let files = State.evaluate 0 mp- in do mapM_ Plot.writeData files- callGnuplot attrs "plot" $- concatMap (\(Plot.File filename _ grs) ->- map (\gr -> quote filename ++ " " ++ Graph2D.toString gr) grs) $- files+plot2d ::+ (Atom.C x, Atom.C y) =>+ [Attribute] -> Plot2D.T x y -> IO ()+plot2d attrs plt =+ runGnuplot attrs "plot" plt setPlotStyle :: PlotStyle -> Plot2D.T x y -> Plot2D.T x y setPlotStyle ps =@@ -494,15 +491,12 @@ Graph2D.lineSpec (lineSpecRecord $ lineSpec ps)) -plot3d :: [Attribute] -> [Attribute3d] -> Plot3D.T x y z -> IO ()-plot3d attrs pt (Plot.Cons mp) =- let files = State.evaluate 0 mp- in do mapM_ Plot.writeData files- callGnuplot- (attrs ++ [Custom "pm3d" (map attribute3dToString pt)]) "splot" $- concatMap (\(Plot.File filename _ grs) ->- map (\gr -> quote filename ++ " " ++ Graph3D.toString gr) grs) $- files+plot3d ::+ (Atom.C x, Atom.C y, Atom.C z) =>+ [Attribute] -> [Attribute3d] -> Plot3D.T x y z -> IO ()+plot3d attrs pt plt =+ runGnuplot+ (attrs ++ [Custom "pm3d" (map attribute3dToString pt)]) "splot" plt lineSpecRecord :: LineSpec -> LineSpec.T@@ -522,6 +516,17 @@ LineTitle s -> LineSpec.title s ) +runGnuplot ::+ Graph.C graph =>+ [Attribute] -> String -> Plot.T graph -> IO ()+runGnuplot attrs cmd (Plot.Cons mp) =+ let files = State.evaluate 0 mp+ in do mapM_ Plot.writeData files+ callGnuplot attrs cmd $+ concatMap (\(Plot.File filename _ grs) ->+ map (\gr -> quote filename ++ " " ++ Graph.toString gr) grs) $+ files+ callGnuplot :: [Attribute] -> String -> [String] -> IO () callGnuplot attrs cmd params = Exec.simple@@ -529,6 +534,6 @@ [cmd ++ " " ++ extractRanges attrs ++ " " ++ commaConcat params])- ["-persist"]+ ["--persist"] -- instead of the option, one can also use 'set terminal x11 persist' >> return ()
src/Graphics/Gnuplot/Terminal/PNG.hs view
@@ -7,9 +7,8 @@ ) where import qualified Graphics.Gnuplot.Private.Terminal as Terminal-import Graphics.Gnuplot.Private.Terminal (formatBool, ) import Data.Maybe (catMaybes, )-import Graphics.Gnuplot.Utility (quote, )+import Graphics.Gnuplot.Utility (quote, formatBool, ) data T =
src/Graphics/Gnuplot/Terminal/WXT.hs view
@@ -9,9 +9,8 @@ ) where import qualified Graphics.Gnuplot.Private.Terminal as Terminal-import Graphics.Gnuplot.Private.Terminal (formatBool, ) import Data.Maybe (catMaybes, )-import Graphics.Gnuplot.Utility (quote, )+import Graphics.Gnuplot.Utility (quote, formatBool, ) data T =
src/Graphics/Gnuplot/Terminal/X11.hs view
@@ -5,9 +5,8 @@ ) where import qualified Graphics.Gnuplot.Private.Terminal as Terminal-import Graphics.Gnuplot.Private.Terminal (formatBool, ) import Data.Maybe (catMaybes, )-import Graphics.Gnuplot.Utility (quote, )+import Graphics.Gnuplot.Utility (quote, formatBool, ) data T =
src/Graphics/Gnuplot/Utility.hs view
@@ -33,3 +33,8 @@ intersperse (showString ", ") p ++ [showString "\n"]) ps)+++formatBool :: String -> Bool -> String+formatBool name b =+ if b then name else "no"++name