예제 #1
0
graph_file = open("b+tree50.g", "r")

nodes = []
max_level = 0
for line in graph_file:
    match = re.match(r'(\s*)\| (\d+) \|( (\d) \|)?', line)
    node = {'level': len(match.group(1)), 'from': match.group(2)}
    if len(match.group(1)) > max_level: max_level = len(match.group(1))
    if not match.group(4) == None: node['to'] = match.group(4)
    else: node['to'] = '-'
    nodes.append(node)

width = 640
height = 320
canvas = Canvas(width, height, 0.1, 100)
    
#nodes.reverse()
node = nodes[0]
x = 1
y = 1
title = str(node['from'])
if 'to' in node: title += ' ' + str(node['to'])
master = Point(x, y, 100, title = title)
node_chain = [(node, master)]
canvas.points.append(master)
i = 1
for node in nodes[1:]:
    i+=1
    y = node['level']*(height-1)/max_level
    x = i*(width-1)/len(nodes)
예제 #2
0
graph_file = open(sys.argv[1], "r")

nodes = {}
for line in graph_file:
    line = line.strip()
    match = re.match(r'([^\s])\s([^\s])', line)
    if not match: print "Malformed line: '%s'" % line
    node_from_id = match.group(1)
    node_to_id = match.group(2)
    for id in (node_from_id, node_to_id):
        if not id in nodes: nodes[id] = {'links': []}
    nodes[node_from_id]['links'].append(node_to_id)

width = 640
height = 320
canvas = Canvas(width, height, 0.1, 10000)
    
#nodes.reverse()
i = 0
for node in nodes:
    i+=1.0

    y = r.randint(1, height-1)#float((i % r)+1)/(r+1)*height
    x = r.randint(1, width-1)#float((i % r)+1)/(r+1)*width
    print x, y
    p = Point(x, y, 10000, title = node[:5])
    canvas.points.append(p)
    nodes[node]['p'] = p

for node in nodes:
    for dest in nodes[node]['links']: