Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tiago Peixoto
graph-tool
Commits
2092c3c6
Commit
2092c3c6
authored
Jan 24, 2015
by
Tiago Peixoto
Browse files
Include interactive visualization demo
parent
c9fca17b
Changes
2
Hide whitespace changes
Inline
Side-by-side
doc/demos/animation.rst
View file @
2092c3c6
...
...
@@ -155,7 +155,7 @@ format <http://www.webmproject.org>`_:
.. code-block:: bash
$ mencoder mf://frames/dancing*.png -mf w=500:h=400:type=png -ovc raw -of rawvideo -vf format=i420 -nosound -o dancing.yuy
$ vpxenc
sirs
.yuy -o dancing.webm -w 500 -h 400 --fps=100/1 --target-bitrate=5000 --good --threads=4
$ vpxenc
dancing
.yuy -o dancing.webm -w 500 -h 400 --fps=100/1 --target-bitrate=5000 --good --threads=4
.. doctest::
...
...
@@ -175,4 +175,58 @@ The resulting animation can be downloaded :download:`here
<div style="text-align:center">
<video id="sirs" src="../_downloads/dancing.webm" controls></video>
</div>
\ No newline at end of file
</div>
Interactive visualizations
--------------------------
Here we show an example of interactive visualization where the BFS tree
of the currently selected vertex is highlighted with a different color.
The script which performs the visualization is called
:download:`interactive_bst.py <interactive_bst.py>` and is shown
below. When called, it will open an interactive window.
.. literalinclude:: interactive_bst.py
:linenos:
.. code-block:: bash
$ ./interactive_bst.py offscreen
.. doctest::
:hide:
>>> import subprocess
>>> subprocess.call(["demos/interactive_bst.py", "offscreen"])
0
The above script is interactive, i.e. it expects a reaction from the
user. But for the purpose of this demo, it also saves the frames to a
file, so we can encode the animation with the `WebM format
<http://www.webmproject.org>`_:
.. code-block:: bash
$ mencoder mf://frames/bfs*.png -mf w=500:h=400:type=png -ovc raw -of rawvideo -vf format=i420 -nosound -o bfs.yuy
$ vpxenc bfs.yuy -o bfs.webm -w 500 -h 400 --fps=5/1 --target-bitrate=5000 --good --threads=4
.. doctest::
:hide:
>>> import subprocess
>>> subprocess.call("mencoder mf://frames/bfs*.png -mf w=500:h=400:type=png -ovc raw -of rawvideo -vf format=i420 -nosound -o demos/bfs.yuy".split())
0
>>> subprocess.call("vpxenc demos/bfs.yuy -o demos/bfs.webm -w 500 -h 400 --fps=5/1 --target-bitrate=2000 --good --threads=4".split())
0
The resulting animation can be downloaded :download:`here
<bfs.webm>`, or played below if your browser supports WebM.
.. raw:: html
<div style="text-align:center">
<video id="sirs" src="../_downloads/bfs.webm" controls></video>
</div>
src/graph_tool/draw/gtk_draw.py
View file @
2092c3c6
...
...
@@ -656,14 +656,10 @@ class GraphWidget(Gtk.DrawingArea):
self
.
queue_draw
()
if
self
.
drag_begin
is
None
:
self
.
drag_begin
=
[
x
,
y
]
return
True
if
(
event
.
button
==
2
or
elif
(
event
.
button
==
2
or
(
event
.
button
==
1
and
state
&
Gdk
.
ModifierType
.
CONTROL_MASK
)):
self
.
panning
=
(
event
.
x
,
event
.
y
)
return
True
if
event
.
button
==
3
:
elif
event
.
button
==
3
:
if
isinstance
(
self
.
picked
,
PropertyMap
):
self
.
picked
=
None
self
.
selected
.
fa
=
False
...
...
@@ -672,7 +668,6 @@ class GraphWidget(Gtk.DrawingArea):
self
.
picked
=
False
self
.
selected
.
fa
=
False
self
.
queue_draw
()
return
True
def
button_release_event
(
self
,
widget
,
event
):
r
"""Handle button release."""
...
...
@@ -710,13 +705,9 @@ class GraphWidget(Gtk.DrawingArea):
self
.
moved_picked
=
False
self
.
regenerate_surface
(
timeout
=
100
)
self
.
queue_draw
()
return
True
if
event
.
button
==
2
:
elif
event
.
button
==
2
:
self
.
panning
=
None
self
.
queue_draw
()
return
True
def
motion_notify_event
(
self
,
widget
,
event
):
r
"""Handle pointer motion."""
...
...
@@ -775,7 +766,6 @@ class GraphWidget(Gtk.DrawingArea):
self
.
queue_draw
()
self
.
picked
=
v
self
.
selected
[
v
]
=
True
return
True
def
scroll_event
(
self
,
widget
,
event
):
r
"""Handle scrolling."""
...
...
@@ -845,21 +835,20 @@ class GraphWidget(Gtk.DrawingArea):
self
.
moved_picked
=
True
self
.
queue_draw
()
return
True
def
key_press_event
(
self
,
widget
,
event
):
r
"""Handle key press."""
#print event.keyval
if
event
.
keyval
==
114
:
if
event
.
keyval
==
ord
(
'r'
)
:
self
.
fit_to_window
()
self
.
regenerate_surface
(
timeout
=
50
)
self
.
queue_draw
()
elif
event
.
keyval
==
115
:
elif
event
.
keyval
==
ord
(
's'
)
:
self
.
reset_layout
()
elif
event
.
keyval
==
97
:
elif
event
.
keyval
==
ord
(
'a'
)
:
self
.
apply_transform
()
elif
event
.
keyval
==
112
:
elif
event
.
keyval
==
ord
(
'p'
)
:
if
self
.
picked
==
False
:
self
.
init_picked
()
else
:
...
...
@@ -867,13 +856,12 @@ class GraphWidget(Gtk.DrawingArea):
self
.
selected
.
fa
=
False
self
.
vertex_matrix
=
None
self
.
queue_draw
()
elif
event
.
keyval
==
0x7a
:
elif
event
.
keyval
==
ord
(
'z'
)
:
if
isinstance
(
self
.
picked
,
PropertyMap
):
u
=
GraphView
(
self
.
g
,
vfilt
=
self
.
picked
)
self
.
fit_to_window
(
g
=
u
)
self
.
regenerate_surface
(
timeout
=
50
)
self
.
queue_draw
()
return
True
def
key_release_event
(
self
,
widget
,
event
):
r
"""Handle release event."""
...
...
@@ -883,12 +871,11 @@ class GraphWidget(Gtk.DrawingArea):
self
.
key_press_user_callback
(
self
.
g
,
event
.
keyval
,
self
.
picked
,
self
.
pos
,
self
.
vprops
,
self
.
eprops
)
if
event
.
keyval
==
65507
:
if
event
.
keyval
==
65507
:
# Control_L
if
self
.
moved_picked
:
self
.
moved_picked
=
False
self
.
regenerate_surface
(
timeout
=
100
)
self
.
queue_draw
()
return
True
class
GraphWindow
(
Gtk
.
Window
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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