mirror of
https://github.com/IHaskell/IHaskell.git
synced 2025-04-19 12:56:08 +00:00
created a display instance for the (haskell-)gnuplot package
This commit is contained in:
parent
fd7da220ca
commit
1889f5cdcf
186
ihaskell-display/ihaskell-gnuplot/IHaskell/Display/Gnuplot.hs
Normal file
186
ihaskell-display/ihaskell-gnuplot/IHaskell/Display/Gnuplot.hs
Normal file
@ -0,0 +1,186 @@
|
||||
{- 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 Graphics.Gnuplot.Frame.OptionSet (size, deflt)
|
||||
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
|
20
ihaskell-display/ihaskell-gnuplot/LICENSE
Normal file
20
ihaskell-display/ihaskell-gnuplot/LICENSE
Normal file
@ -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.
|
2
ihaskell-display/ihaskell-gnuplot/Setup.hs
Normal file
2
ihaskell-display/ihaskell-gnuplot/Setup.hs
Normal file
@ -0,0 +1,2 @@
|
||||
import Distribution.Simple
|
||||
main = defaultMain
|
70
ihaskell-display/ihaskell-gnuplot/ihaskell-gnuplot.cabal
Normal file
70
ihaskell-display/ihaskell-gnuplot/ihaskell-gnuplot.cabal
Normal file
@ -0,0 +1,70 @@
|
||||
-- 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.0
|
||||
|
||||
-- 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:
|
||||
|
||||
-- Language extensions.
|
||||
default-extensions: DoAndIfThenElse
|
||||
OverloadedStrings
|
||||
|
||||
-- Other library packages from which modules are imported.
|
||||
build-depends: base >=4.6 && <4.9,
|
||||
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
|
33
ihaskell-display/ihaskell-gnuplot/stack.yaml
Normal file
33
ihaskell-display/ihaskell-gnuplot/stack.yaml
Normal file
@ -0,0 +1,33 @@
|
||||
# For more information, see: https://github.com/commercialhaskell/stack/blob/release/doc/yaml_configuration.md
|
||||
|
||||
# Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2)
|
||||
resolver: lts-3.14
|
||||
|
||||
# Local packages, usually specified by relative directory name
|
||||
packages:
|
||||
- '.'
|
||||
|
||||
# Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3)
|
||||
extra-deps:
|
||||
- gnuplot-0.5.4
|
||||
- data-accessor-transformers-0.2.1.6
|
||||
# Override default flag values for local packages and extra-deps
|
||||
flags: {}
|
||||
|
||||
# Extra package databases containing global packages
|
||||
extra-package-dbs: []
|
||||
|
||||
# Control whether we use the GHC we find on the path
|
||||
# system-ghc: true
|
||||
|
||||
# Require a specific version of stack, using version ranges
|
||||
# require-stack-version: -any # Default
|
||||
# require-stack-version: >= 1.0.0
|
||||
|
||||
# Override the architecture used by stack, especially useful on Windows
|
||||
# arch: i386
|
||||
# arch: x86_64
|
||||
|
||||
# Extra directories used by stack for building
|
||||
# extra-include-dirs: [/path/to/dir]
|
||||
# extra-lib-dirs: [/path/to/dir]
|
@ -15,6 +15,7 @@ packages:
|
||||
- ihaskell-display/ihaskell-basic/
|
||||
- ihaskell-display/ihaskell-aeson/
|
||||
- ihaskell-display/ihaskell-hatex/
|
||||
- ihaskell-display/ihaskell-gnuplot/
|
||||
extra-deps:
|
||||
- magic-1.1
|
||||
- Rlang-QQ-0.3.1.0
|
||||
@ -24,4 +25,7 @@ extra-deps:
|
||||
- xformat-0.1.2.1
|
||||
- ratio-int-0.1.2
|
||||
- friday-0.2.2.0
|
||||
- haskell-src-exts-1.17.0
|
||||
- gnuplot-0.5.4
|
||||
- data-accessor-transformers-0.2.1.6
|
||||
resolver: nightly-2016-03-25
|
||||
|
Loading…
x
Reference in New Issue
Block a user