-
Notifications
You must be signed in to change notification settings - Fork 0
A small lib for generating GraphViz dot digraphs from ruby.
License
ander/digraph
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Digraph ======= A small lib for generating GraphViz dot digraphs from ruby. If you want to use a DSL-like definition for a graph, you can try e.g. graph = Digraph.new do a >> b['color=red'] >> c >> d c >> g end Where 'color=red' is an attribute of the node b. Or, you can do it like this: graph = Digraph::Graph.new a = graph.add_node('a') b = graph.add_node('b') b['color=red'] graph.add_edge(a,b) ... ----- If you need to add attributes to edges, use the E-method for wrapping the edge attributes along with the destination node Digraph.new do a >> E(b, 'style=dotted') >> c c >> E(d['shape=box'], 'label="required"') end or graph.add_edge(c, d, 'label="required"') ----- You can set the graph attributes with instance variables: Digraph.new do @size = "4,4" end Or using add_attribute: graph = Digraph::Graph.new graph.add_attribute("size", "4,4") ----- You can also give global attributes in a hash Digraph.new({:node => 'style=filled, fillcolor="#294b76"'}) do ... end ----- Subgraphs are also possible: Digraph.new do subgraph(:cluster0, {:node => 'style=filled,color=white'}) do @style = 'filled' @color = 'lightgrey' a0 >> a1 >> a2 >> a3 @label = "process #1" end subgraph(:cluster1, {:node => 'style=filled'}) do b0 >> b1 >> b2 >> b3 @label = "process #2" @color = 'blue' end start >> a0 start >> b0 a1 >> b3 b2 >> a3 a3 >> a0 a3 >> theend b3 >> theend start['shape=Mdiamond'] theend['shape=Msquare'] end ----- Write the graph by calling your graph's write-method. Change Digraph::GRAPH_DIR as needed. See the source. Cheers.
About
A small lib for generating GraphViz dot digraphs from ruby.
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published