|
|
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
- Since it doesn't use bitmaps it is fast and has a small memory footprint.
- Arbitrary zoom.
- Keyboard/mouse navigation.
- Supports events on the nodes with URLs.
Known Issues
- Not all xdot attributes are supported or correctly rendered yet. It works well for my applications but YMMV. Contributions are welcome.
- Text doesn't scale properly to large sizes if font hinting is enabled. I haven't find a reliable way to disable font hinting during rendering yet. Suggestions are welcome.
Screenshots
Requirements
Windows users
- Download and install Python for Windows
- Download and install the GTK+ Runtime for Windows
- Download and install PyCairo, PyGobject, and PyGTK for Windows
- Download and install Graphviz for Windows
- Download and run Easy Install script
- Install pyparsing via the Easy Install script:
C:\Python25\Scripts\easy_install.exe pyparsing
C:\Python25\Scripts\easy_install.exe -f http://code.enthought.com/enstaller/eggs/windows/xp pydot
Debian/Ubuntu users
- Run:
apt-get install python-gtk2 python-pyparsing python-pydot graphviz
Usage
Command Line
usage: xdot.py [file] options: --version show program's version number and exit -h, --help show this help message and exit
If no input file is given then it will read the dot graph from the standard input.
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
- Graphviz homepage
- ZGRViewer -- another superb graphviz/dot viewer
- The pypy project also includes an interactive dot viewer based on xdot format and the pygame library.
Sign in to add a comment




