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
05991356
Commit
05991356
authored
Mar 07, 2018
by
Justus Sagemüller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow animations to be sized with the same functions as diagrams.
parent
df0be6b8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
11 deletions
+28
-11
Animation.hs
.../ihaskell-diagrams/IHaskell/Display/Diagrams/Animation.hs
+28
-11
No files found.
ihaskell-display/ihaskell-diagrams/IHaskell/Display/Diagrams/Animation.hs
View file @
05991356
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
module
IHaskell.Display.Diagrams.Animation
(
animation
)
where
module
IHaskell.Display.Diagrams.Animation
(
animation
)
where
...
@@ -11,15 +12,16 @@ import Diagrams.Backend.Cairo.CmdLine (GifOpts(..))
...
@@ -11,15 +12,16 @@ import Diagrams.Backend.Cairo.CmdLine (GifOpts(..))
import
Diagrams.Backend.CmdLine
(
DiagramOpts
(
..
),
mainRender
)
import
Diagrams.Backend.CmdLine
(
DiagramOpts
(
..
),
mainRender
)
import
IHaskell.Display
import
IHaskell.Display
import
IHaskell.Display.Diagrams.ImgSize
instance
IHaskellDisplay
(
QAnimation
Cairo
V2
Double
Any
)
where
instance
IHaskellDisplay
(
ManuallySized
(
QAnimation
Cairo
V2
Double
Any
)
)
where
display
renderable
=
do
display
renderable
=
do
gif
<-
animationData
renderable
gif
<-
animationData
renderable
return
$
Display
[
html
$
"<img src=
\"
data:image/gif;base64,"
return
$
Display
[
html
$
"<img src=
\"
data:image/gif;base64,"
++
gif
++
"
\"
/>"
]
++
gif
++
"
\"
/>"
]
animationData
::
Animation
Cairo
V2
Double
->
IO
String
animationData
::
ManuallySized
(
Animation
Cairo
V2
Double
)
->
IO
String
animationData
renderable
=
do
animationData
(
ManuallySized
renderable
imgWidth
imgHeight
)
=
do
switchToTmpDir
switchToTmpDir
-- Generate the frames
-- Generate the frames
...
@@ -29,14 +31,6 @@ animationData renderable = do
...
@@ -29,14 +31,6 @@ animationData renderable = do
timediff
=
100
`
div
`
ceiling
fps
::
Int
timediff
=
100
`
div
`
ceiling
fps
::
Int
frameSet
=
map
(
\
x
->
(
x
#
bg
white
,
timediff
))
frames
frameSet
=
map
(
\
x
->
(
x
#
bg
white
,
timediff
))
frames
-- Compute width and height.
let
shape
=
activeStart
animAdjusted
w
=
width
shape
h
=
height
shape
aspect
=
w
/
h
imgHeight
=
300
imgWidth
=
aspect
*
imgHeight
-- Write the image.
-- Write the image.
let
filename
=
".ihaskell-diagram.gif"
let
filename
=
".ihaskell-diagram.gif"
diagOpts
=
DiagramOpts
diagOpts
=
DiagramOpts
...
@@ -54,3 +48,26 @@ animationData renderable = do
...
@@ -54,3 +48,26 @@ animationData renderable = do
-- Rendering hint.
-- Rendering hint.
animation
::
Animation
Cairo
V2
Double
->
Animation
Cairo
V2
Double
animation
::
Animation
Cairo
V2
Double
->
Animation
Cairo
V2
Double
animation
=
id
animation
=
id
instance
(
b
~
Cairo
,
v
~
V2
,
s
~
Double
,
m
~
Any
)
=>
ManuallySizeable
(
QAnimation
b
v
s
m
)
where
withSizeSpec
spec
renderable
=
ManuallySized
renderable
imgWidth
imgHeight
where
fps
=
30
shape
=
activeStart
$
animEnvelope'
fps
renderable
aspect
=
width
shape
/
height
shape
V2
imgWidth
imgHeight
=
case
getSpec
spec
of
V2
(
Just
w
)
(
Just
h
)
->
V2
w
h
V2
(
Just
w
)
Nothing
->
V2
w
(
w
/
aspect
)
V2
Nothing
(
Just
h
)
->
V2
(
aspect
*
h
)
h
V2
Nothing
Nothing
->
(
defaultDiagonal
/
sqrt
(
1
+
aspect
^
2
))
*^
V2
aspect
1
-- w^2 + h^2 = defaultDiagonal^2 / (1+aspect^2)
-- * (aspect^2 + 1)
-- = defaultDiagonal^2
-- w/h = aspect/1 = aspect
defaultDiagonal
=
500
instance
IHaskellDisplay
(
QAnimation
Cairo
V2
Double
Any
)
where
display
=
display
.
withSizeSpec
(
mkSizeSpec2D
Nothing
Nothing
)
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