gnuplot 0.2 → 0.3
raw patch · 5 files changed
+41/−37 lines, 5 filesdep +utility-htPVP ok
version bump matches the API change (PVP)
Dependencies added: utility-ht
API changes (from Hackage documentation)
- Graphics.Gnuplot.Simple: type PlotStyle = (PlotType, LineSpec)
+ Graphics.Gnuplot.Simple: Custom :: String -> [String] -> Attribute
+ Graphics.Gnuplot.Simple: LineTitle :: String -> LineAttr
+ Graphics.Gnuplot.Simple: PNG :: FilePath -> Attribute
+ Graphics.Gnuplot.Simple: PlotStyle :: PlotType -> LineSpec -> PlotStyle
+ Graphics.Gnuplot.Simple: data PlotStyle
+ Graphics.Gnuplot.Simple: lineSpec :: PlotStyle -> LineSpec
+ Graphics.Gnuplot.Simple: plotType :: PlotStyle -> PlotType
Files
- execute/shell/Graphics/Gnuplot/Execute.hs +3/−1
- gnuplot.cabal +2/−1
- src/Graphics/Gnuplot/Simple.hs +32/−18
- src/Graphics/Gnuplot/Time.hs +3/−3
- src/Graphics/Gnuplot/Utility.hs +1/−14
execute/shell/Graphics/Gnuplot/Execute.hs view
@@ -12,12 +12,14 @@ -> IO ExitCode simple program options = let cmd =- "sh -c 'echo " ++ quote (escape (semiColonConcat program)) +++ "sh -c 'echo " ++ quote (semiColonConcat program) ++ " | gnuplot " ++ unwords options ++ "'" in do --putStrLn cmd system cmd +{- escape :: String -> String escape ('\"':xs) = '\\' : '\"' : escape xs escape (x:xs) = x : escape xs escape [] = []+-}
gnuplot.cabal view
@@ -1,5 +1,5 @@ Name: gnuplot-Version: 0.2+Version: 0.3 License: GPL License-File: LICENSE Author: Henning Thielemann <haskell@henning-thielemann.de>@@ -45,6 +45,7 @@ default: False Library+ Build-Depends: utility-ht >= 0.0.1 && < 0.1 If flag(splitBase) Build-Depends: base >= 2, process >= 1.0 && < 1.1, time >= 1.1 && < 1.2, old-locale >= 1.0 && < 1.1 Else
src/Graphics/Gnuplot/Simple.hs view
@@ -7,7 +7,7 @@ LineSpec(..), PlotType(..), - PlotStyle,+ PlotStyle(..), linearScale, defaultStyle,@@ -42,13 +42,17 @@ import Data.Maybe (listToMaybe, mapMaybe, isNothing, ) import qualified Graphics.Gnuplot.Execute as Exec import Graphics.Gnuplot.Utility- (dropWhileRev, functionToGraph,+ (functionToGraph, quote, commaConcat, showTriplet, )+import Data.List.HT (dropWhileRev, ) + {-* User front-end -} data Attribute =- EPS FilePath+ Custom String [String] -- ^ anything that is allowed after gnuplot's @set@ command+ | EPS FilePath+ | PNG FilePath | Grid (Maybe [String]) | Key (Maybe [String]) | Border (Maybe [String])@@ -84,6 +88,7 @@ | LineWidth Double | PointType Int | PointSize Double+ | LineTitle String data LineSpec = DefaultStyle Int@@ -115,7 +120,7 @@ | Vectors | PM3d -type PlotStyle = (PlotType, LineSpec)+data PlotStyle = PlotStyle { plotType :: PlotType, lineSpec :: LineSpec } -- candidate for Useful, similar routines are in module Integration@@ -124,7 +129,7 @@ map (\m -> x0 + (x1-x0) * fromIntegral m / fromIntegral n) [0..n] defaultStyle :: PlotStyle-defaultStyle = (Lines, CustomStyle [])+defaultStyle = PlotStyle Lines (CustomStyle []) @@ -138,7 +143,7 @@ plotListStyle attrs style dat = do writeFile tmpFile (unlines (map show dat)) callGnuplot attrs "plot"- [quote tmpFile ++ " using 1 with " +++ [quote tmpFile ++ " using 1 " ++ plotStyleToString style] return () @@ -157,7 +162,7 @@ callGnuplot attrs "plot" (zipWith (\fileName style ->- quote fileName ++ " using 1 with " +++ quote fileName ++ " using 1 " ++ plotStyleToString style) fileNames (map fst dats)) return ()@@ -199,7 +204,7 @@ plotDots :: Show a => [Attribute] -> [(a,a)] -> IO ()-plotDots attrs = plot2dGen attrs (Points, CustomStyle [])+plotDots attrs = plot2dGen attrs (defaultStyle { plotType = Dots }) @@ -285,9 +290,17 @@ attrToProg :: Attribute -> String+attrToProg (Custom attribute parameters) =+ "set " ++ attribute ++ " " ++ unwords parameters+ attrToProg (EPS filename) = "set terminal postscript eps;" ++ -- latex "set output " ++ quote filename++attrToProg (PNG filename) =+ "set terminal png;" ++ -- latex+ "set output " ++ quote filename+ attrToProg (Grid (Just x)) = "set grid " ++ unwords x attrToProg (Grid Nothing) = "set nogrid" attrToProg (Key (Just x)) = "set key " ++ unwords x@@ -304,16 +317,16 @@ attrToProg (Aspect (NoRatio)) = "set size noratio" attrToProg (BoxAspect (Ratio r)) = "set size ratio " ++ show r attrToProg (BoxAspect (NoRatio)) = "set size noratio"-attrToProg (LineStyle num style)- = "set linestyle " ++ show num ++ " " ++ unwords (map lineAttrToString style)-attrToProg (Title title) = "set title " ++ quote title+attrToProg (LineStyle num style) =+ "set linestyle " ++ show num ++ " " ++ unwords (map lineAttrToString style)+attrToProg (Title title_) = "set title " ++ quote title_ attrToProg (XLabel label) = "set xlabel " ++ quote label attrToProg (YLabel label) = "set ylabel " ++ quote label attrToProg (XRange _) = "" -- xrange is handled in plot command attrToProg (YRange _) = "" -- yrange is handled in plot command attrToProg (ZRange _) = "" -- zrange is handled in plot command-attrToProg (Palette colors)- = "set palette defined (" +++attrToProg (Palette colors) =+ "set palette defined (" ++ commaConcat (map (\(idx,c) -> show idx ++ " " ++ showTriplet c) colors) ++ ")" attrToProg (ColorBox (Just x)) = "set colorbox " ++ unwords x attrToProg (ColorBox Nothing) = "unset colorbox"@@ -334,7 +347,7 @@ extractRanges :: [Attribute] -> String extractRanges attrs = let ranges = map (listToMaybe . flip mapMaybe attrs)- [xRangeFromAttr, yRangeFromAttr, zRangeFromAttr]+ [xRangeFromAttr, yRangeFromAttr, zRangeFromAttr] showRng (l,r) = "[" ++ show l ++ ":" ++ show r ++ "]" in unwords (map (maybe "[:]" showRng) (dropWhileRev isNothing ranges)) @@ -345,6 +358,7 @@ lineAttrToString (LineWidth x) = "linewidth " ++ show x lineAttrToString (PointType t) = "pointtype " ++ show t lineAttrToString (PointSize x) = "pointsize " ++ show x+lineAttrToString (LineTitle s) = "title " ++ quote s lineSpecToString :: LineSpec -> String lineSpecToString (DefaultStyle n) = "linestyle " ++ show n@@ -378,8 +392,8 @@ plotStyleToString :: PlotStyle -> String-plotStyleToString (p, l) =- plotTypeToString p ++ " " ++ lineSpecToString l+plotStyleToString (PlotStyle p l) =+ "with " ++ plotTypeToString p ++ " " ++ lineSpecToString l plot3dTypeToString :: Plot3dType -> String@@ -406,7 +420,7 @@ storeData :: Show a => FilePath -> PlotStyle -> [(a,a)] -> IO String storeData file style dat = do writeFile file (unlines (map (\(x,y) -> show x ++ " " ++ show y) dat))- return (quote file ++ " using 1:2 with " ++ plotStyleToString style)+ return (quote file ++ " using 1:2 " ++ plotStyleToString style) plot2dGen :: Show a => [Attribute] -> PlotStyle -> [(a,a)] -> IO () plot2dGen attrs style dat =@@ -428,7 +442,7 @@ plot2dMultiSharedAbscissa attrs styles dat = let plotParams = zipWith (\n style -> quote tmpFile ++ " using 1:"- ++ show (n+1) ++ " with " ++ plotStyleToString style)+ ++ show (n+1) ++ " " ++ plotStyleToString style) [(1::Int)..] styles in do {- writeFile tmpFile (concatMap (\(x,ys) -> foldr (\y -> shows y . (' ':)) (shows x "\n") ys) dat) -}
src/Graphics/Gnuplot/Time.hs view
@@ -1,8 +1,8 @@ module Graphics.Gnuplot.Time where -import System.Locale(defaultTimeLocale)-import Data.Time.Format(FormatTime, formatTime)-import Graphics.Gnuplot.Utility (mapFst)+import System.Locale (defaultTimeLocale, )+import Data.Time.Format (FormatTime, formatTime, )+import Data.Tuple.HT (mapFst, ) {- | Use it this way:
src/Graphics/Gnuplot/Utility.hs view
@@ -3,10 +3,6 @@ import Data.List (intersperse, ) -dropWhileRev :: (a -> Bool) -> [a] -> [a]-dropWhileRev p =- foldr (\x xs -> if p x && null xs then [] else x:xs) []- functionToGraph :: [a] -> (a -> a) -> [(a,a)] functionToGraph args f = map (\x -> (x, f x)) args -- functionToGraph args f = map swap $ attachKey f args@@ -22,13 +18,4 @@ quote :: String -> String-quote str = "\"" ++ str ++ "\""-----mapFst :: (a -> c) -> (a,b) -> (c,b)-mapFst f ~(a,b) = (f a, b)--mapSnd :: (b -> c) -> (a,b) -> (a,c)-mapSnd f ~(a,b) = (a, f b)+quote = show