Code Monkey home page Code Monkey logo

graphvizanim's Introduction

GraphvizAnim

Build Status Binder DOI

GraphvizAnim is a tool to create simple animated graph visualizations; it is just a proof of concept, aimed mainly at teaching purposes. It is based on Graphviz for the graph rendering part and on ImageMagick for the animated gif generation. You can run the heap sort animation on-line using binder.

A graph animation is just a sequence of steps, a step is in turn one or more actions such as: add, hilight, label, unlabel or remove a node, and add, hilight, or remove an edge. Animations can be built by invoking suitable methods of a gvanim.Animation object (in a Python program), or by parsing a simple text file (that, in turn, can be generated by a program in any language).

The examples folder contains few instances of such approaches. After installing the package with python setup.py install, or using

pip install GraphvizAnim

you can generate an animated depth first visit (in a 3-regular random graph of 6 nodes) by running

python examples/dfv.py

or you can generate the simple animation described in simple.txt as

python -m gvanim examples/simple.txt simple

You can generate an Erdős–Rényi graph (with 10 nodes and edge probability 1/10) by running

cd examples
gcc -o er er.c
./er | python -m gvanim er

Finally, you can obain an interactive visualization of the heap sort algorithm using Jupyter by running

cd examples
jupyter notebook heapsort.ipynb

and running all the cells in order; or you can give a try to binder and watch the above animation actually running on-line.

graphvizanim's People

Contributors

dirk-thomas avatar javaclll avatar joilnen avatar mapio avatar raphaelwimmer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

graphvizanim's Issues

AttributeError: 'function' object has no attribute 'gif'

Hello guys,
I'm trying to launch the basic example simple.txt.

However I can't get it working, and I always get the following (or something similar):

Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/msoccio/.local/lib/python2.7/site-packages/gvanim/__main__.py", line 36, in <module>
    main()
  File "/home/msoccio/.local/lib/python2.7/site-packages/gvanim/__main__.py", line 33, in main
    render.gif( render.render( ga.graphs(), args.basename, 'png' ), args.basename, args.delay )
AttributeError: 'function' object has no attribute 'gif'

I have tried on

  • Windows with Cygwin, python 2.7 and python 3.6
  • Linux, cloning the package and doing the python build and python install
  • Linux, with the pip install

All give the same error.

Unlabeled Nodes cannot be removed

Since the label of a node is not set upon creation, RemoveNode fails on del steps[ -1 ].L[ self.v ]
For me, adding steps[ -1 ].L[ self.v ] = self.v in AddNode essentially fixed the problem, as did changing the RemoveNode-line to if self.v in steps[ -1 ].L: del steps[ -1 ].L[ self.v ]. The second fix seems cleaner to me.

Fix cropping in case of different size PNGs

Use something like

convert *png -gravity center -background white -extent 285x320  simple.gif

to fix the issue when node changing in size generate PNGs of different pixel size that result in a cropped GIF (thanks to @carlobellettini for noting this).

Missing how to load existing graph in examples

I just came across this project. It looks really good. However, there was one thing blocking me from trying it out. I didn't see in the examples how I could animate an existing graph. Is this not possible or was this feature just not showcased?

Consider use ordered set instead of set

demo

When drawing binary trees, it's better to keep nodes in order so that we can distinguish the left and right nodes.

and we also need graph [ordering="out"];

Make highlighting use an optional color (not just red)

Modify the way highlighting is handled: instead of using a set (to keep track of highlighted nodes/edges), use a dict to map highlighted nodes/edges to their color (and add an optional parameter to the highlight methods).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.