Drawing Library for Ruby

Pascal picture Pascal · Aug 14, 2008 · Viewed 10.7k times · Source

I am trying to code a flowchart generator for a language using Ruby.

I wanted to know if there were any libraries that I could use to draw various shapes for the various flowchart elements and write out text to those shapes.

I would really prefer not having to write code for drawing basic shapes, if I can help it.

Can someone could point me to some reference documentation with examples of using that library?

Answer

rampion picture rampion · Dec 23, 2008

Write up your flowchart as a directed or undirected graph in Graphviz. Graphviz has a language, dot that makes it easy to generate graphs. Just generate the dot file, run it through Graphiviz, and you get your image.

graph {
  A -- B -- C;
  B -- D;
  C -- D [constraint=false];
}

renders as
undirected

digraph {
  A [label="start"];
  B [label="eat"];
  C [label="drink"];
  D [label="be merry"];

  A -> B -> C;
  C -> D [constraint=false];
  B -> D [ arrowhead=none, arrowtail=normal]; // reverse this edge
}

renders as
directed

You can control node shapes and much more in Graphviz.