My favorites | Sign in
Project Logo
                
Search
for
Updated Sep 30, 2009 by Jose.R.Fonseca
Labels: Script, Python, Featured
XDot  
Interactive viewer for Graphviz dot files

About

xdot.py is an interactive viewer for graphs written in Graphviz's dot language.

It uses internally the graphviz's xdot output format as an intermediate format, and PyGTK and Cairo for rendering.

xdot.py can be used either as a standalone application from command line, or as a library embedded in your python application.

Status

Features

Changelog

  • 2009-09-30: Add a reload button (fixes  issue #22 )
  • 2009-09-30: Properly handle motion-notify-event (from lodatom,  issue #24 )
  • 2009-09-20: Automatically reloads open file when it changes (from Robert Meerman,  issue #21 )
  • 2009-09-20: Add support for ColorBrewer Color Schemes (from to michael.hliao,  issue #23 ).
  • 2009-08-09: Upload to PyPi (thanks to Marius Gedminas,  issue #19 )
  • 2009-05-24: Reloads the file on the 'r' key (from peterbjorgensen).
  • 2009-04-09: Render subgraphs correctly.
  • 2009-03-04: Support filled bezier shapes.
  • 2009-01-29: Check for unicode input; check subprocess returncode (from Jaap Karssenberg).
  • 2008-10-27: Replace pydot and pyparsing by a much faster hand written lexer and parser ( issue #9 ).
  • 2008-09-02: Make mouse wheel zoom around the mouse cursor rather than center of window (from Marius Gedminas).
  • 2008-09-02: Handle polylines. Handle ports in node names.
  • 2008-07-27: Allow to specify the graphviz filter to use.
  • 2008-07-13: Commit several enhancements done by Marius Gedminas, such as, animated jumping between nodes, highlighted node/edge under mouse, and support to more xdot language features.

Known Issues

Screenshots

Requirements

Windows users

Debian/Ubuntu users

Usage

Command Line

Usage: 
	xdot.py [file]

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -f FILTER, --filter=FILTER
                        graphviz filter: dot, neato, twopi, circo, or fdp
                        [default: dot]

If no input file is given then it will read the dot graph from the standard input.

Shortcuts

Embedding

Sample code

#!/usr/bin/env python

import gtk
import gtk.gdk

import xdot

class MyDotWindow(xdot.DotWindow):

    def __init__(self):
        xdot.DotWindow.__init__(self)
        self.widget.connect('clicked', self.on_url_clicked)

    def on_url_clicked(self, widget, url, event):
        dialog = gtk.MessageDialog(
                parent = self, 
                buttons = gtk.BUTTONS_OK,
                message_format="%s clicked" % url)
        dialog.connect('response', lambda dialog, response: dialog.destroy())
        dialog.run()
        return True

dotcode = """
digraph G {
  Hello [URL="http://en.wikipedia.org/wiki/Hello"]
  World [URL="http://en.wikipedia.org/wiki/World"]
    Hello -> World
}
"""

def main():
    window = MyDotWindow()
    window.set_dotcode(dotcode)
    window.connect('destroy', gtk.main_quit)
    gtk.main()

if __name__ == '__main__':
    main()

Result

Download

Links


Comment by mgedmin, Jul 10, 2008

Having spent today immersed in pypy's dotviewer's internals I can tell that it doesn't use 'xdot' as the intermediate format; it uses the simplest and most crippled 'plain' format, and that causes problems.

Comment by darethehair, Jan 05, 2009

This is so cool! I have experimentally compiled Graphviz for the Maemo operating system, put it on my Nokia N800, and then used 'xDot' to successfully navigate around some sample 'dot' files with it! To enable the use of the device's zoom buttons, I added some F7 and F8 'keysymbs'. Does xDot use the GPL license?

Comment by Jose.R.Fonseca, Jan 06, 2009

darethehair,

XDot uses the LGPL license, which means you can use it in closed source projects as long as the xdot module itself is kept open source. Of course, it is difficult to conceive closed source python software unless one goes out of its way and uses byte code, or code obfuscators, etc.

Comment by shamal.faily, Jan 09, 2009

I do like this tool. Well done! I'm actually using this inside a wxPython application of all places, as this seems to be a nice alternative to the wx floatcanvas package.

The only comment I have is that shapefile nodes aren't supported, as XDotAttrParser::parse writes "unknown xdot opcode 'I' " when it encounters the draw field . If I had the time to dig around the internals (alas there are only 24 in the day) I would have a shot at trying to implement this myself. In the meantime, if you are looking for more xdot features to implement, you could do a lot worse than add shapefile support :-)

Comment by Metal3d, Jan 12, 2009

Really good !!!

I now can see my UML that I create parsing PHP files easier than before. Now you only have to implement an editor on the left :)

Comment by arpad.zsuzsi, Mar 30, 2009

I downloaded version 0.4 from SVN. But the sample.py have not worked for me earlier. I changed two rows in 3 places (filled=True; handle_ellipse; EllipseShape?), and now it works well. (Upper rows are the good rows.)

$ diff xdot.py xdot2.py 
625c625
<     def handle_ellipse(self, x0, y0, w, h, filled=True):
---
>     def handle_ecllipse(self, x0, y0, w, h):
629c629
<         self.shapes.append(EllipseShape(self.pen, x0, y0, w, h))
---
>         self.shapes.append(EclipseShape(self.pen, x0, y0, w, h))

I like it.

Comment by Jose.R.Fonseca, Mar 30, 2009

Thanks arpad. I really need to make a testsuite to catch this kind of problems earlier on.

Comment by eldmannen, Apr 03, 2009

Please provide some more samples.

How do I add a node? Does it have to re-process all the code i want to add a node? Can I remove a node?

Comment by Jose.R.Fonseca, Apr 04, 2009

eldmannen,

Xdot.py is just a viewer for graphviz's dot language. It does not support editing. To change the graph you'll need to regenerate another dot file.

See http://www.graphviz.org/Documentation.php for the dot languange documentation and examples; and see http://code.google.com/p/yapgvb/ , http://software.inl.fr/trac/wiki/GvGen , and http://code.google.com/p/pydot/ for python libraries that can help generate those graphs in the dot language.

Comment by peterbjorgensen, Apr 24, 2009

Hey very cool and fairly lightweight (no JAVA yaaay \o/ :D) dot viewer. I've made a tiny patch that reloads the file on the 'r' key and I find it quite useful :) It would be even nicer if it was able to watch the file for changes automatically. Maybe I'll add that later.

1553a1554,1558
>         if event.keyval == gtk.keysyms.r:
>             win = self.get_toplevel()
>             if win.openfilename is not None:
>                 win.open_file(win.openfilename)
>             return True
1713a1719,1720
>         
>         self.openfilename = None
1731a1739
>             self.openfilename = filename
Comment by butterfoss, Apr 27, 2009

Great tool, very light weight. I hacked in a "Find" button to search through node text. I've never used gtk or python before so its probably a little rough, but it does work. Any where I can send code back to contribute?

Comment by Jose.R.Fonseca, Apr 27, 2009

butterfoss,

Please open an issue and attached a patch or the modified source code.

Comment by amascarell, Jun 30, 2009

Simplemente, es perfecto. Justo lo que andaba buscando.

Comment by gandalfmeister, Sep 07, 2009

It doesn't work for me - this is what happened... Graham

graham@graham-laptop:~$ sudo apt-get install python-gtk2 graphviz sudo? password for graham: Reading package lists... Done Building dependency tree Reading state information... Done python-gtk2 is already the newest version. graphviz is already the newest version. 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. graham@graham-laptop:~$ cd bin graham@graham-laptop:~/bin$ xdot.py test2.dot Traceback (most recent call last):

File "/home/graham/bin/xdot.py", line 1804, in <module>
main()
File "/home/graham/bin/xdot.py", line 1799, in main
win.open_file(args0?)
File "/home/graham/bin/xdot.py", line 1742, in open_file
self.set_dotcode(fp.read(), filename)
File "/home/graham/bin/xdot.py", line 1730, in set_dotcode
if self.widget.set_dotcode(dotcode, filename):
File "/home/graham/bin/xdot.py", line 1401, in set_dotcode
xdotcode, error = p.communicate(dotcode)
File "/usr/lib/python2.6/subprocess.py", line 663, in communicate
return self.communicate(input)
File "/usr/lib/python2.6/subprocess.py", line 1163, in communicate
bytes_written = os.write(self.stdin.fileno(), chunk)
OSError: 32? Broken pipe graham@graham-laptop:~/bin$

Comment by kaskaras, Sep 13, 2009

Hi,

thanks very much for this dot visor but how can I handle node clicks? I'd like to click in some node and call some method. Is it possible?

Regards

Comment by ondrej.mikle, Sep 14, 2009

Very usable stuff.

I have based a profiler visualizer SleepyGraph on XDot: http://sleepygraph.sourceforge.net/

It visualizes measurements from VerySleepy profiler.

To adapt SleepyGraph to another profiler input, just 3 classes need to be modified - Symbol, Callstack and Database - to be able to parse/load inputs of different format.

Comment by Jose.R.Fonseca, Sep 20, 2009

kaskaras,

The sample code above does what you want.

Comment by Jose.R.Fonseca, Sep 20, 2009

gandalfmeister,

Broken pipe means that the dot process died prematurely. Perhaps graphviz is not in the path, or properly installed, or the dot input is wrong in some way.

Comment by a.tarun, Oct 08, 2009

Can this be converted to an editor? Do you have any plans for that?

Comment by Jose.R.Fonseca, Oct 08, 2009

a.tarun,

No, no plans to convert into an editor. Most use I have for xdot.py is just visualization of graphviz graphs generated automatically from other data.


Sign in to add a comment
Hosted by Google Code