mirror of
https://github.com/IHaskell/IHaskell.git
synced 2025-04-16 03:16:20 +00:00
moving ihaskell-display and adding build script
This commit is contained in:
parent
e09132a0a6
commit
354cffca2a
13
build.sh
Executable file
13
build.sh
Executable file
@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
cd profile
|
||||
rm profile.tar
|
||||
tar -cvf profile.tar *
|
||||
cd ..
|
||||
cabal install --force-reinstalls || return 1
|
||||
cd ihaskell-display
|
||||
for dir in `ls`
|
||||
do
|
||||
cd $dir
|
||||
cabal install || return 1
|
||||
cd ..
|
||||
done
|
16
ihaskell-display/ihaskell-aeson/IHaskell/Display/Aeson.hs
Normal file
16
ihaskell-display/ihaskell-aeson/IHaskell/Display/Aeson.hs
Normal file
@ -0,0 +1,16 @@
|
||||
{-# LANGUAGE NoImplicitPrelude, TypeSynonymInstances, QuasiQuotes #-}
|
||||
module IHaskell.Display.Aeson where
|
||||
|
||||
import ClassyPrelude
|
||||
import Data.Textual.Encoding
|
||||
import Data.Aeson
|
||||
import Data.Aeson.Encode.Pretty
|
||||
import Data.String.Here
|
||||
|
||||
import IHaskell.Display
|
||||
|
||||
instance IHaskellDisplay Value where
|
||||
display renderable = return [plain json, html dom]
|
||||
where
|
||||
json = unpack $ decodeUtf8 $ encodePretty renderable
|
||||
dom = [i|<div class="highlight-code" id="javascript">${json}</div>|]
|
20
ihaskell-display/ihaskell-aeson/LICENSE
Normal file
20
ihaskell-display/ihaskell-aeson/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-aeson/Setup.hs
Normal file
2
ihaskell-display/ihaskell-aeson/Setup.hs
Normal file
@ -0,0 +1,2 @@
|
||||
import Distribution.Simple
|
||||
main = defaultMain
|
71
ihaskell-display/ihaskell-aeson/ihaskell-aeson.cabal
Normal file
71
ihaskell-display/ihaskell-aeson/ihaskell-aeson.cabal
Normal file
@ -0,0 +1,71 @@
|
||||
-- The name of the package.
|
||||
name: ihaskell-aeson
|
||||
|
||||
-- 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 instances for Aeson
|
||||
|
||||
-- A longer description of the package.
|
||||
-- description:
|
||||
|
||||
-- URL for the project homepage or repository.
|
||||
homepage: http://www.github.com/gibiansky/IHaskell-Display
|
||||
|
||||
-- The license under which the package is released.
|
||||
-- license:
|
||||
|
||||
-- The file containing the license text.
|
||||
license-file: LICENSE
|
||||
|
||||
-- The package author(s).
|
||||
author: Andrew Gibiansky
|
||||
|
||||
-- An email address to which users can send suggestions, bug reports, and
|
||||
-- patches.
|
||||
maintainer: 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.Aeson
|
||||
|
||||
-- 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.*,
|
||||
here,
|
||||
classy-prelude >=0.7,
|
||||
aeson,
|
||||
aeson-pretty,
|
||||
ihaskell
|
||||
|
||||
-- Directories containing source files.
|
||||
-- hs-source-dirs:
|
||||
|
||||
-- Base language which the package is written in.
|
||||
default-language: Haskell2010
|
15
ihaskell-display/ihaskell-basic/IHaskell/Display/Display.hs
Normal file
15
ihaskell-display/ihaskell-basic/IHaskell/Display/Display.hs
Normal file
@ -0,0 +1,15 @@
|
||||
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
|
||||
module IHaskell.Display.Display where
|
||||
|
||||
import IHaskell.Display
|
||||
|
||||
import Text.Printf
|
||||
|
||||
instance Show a => IHaskellDisplay (Maybe a) where
|
||||
display just = return [stringDisplay, htmlDisplay]
|
||||
where
|
||||
stringDisplay = plain (show just)
|
||||
htmlDisplay = html str
|
||||
str = case just of
|
||||
Nothing -> "<span style='color: red; font-weight: bold;'>Nothing</span>"
|
||||
Just x -> printf "<span style='color: green; font-weight: bold;'>Just</span><span style='font-family: monospace;'>%s</span>" (show x)
|
20
ihaskell-display/ihaskell-basic/LICENSE
Normal file
20
ihaskell-display/ihaskell-basic/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.
|
4
ihaskell-display/ihaskell-basic/README.md
Normal file
4
ihaskell-display/ihaskell-basic/README.md
Normal file
@ -0,0 +1,4 @@
|
||||
IHaskell-Display
|
||||
================
|
||||
|
||||
Instances of IHaskellDisplay for default prelude data types.
|
2
ihaskell-display/ihaskell-basic/Setup.hs
Normal file
2
ihaskell-display/ihaskell-basic/Setup.hs
Normal file
@ -0,0 +1,2 @@
|
||||
import Distribution.Simple
|
||||
main = defaultMain
|
73
ihaskell-display/ihaskell-basic/ihaskell-display.cabal
Normal file
73
ihaskell-display/ihaskell-basic/ihaskell-display.cabal
Normal file
@ -0,0 +1,73 @@
|
||||
-- Initial ihaskell-display.cabal generated by cabal init. For further
|
||||
-- documentation, see http://haskell.org/cabal/users-guide/
|
||||
|
||||
-- The name of the package.
|
||||
name: ihaskell-display
|
||||
|
||||
-- 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 instances for basic types
|
||||
|
||||
-- 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:
|
||||
|
||||
-- The file containing the license text.
|
||||
license-file: LICENSE
|
||||
|
||||
-- The package author(s).
|
||||
author: Andrew Gibiansky
|
||||
|
||||
-- An email address to which users can send suggestions, bug reports, and
|
||||
-- patches.
|
||||
maintainer: 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.Display
|
||||
|
||||
-- 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.*,
|
||||
classy-prelude >=0.6,
|
||||
ihaskell
|
||||
|
||||
-- Directories containing source files.
|
||||
-- hs-source-dirs:
|
||||
|
||||
-- Base language which the package is written in.
|
||||
default-language: Haskell2010
|
||||
|
17
ihaskell-display/ihaskell-blaze/IHaskell/Display/Blaze.hs
Normal file
17
ihaskell-display/ihaskell-blaze/IHaskell/Display/Blaze.hs
Normal file
@ -0,0 +1,17 @@
|
||||
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
|
||||
module IHaskell.Display.Blaze where
|
||||
|
||||
import IHaskell.Display
|
||||
|
||||
import Text.Printf
|
||||
import Text.Blaze.Html
|
||||
import Text.Blaze.Renderer.Pretty
|
||||
import Text.Blaze.Internal
|
||||
import Control.Monad
|
||||
|
||||
instance IHaskellDisplay (MarkupM a) where
|
||||
display val = return [stringDisplay, htmlDisplay]
|
||||
where
|
||||
str = renderMarkup (void val)
|
||||
stringDisplay = plain str
|
||||
htmlDisplay = html str
|
20
ihaskell-display/ihaskell-blaze/LICENSE
Normal file
20
ihaskell-display/ihaskell-blaze/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-blaze/Setup.hs
Normal file
2
ihaskell-display/ihaskell-blaze/Setup.hs
Normal file
@ -0,0 +1,2 @@
|
||||
import Distribution.Simple
|
||||
main = defaultMain
|
74
ihaskell-display/ihaskell-blaze/ihaskell-blaze.cabal
Normal file
74
ihaskell-display/ihaskell-blaze/ihaskell-blaze.cabal
Normal file
@ -0,0 +1,74 @@
|
||||
-- Initial ihaskell-display.cabal generated by cabal init. For further
|
||||
-- documentation, see http://haskell.org/cabal/users-guide/
|
||||
|
||||
-- The name of the package.
|
||||
name: ihaskell-blaze
|
||||
|
||||
-- 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 instances for blaze-html types
|
||||
|
||||
-- A longer description of the package.
|
||||
-- description:
|
||||
|
||||
-- URL for the project homepage or repository.
|
||||
homepage: http://www.github.com/gibiansky/IHaskell-Display
|
||||
|
||||
-- The license under which the package is released.
|
||||
-- license:
|
||||
|
||||
-- The file containing the license text.
|
||||
license-file: LICENSE
|
||||
|
||||
-- The package author(s).
|
||||
author: Andrew Gibiansky
|
||||
|
||||
-- An email address to which users can send suggestions, bug reports, and
|
||||
-- patches.
|
||||
maintainer: 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.Blaze
|
||||
|
||||
-- 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.*,
|
||||
classy-prelude >=0.6,
|
||||
blaze-html >= 0.6,
|
||||
blaze-markup >= 0.5,
|
||||
ihaskell
|
||||
|
||||
-- Directories containing source files.
|
||||
-- hs-source-dirs:
|
||||
|
||||
-- Base language which the package is written in.
|
||||
default-language: Haskell2010
|
47
ihaskell-display/ihaskell-charts/IHaskell/Display/Charts.hs
Normal file
47
ihaskell-display/ihaskell-charts/IHaskell/Display/Charts.hs
Normal file
@ -0,0 +1,47 @@
|
||||
{-# LANGUAGE NoImplicitPrelude #-}
|
||||
module IHaskell.Display.Charts where
|
||||
|
||||
import ClassyPrelude
|
||||
|
||||
import System.Directory
|
||||
import Data.Default.Class
|
||||
import Graphics.Rendering.Chart.Renderable
|
||||
import Graphics.Rendering.Chart.Backend.Cairo
|
||||
import qualified Data.ByteString.Base64 as Base64
|
||||
import qualified Data.ByteString.Char8 as Char
|
||||
import System.IO.Unsafe
|
||||
|
||||
import IHaskell.Display
|
||||
|
||||
width :: Width
|
||||
width = 600
|
||||
|
||||
height :: Height
|
||||
height = 400
|
||||
|
||||
instance IHaskellDisplay (Renderable a) where
|
||||
display renderable = do
|
||||
imgData <- chartData renderable PNG
|
||||
|
||||
-- We can add `svg svgDisplay` to the output of `display`,
|
||||
-- but SVGs are not resizable in the IPython notebook.
|
||||
svgDisplay <- chartData renderable SVG
|
||||
|
||||
return [png width height imgData, svg svgDisplay]
|
||||
|
||||
chartData :: Renderable a -> FileFormat -> IO String
|
||||
chartData renderable format = do
|
||||
-- Switch to a temporary directory so that any files we create aren't
|
||||
-- visible. On Unix, this is usually /tmp.
|
||||
try (getTemporaryDirectory >>= setCurrentDirectory) :: IO (Either SomeException ())
|
||||
|
||||
-- Write the PNG image.
|
||||
let filename = ".ihaskell-chart.png"
|
||||
opts = def{_fo_format = format, _fo_size = (width, height)}
|
||||
renderableToFile opts renderable filename
|
||||
|
||||
-- Convert to base64.
|
||||
imgData <- readFile $ fpFromString filename
|
||||
return $ Char.unpack $ case format of
|
||||
PNG -> Base64.encode imgData
|
||||
_ -> imgData
|
20
ihaskell-display/ihaskell-charts/LICENSE
Normal file
20
ihaskell-display/ihaskell-charts/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-charts/Setup.hs
Normal file
2
ihaskell-display/ihaskell-charts/Setup.hs
Normal file
@ -0,0 +1,2 @@
|
||||
import Distribution.Simple
|
||||
main = defaultMain
|
331
ihaskell-display/ihaskell-charts/Test.ipynb
Normal file
331
ihaskell-display/ihaskell-charts/Test.ipynb
Normal file
File diff suppressed because one or more lines are too long
75
ihaskell-display/ihaskell-charts/ihaskell-charts.cabal
Normal file
75
ihaskell-display/ihaskell-charts/ihaskell-charts.cabal
Normal file
@ -0,0 +1,75 @@
|
||||
-- The name of the package.
|
||||
name: ihaskell-charts
|
||||
|
||||
-- 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 instances for charts types
|
||||
|
||||
-- A longer description of the package.
|
||||
-- description:
|
||||
|
||||
-- URL for the project homepage or repository.
|
||||
homepage: http://www.github.com/gibiansky/IHaskell-Display
|
||||
|
||||
-- The license under which the package is released.
|
||||
-- license:
|
||||
|
||||
-- The file containing the license text.
|
||||
license-file: LICENSE
|
||||
|
||||
-- The package author(s).
|
||||
author: Andrew Gibiansky
|
||||
|
||||
-- An email address to which users can send suggestions, bug reports, and
|
||||
-- patches.
|
||||
maintainer: 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.Charts
|
||||
|
||||
-- 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.*,
|
||||
classy-prelude >=0.6,
|
||||
base64-bytestring,
|
||||
bytestring,
|
||||
data-default-class,
|
||||
directory,
|
||||
Chart,
|
||||
Chart-cairo,
|
||||
ihaskell
|
||||
|
||||
-- Directories containing source files.
|
||||
-- hs-source-dirs:
|
||||
|
||||
-- Base language which the package is written in.
|
||||
default-language: Haskell2010
|
@ -0,0 +1,52 @@
|
||||
{-# LANGUAGE NoImplicitPrelude, TypeSynonymInstances, FlexibleInstances #-}
|
||||
module IHaskell.Display.Diagrams where
|
||||
|
||||
import ClassyPrelude
|
||||
|
||||
import System.Directory
|
||||
import qualified Data.ByteString.Base64 as Base64
|
||||
import qualified Data.ByteString.Char8 as Char
|
||||
import System.IO.Unsafe
|
||||
|
||||
import Diagrams.Prelude
|
||||
import Diagrams.Backend.Cairo
|
||||
|
||||
import IHaskell.Display
|
||||
|
||||
instance IHaskellDisplay (Diagram Cairo R2) where
|
||||
display renderable = do
|
||||
(width, height, imgData) <- diagramData renderable PNG
|
||||
(_, _, svgData) <- diagramData renderable SVG
|
||||
return [png (floor width) (floor height) imgData, svg svgData]
|
||||
|
||||
diagramData :: Diagram Cairo R2 -> OutputType -> IO (Double, Double, String)
|
||||
diagramData renderable format = do
|
||||
-- Switch to a temporary directory so that any files we create aren't
|
||||
-- visible. On Unix, this is usually /tmp.
|
||||
try (getTemporaryDirectory >>= setCurrentDirectory) :: IO (Either SomeException ())
|
||||
|
||||
-- Compute width and height.
|
||||
let w = width renderable
|
||||
h = height renderable
|
||||
aspect = w / h
|
||||
imgHeight = 300
|
||||
imgWidth = aspect * imgHeight
|
||||
|
||||
-- Write the image.
|
||||
let filename = ".ihaskell-diagram." ++ extension format
|
||||
renderCairo filename (Height imgHeight) renderable
|
||||
|
||||
-- Convert to base64.
|
||||
imgData <- readFile $ fpFromString filename
|
||||
let value = Char.unpack $ case format of
|
||||
PNG -> Base64.encode imgData
|
||||
_ -> imgData
|
||||
|
||||
return (imgWidth, imgHeight, value)
|
||||
where
|
||||
extension SVG = "svg"
|
||||
extension PNG = "png"
|
||||
|
||||
-- Rendering hint.
|
||||
diagram :: Diagram Cairo R2 -> Diagram Cairo R2
|
||||
diagram = id
|
20
ihaskell-display/ihaskell-diagrams/LICENSE
Normal file
20
ihaskell-display/ihaskell-diagrams/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-diagrams/Setup.hs
Normal file
2
ihaskell-display/ihaskell-diagrams/Setup.hs
Normal file
@ -0,0 +1,2 @@
|
||||
import Distribution.Simple
|
||||
main = defaultMain
|
331
ihaskell-display/ihaskell-diagrams/Test.ipynb
Normal file
331
ihaskell-display/ihaskell-diagrams/Test.ipynb
Normal file
File diff suppressed because one or more lines are too long
75
ihaskell-display/ihaskell-diagrams/ihaskell-diagrams.cabal
Normal file
75
ihaskell-display/ihaskell-diagrams/ihaskell-diagrams.cabal
Normal file
@ -0,0 +1,75 @@
|
||||
-- The name of the package.
|
||||
name: ihaskell-diagrams
|
||||
|
||||
-- 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 instances for diagram types
|
||||
|
||||
-- A longer description of the package.
|
||||
-- description:
|
||||
|
||||
-- URL for the project homepage or repository.
|
||||
homepage: http://www.github.com/gibiansky/IHaskell-Display
|
||||
|
||||
-- The license under which the package is released.
|
||||
-- license:
|
||||
|
||||
-- The file containing the license text.
|
||||
license-file: LICENSE
|
||||
|
||||
-- The package author(s).
|
||||
author: Andrew Gibiansky
|
||||
|
||||
-- An email address to which users can send suggestions, bug reports, and
|
||||
-- patches.
|
||||
maintainer: 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.Diagrams
|
||||
|
||||
-- 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.*,
|
||||
classy-prelude >=0.6,
|
||||
base64-bytestring,
|
||||
bytestring,
|
||||
directory,
|
||||
diagrams,
|
||||
diagrams-lib,
|
||||
diagrams-cairo,
|
||||
ihaskell
|
||||
|
||||
-- Directories containing source files.
|
||||
-- hs-source-dirs:
|
||||
|
||||
-- Base language which the package is written in.
|
||||
default-language: Haskell2010
|
Loading…
x
Reference in New Issue
Block a user