Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
gargantext-ihaskell
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
gargantext-ihaskell
Commits
1f852097
Commit
1f852097
authored
Mar 04, 2018
by
Vaibhav Sagar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ihaskell-diagrams: make imgHeight configurable
parent
3d5cbb16
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
5 deletions
+11
-5
Diagrams.hs
...ll-display/ihaskell-diagrams/IHaskell/Display/Diagrams.hs
+11
-5
No files found.
ihaskell-display/ihaskell-diagrams/IHaskell/Display/Diagrams.hs
View file @
1f852097
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
module
IHaskell.Display.Diagrams
(
diagram
,
animation
)
where
module
IHaskell.Display.Diagrams
(
diagram
,
animation
,
imgHeight
)
where
import
qualified
Data.ByteString.Char8
as
Char
import
qualified
Data.ByteString.Char8
as
Char
import
System.Directory
import
System.Directory
import
System.IO.Unsafe
import
System.IO.Unsafe
import
Data.IORef
import
Diagrams.Backend.Cairo
import
Diagrams.Backend.Cairo
import
Diagrams.Prelude
import
Diagrams.Prelude
import
IHaskell.Display
import
IHaskell.Display
...
@@ -16,26 +17,31 @@ instance IHaskellDisplay (QDiagram Cairo V2 Double Any) where
...
@@ -16,26 +17,31 @@ instance IHaskellDisplay (QDiagram Cairo V2 Double Any) where
svg
<-
diagramData
renderable
SVG
svg
<-
diagramData
renderable
SVG
return
$
Display
[
png
,
svg
]
return
$
Display
[
png
,
svg
]
{-# NOINLINE imgHeight #-}
imgHeight
::
IORef
Double
imgHeight
=
unsafePerformIO
(
newIORef
300
)
diagramData
::
Diagram
Cairo
->
OutputType
->
IO
DisplayData
diagramData
::
Diagram
Cairo
->
OutputType
->
IO
DisplayData
diagramData
renderable
format
=
do
diagramData
renderable
format
=
do
switchToTmpDir
switchToTmpDir
imgHeight'
<-
readIORef
imgHeight
-- Compute width and height.
-- Compute width and height.
let
w
=
width
renderable
let
w
=
width
renderable
h
=
height
renderable
h
=
height
renderable
aspect
=
w
/
h
aspect
=
w
/
h
imgHeight
=
300
imgWidth
=
aspect
*
imgHeight'
imgWidth
=
aspect
*
imgHeight
-- Write the image.
-- Write the image.
let
filename
=
".ihaskell-diagram."
++
extension
format
let
filename
=
".ihaskell-diagram."
++
extension
format
renderCairo
filename
(
mkSizeSpec2D
(
Just
imgWidth
)
(
Just
imgHeight
))
renderable
renderCairo
filename
(
mkSizeSpec2D
(
Just
imgWidth
)
(
Just
imgHeight
'
))
renderable
-- Convert to base64.
-- Convert to base64.
imgData
<-
Char
.
readFile
filename
imgData
<-
Char
.
readFile
filename
let
value
=
let
value
=
case
format
of
case
format
of
PNG
->
png
(
floor
imgWidth
)
(
floor
imgHeight
)
$
base64
imgData
PNG
->
png
(
floor
imgWidth
)
(
floor
imgHeight
'
)
$
base64
imgData
SVG
->
svg
(
Char
.
unpack
imgData
)
SVG
->
svg
(
Char
.
unpack
imgData
)
return
value
return
value
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment