Nice graphs from class hierarchies?

Roman Suzi rnd at onego.ru
Tue Jul 17 00:45:26 EDT 2001


Hello!

I want to have nice graphs from Python class hierarchies.  The daVinci
package can do it (see the program below for Exception class tree), but
the quality is not good enough.

Does anyone know any other tool which can help automatically draw graphs
(or only trees) with ability to output to PS?

I need to set font, size and elements order. DaVinci is nice but it puts
lines OVER boxes and I have not found way to control aspects of
font and size.

Dia and Sketch are nice, but I am not into developing graph layout
algorithms...

Oh, forgot to mention: I need this solution under Linux and Open Source of
course. I also tried some packages for TeX/LaTeX, but have not found
anything easier.

If not trees (graphs) what is another nice way to visualise
a tree? (apart from kind of:

root
  node1
    leaf1.1
    leaf1.2
  node2
    node2.1
       ...
...

thingie?

Any help appreciated!

The below is a script which could be then feed to daVinci:
--------------------------------------------------------------
#!/usr/bin/env python2.0
#!/usr/bin/env python1.5
#!/usr/bin/env python2.1

# Exception class hiearachy -> daVinci input
# This piece of code contributed as-is to Public Domain by Roman A. Suzi
# Use at your own risk!

import types

d = {}
for i in dir(__builtins__):
  if types.ClassType == type(eval(i)) \
     and issubclass(eval(i), Exception):
    k = map(lambda x: x.__name__,
               eval(i).__bases__)
    # print "%20s"%i, k
    if k:
      try:
        d[k[0]].append(i)
      except:
        d[k[0]] = [i]
    else:
      root = i

#print d

def give_list(r):
  ll = [r]
  ll1 = []
  if d.has_key(r):
    for i in d[r]:
      ll1.append(give_list(i))
  return ll + ll1

#print give_list(root)

import string
def davinci(l):
  name = l[0]
  if len(l) == 1:
    return """l("%(name)s",n("",[a("OBJECT","%(name)s")],[]))""" % vars()
  else:
    sub = []
    for child in l[1:]:
      subtree = davinci(child)
      childname = child[0]
      sub.append( """
      l("%(name)s->%(childname)s",
         e("%(name)s->%(childname)s",[],
             %(subtree)s
       ))""" %vars())
    sub = string.join(sub, ", ")
    return """l("%(name)s",n("",[a("OBJECT","%(name)s")],
    [
    %(sub)s
    ]
    ))""" % vars()


print "[", davinci(give_list(root)), "]"
-------------------------------------------------------------


Sincerely yours, Roman Suzi
-- 
_/ Russia _/ Karelia _/ Petrozavodsk _/ rnd at onego.ru _/
_/ Tuesday, July 17, 2001 _/ Powered by Linux RedHat 6.2 _/
_/ "...put knot yore trust inn spel chequers." _/





More information about the Python-list mailing list