Skip to content

Commit 52f1891

Browse files
committed
Testing a Binder connection
1 parent e7c9499 commit 52f1891

7 files changed

Lines changed: 124 additions & 3 deletions

File tree

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM andrewosh/binder-base
2+
MAINTAINER Massimo Santini <massimo.santini@gmail.com>
3+
RUN apt-get -y update && apt-get install -y graphviz

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ finally, you can generate an [Erdős–Rényi](https://en.wikipedia.org/wiki/Erd
3939
gcc -o er er.c
4040
./er | python -m gvanim er
4141

42+
## With Jupyter
43+
44+
[![Binder](http://mybinder.org/badge.svg)](http://mybinder.org/repo/mapio/GraphvizAnim)
45+
46+
4247
## Todo
4348

4449
Any help will be appreciated. Things to do to make this more usable are:

gvanim/animation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ def graphs( self ):
131131
graphs = []
132132
for n, s in enumerate( steps ):
133133
graph = [ 'digraph G {' ]
134-
for v in V: graph.append( '"{}" {};'.format( quote( v ), s.node_format( v ) ) )
135-
for e in E: graph.append( '"{}" -> "{}" {};'.format( quote( e[ 0 ] ), quote( e[ 1 ] ), s.edge_format( e ) ) )
134+
for v in V: graph.append( '"{}" {};'.format( quote( str( v ) ), s.node_format( v ) ) )
135+
for e in E: graph.append( '"{}" -> "{}" {};'.format( quote( str( e[ 0 ] ) ), quote( str( e[ 1 ] ) ), s.edge_format( e ) ) )
136136
graph.append( '}' )
137137
graphs.append( '\n'.join( graph ) )
138138
return graphs

gvanim/jupyter.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2016, Massimo Santini <santini@di.unimi.it>
2+
#
3+
# This file is part of "GraphvizAnim".
4+
#
5+
# "GraphvizAnim" is free software: you can redistribute it and/or modify it
6+
# under the terms of the GNU General Public License as published by the Free
7+
# Software Foundation, either version 3 of the License, or (at your option) any
8+
# later version.
9+
#
10+
# "GraphvizAnim" is distributed in the hope that it will be useful, but
11+
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13+
# details.
14+
#
15+
# You should have received a copy of the GNU General Public License along with
16+
# "GraphvizAnim". If not, see <http://www.gnu.org/licenses/>.
17+
18+
from os.path import join
19+
from tempfile import mkdtemp
20+
from shutil import rmtree
21+
22+
from IPython.display import SVG
23+
import ipywidgets as widgets
24+
25+
from render import render
26+
27+
def interactive( animation ):
28+
basedir = mkdtemp()
29+
basename = join( basedir, 'graph' )
30+
steps = [ SVG( path ) for path in render( animation.graphs(), basename, 'svg' ) ]
31+
rmtree( basedir )
32+
slider = widgets.IntSlider( min = 0, max = len( steps ) - 1, step = 1, value = 0 )
33+
return widgets.interactive( lambda n: steps[ n ], n = slider )

gvanim/render.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from subprocess import Popen, PIPE, STDOUT, call
1919

20-
def render( graphs, basename, fmt ):
20+
def render( graphs, basename, fmt = 'png' ):
2121
paths = []
2222
for n, graph in enumerate( graphs ):
2323
path = '{}_{:03}.{}'.format( basename, n, fmt )

index.ipynb

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 51,
6+
"metadata": {
7+
"collapsed": false
8+
},
9+
"outputs": [
10+
{
11+
"data": {
12+
"image/svg+xml": [
13+
"<svg height=\"188pt\" viewBox=\"0.00 0.00 89.00 188.00\" width=\"89pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
14+
"<g class=\"graph\" id=\"graph0\" transform=\"scale(1 1) rotate(0) translate(4 184)\">\n",
15+
"<title>G</title>\n",
16+
"<polygon fill=\"white\" points=\"-4,4 -4,-184 85,-184 85,4 -4,4\" stroke=\"none\"/>\n",
17+
"<!-- 1 -->\n",
18+
"<g class=\"node\" id=\"node1\"><title>1</title>\n",
19+
"<ellipse cx=\"54\" cy=\"-162\" fill=\"none\" rx=\"27\" ry=\"18\" stroke=\"black\"/>\n",
20+
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"54\" y=\"-158.3\">1</text>\n",
21+
"</g>\n",
22+
"<!-- 2 -->\n",
23+
"<g class=\"node\" id=\"node2\"><title>2</title>\n",
24+
"<ellipse cx=\"27\" cy=\"-90\" fill=\"none\" rx=\"27\" ry=\"18\" stroke=\"black\"/>\n",
25+
"<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"27\" y=\"-86.3\">2</text>\n",
26+
"</g>\n",
27+
"<!-- 1&#45;&gt;2 -->\n",
28+
"<g class=\"edge\" id=\"edge1\"><title>1-&gt;2</title>\n",
29+
"<path d=\"M47.6014,-144.411C44.4864,-136.335 40.6663,-126.431 37.1654,-117.355\" fill=\"none\" stroke=\"black\"/>\n",
30+
"<polygon fill=\"black\" points=\"40.4045,-116.027 33.5403,-107.956 33.8735,-118.546 40.4045,-116.027\" stroke=\"black\"/>\n",
31+
"</g>\n",
32+
"<!-- 3 -->\n",
33+
"<!-- 2&#45;&gt;3 -->\n",
34+
"<!-- 3&#45;&gt;1 -->\n",
35+
"</g>\n",
36+
"</svg>"
37+
],
38+
"text/plain": [
39+
"<IPython.core.display.SVG object>"
40+
]
41+
},
42+
"metadata": {},
43+
"output_type": "display_data"
44+
}
45+
],
46+
"source": [
47+
"import gvanim\n",
48+
"ga = gvanim.Animation()\n",
49+
"ga.add_edge(1,2)\n",
50+
"ga.next_step()\n",
51+
"ga.add_edge(2,3)\n",
52+
"ga.next_step()\n",
53+
"ga.add_edge(3,1)\n",
54+
"interactive( ga )"
55+
]
56+
}
57+
],
58+
"metadata": {
59+
"kernelspec": {
60+
"display_name": "Python 2",
61+
"language": "python2",
62+
"name": "python2"
63+
},
64+
"language_info": {
65+
"codemirror_mode": {
66+
"name": "ipython",
67+
"version": 2
68+
},
69+
"file_extension": ".py",
70+
"mimetype": "text/x-python",
71+
"name": "python",
72+
"nbconvert_exporter": "python",
73+
"pygments_lexer": "ipython2",
74+
"version": "2.7.11"
75+
}
76+
},
77+
"nbformat": 4,
78+
"nbformat_minor": 0
79+
}

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/mapio/GraphvizAnim/archive/master.zip

0 commit comments

Comments
 (0)