ihaskell-gnuplot (empty) → 0.1.0.1
raw patch · 4 files changed
+276/−0 lines, 4 filesdep +basedep +bytestringdep +gnuplotsetup-changed
Dependencies added: base, bytestring, gnuplot, ihaskell
Files
- IHaskell/Display/Gnuplot.hs +187/−0
- LICENSE +20/−0
- Setup.hs +3/−0
- ihaskell-gnuplot.cabal +66/−0
+ IHaskell/Display/Gnuplot.hs view
@@ -0,0 +1,187 @@+{-# LANGUAGE FlexibleInstances #-}++{- There are 3 types of plots to consider in haskell-gnuplot: Plot, Frame and Multiplot.+ Plot types are the actual plots, whereas Frame types are plots with additional options+ e.g. custom axes tics, graph title etc.. Multiplots are collections of 2D and/or 3D plots.+ We have to create instances of IHaskellDisplay for all of these types.++ Note: To stop gnuplot from printing the filepath ontop of the canvas, you have to set+ the gnuplot option "key" to "noautotitle".+ Code: Graphics.Gnuplot.Frame.cons (Graphics.Gnuplot.Frame.OptionSet.add+ (Graphics.Gnuplot.Frame.Option.key "")+ ["noautotitle"] $ ...)+-}+module IHaskell.Display.Gnuplot where++import qualified Graphics.Gnuplot.Plot as P+import qualified Graphics.Gnuplot.Frame as F+import qualified Graphics.Gnuplot.MultiPlot as M+import qualified Graphics.Gnuplot.Terminal.PNG as Pn+import qualified Graphics.Gnuplot.Terminal.SVG as Sv+import qualified Graphics.Gnuplot.Graph.TwoDimensional as Tw+import qualified Graphics.Gnuplot.Graph.ThreeDimensional as Th+import qualified Data.ByteString.Char8 as Char+import Graphics.Gnuplot.Advanced (plot)+import Graphics.Gnuplot.Value.Atom (C)+import IHaskell.Display++-- Plot-types+instance (C x, C y) => IHaskellDisplay (P.T (Tw.T x y)) where+ display fig = do+ pngDisp <- graphDataPNG2P fig+ svgDisp <- graphDataSVG2P fig+ return $ Display [pngDisp, svgDisp]++instance (C x, C y, C z) => IHaskellDisplay (P.T (Th.T x y z)) where+ display fig = do+ pngDisp <- graphDataPNG3P fig+ svgDisp <- graphDataSVG3P fig+ return $ Display [pngDisp, svgDisp]++-- Frame-types+instance (C x, C y) => IHaskellDisplay (F.T (Tw.T x y)) where+ display fig = do+ pngDisp <- graphDataPNG2F fig+ svgDisp <- graphDataSVG2F fig+ return $ Display [pngDisp, svgDisp]++instance (C x, C y, C z) => IHaskellDisplay (F.T (Th.T x y z)) where+ display fig = do+ pngDisp <- graphDataPNG3F fig+ svgDisp <- graphDataSVG3F fig+ return $ Display [pngDisp, svgDisp]++-- Type: Multiplot+instance IHaskellDisplay M.T where+ display fig = do+ pngDisp <- graphDataPNGM fig+ svgDisp <- graphDataSVGM fig+ return $ Display [pngDisp, svgDisp]++-- Filename+name = ".ihaskell-gnuplot."++-- Width and height+w = 300++h = 300++graphDataPNG2P :: (C x, C y) => P.T (Tw.T x y) -> IO DisplayData+graphDataPNG2P graph = do+ switchToTmpDir++ -- Write the image.+ let fname = Pn.cons $ name ++ "png"+ plot fname graph++ -- Read back, and convert to base64.+ imgData <- Char.readFile $ name ++ "png"+ return $ png w h $ base64 imgData++graphDataSVG2P :: (C x, C y) => P.T (Tw.T x y) -> IO DisplayData+graphDataSVG2P graph = do+ switchToTmpDir++ -- Write the image.+ let fname = Sv.cons $ name ++ "svg"+ plot fname graph++ -- Read back, and convert to base64.+ imgData <- Char.readFile $ name ++ "svg"+ return $ svg $ Char.unpack imgData++graphDataPNG2F :: (C x, C y) => F.T (Tw.T x y) -> IO DisplayData+graphDataPNG2F graph = do+ switchToTmpDir++ -- Write the image.+ let fname = Pn.cons $ name ++ "png"+ plot fname graph++ -- Read back, and convert to base64.+ imgData <- Char.readFile $ name ++ "png"+ return $ png w h $ base64 imgData++graphDataSVG2F :: (C x, C y) => F.T (Tw.T x y) -> IO DisplayData+graphDataSVG2F graph = do+ switchToTmpDir++ -- Write the image.+ let fname = Sv.cons $ name ++ "svg"+ plot fname graph++ -- Read back, and convert to base64.+ imgData <- Char.readFile $ name ++ "svg"+ return $ svg $ Char.unpack imgData++graphDataPNG3P :: (C x, C y, C z) => P.T (Th.T x y z) -> IO DisplayData+graphDataPNG3P graph = do+ switchToTmpDir++ -- Write the image.+ let fname = Pn.cons $ name ++ "png"+ plot fname graph++ -- Read back, and convert to base64.+ imgData <- Char.readFile $ name ++ "png"+ return $ png w h $ base64 imgData++graphDataSVG3P :: (C x, C y, C z) => P.T (Th.T x y z) -> IO DisplayData+graphDataSVG3P graph = do+ switchToTmpDir++ -- Write the image.+ let fname = Sv.cons $ name ++ "svg"+ plot fname graph++ -- Read back, and convert to base64.+ imgData <- Char.readFile $ name ++ "svg"+ return $ svg $ Char.unpack imgData++graphDataPNG3F :: (C x, C y, C z) => F.T (Th.T x y z) -> IO DisplayData+graphDataPNG3F graph = do+ switchToTmpDir++ -- Write the image.+ let fname = Pn.cons $ name ++ "png"+ plot fname graph++ -- Read back, and convert to base64.+ imgData <- Char.readFile $ name ++ "png"+ return $ png w h $ base64 imgData++graphDataSVG3F :: (C x, C y, C z) => F.T (Th.T x y z) -> IO DisplayData+graphDataSVG3F graph = do+ switchToTmpDir++ -- Write the image.+ let fname = Sv.cons $ name ++ "svg"+ plot fname graph++ -- Read back, and convert to base64.+ imgData <- Char.readFile $ name ++ "svg"+ return $ svg $ Char.unpack imgData++graphDataPNGM :: M.T -> IO DisplayData+graphDataPNGM graph = do+ switchToTmpDir++ -- Write the image.+ let fname = Pn.cons $ name ++ "png"+ plot fname graph++ -- Read back, and convert to base64.+ imgData <- Char.readFile $ name ++ "png"+ return $ png w h $ base64 imgData++graphDataSVGM :: M.T -> IO DisplayData+graphDataSVGM graph = do+ switchToTmpDir++ -- Write the image.+ let fname = Sv.cons $ name ++ "svg"+ plot fname graph++ -- Read back, and convert to base64.+ imgData <- Char.readFile $ name ++ "svg"+ return $ svg $ Char.unpack imgData
+ LICENSE view
@@ -0,0 +1,20 @@+The MIT License (MIT)++Copyright (c) 2013 Andrew Gibiansky++Permission is hereby granted, free of charge, to any person obtaining a copy of+this software and associated documentation files (the "Software"), to deal in+the Software without restriction, including without limitation the rights to+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of+the Software, and to permit persons to whom the Software is furnished to do so,+subject to the following conditions:++The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,3 @@+import Distribution.Simple++main = defaultMain
+ ihaskell-gnuplot.cabal view
@@ -0,0 +1,66 @@+-- The name of the package.+name: ihaskell-gnuplot++-- The package version. See the Haskell package versioning policy (PVP) +-- for standards guiding when and how versions should be incremented.+-- http://www.haskell.org/haskellwiki/Package_versioning_policy+-- PVP summary: +-+------- breaking API changes+-- | | +----- non-breaking API additions+-- | | | +--- code changes with no API change+version: 0.1.0.1++-- A short (one-line) description of the package.+synopsis: IHaskell display instance for Gnuplot (from gnuplot package)++-- A longer description of the package.+-- description: ++-- URL for the project homepage or repository.+homepage: http://www.github.com/gibiansky/ihaskell++-- The license under which the package is released.+license: MIT++-- The file containing the license text.+license-file: LICENSE++-- The package author(s).+author: Doro Rose <dororose@hotmail.com>++-- An email address to which users can send suggestions, bug reports, and +-- patches.+maintainer: Doro Rose <dororose@hotmail.com>,+ Andrew Gibiansky <andrew.gibiansky@gmail.com>++-- A copyright notice.+-- copyright: ++category: Development++build-type: Simple++-- Extra files to be distributed with the package, such as examples or a +-- README.+-- extra-source-files: ++-- Constraint on the version of Cabal needed to build this package.+cabal-version: >=1.16++library+ -- Modules exported by the library.+ exposed-modules: IHaskell.Display.Gnuplot+ + -- Modules included in this library but not exported.+ -- other-modules: + + -- Other library packages from which modules are imported.+ build-depends: base >=4.6 && <5,+ bytestring,+ gnuplot >= 0.5.4,+ ihaskell >= 0.6.2+ + -- Directories containing source files.+ -- hs-source-dirs: + + -- Base language which the package is written in.+ default-language: Haskell2010