Question

I have a program that will generate a very large dictionary-style list that would look something like this:

{"a":"b",
 "b":"c",
 "C":"d",
 "d":"b",
 "d":"e"}

I would like to create a program using something like pygame to generate a flowchart that connects all of the first terms to the last terms using arrows. This would ignore repeated connections and generate loops of items if they doubled back on themselves.

If the above list was processed, it would look like this (excuse the hand drawing): enter image description here

Was it helpful?

Solution

Using Graph Tool:

from graph_tool.all import *

g = Graph()

vals = [("a","b"), ("b","c"), ("c","d"), ("d","b"), ("c","e")]

vertexes_names = g.new_vertex_property("string") 
vertexes = {}
for start, stop in vals:
    if start not in vertexes:
        vertexes[start] = g.add_vertex()
        vertexes_names[vertexes[start]] = start
    if stop not in vertexes:
        vertexes[stop] = g.add_vertex()
        vertexes_names[vertexes[stop]] = stop
    g.add_edge(vertexes[start], vertexes[stop])

graph_tool.stats.remove_parallel_edges(g)
graph_draw(g, vertex_text=vertexes_names, vertex_font_size=18, output="output.png")

enter image description here

OTHER TIPS

When I needed to do this, I used pydot and graphviz

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top