lib/yagraphlib.rb in yagraphlib-1.1.0 vs lib/yagraphlib.rb in yagraphlib-1.2.0
- old
+ new
@@ -41,10 +41,11 @@
RANKDIR_LR = "LR"
def initialize()
@nodes = {}
@edges = {}
+ @subgraphs = {}
end
def edges(edge)
@edges[edge.uid] ||= edge
end
@@ -57,10 +58,14 @@
def nodes(node)
@nodes[node.uid] ||= node
end
+ def subgraph(subgraph)
+ @subgraphs[subgraph.uid] ||= subgraph
+ end
+
def rankdir(mode)
@rankdir = mode
end
def initial_nodes()
@@ -82,13 +87,32 @@
end
def to_graphviz(out)
out.puts("digraph main {\n")
out.puts(" rankdir=#{@rankdir}") if @rankdir
+ @subgraphs.each {|k, s| s.to_graphviz(out) }
@nodes.each {|k, n| n.to_graphviz(out) }
@edges.each {|k, e| e.to_graphviz(out) }
out.puts("}")
end
+ end
+
+ class SubGraph < Graph
+ def initialize()
+ super()
+ end
+
+ def is_cluster() false end
+
+ def to_graphviz(out)
+ out.puts(" subgraph #{if is_cluster() then "cluster_" else "" end}#{uid()} {")
+ if label() then out.puts(" label=\"#{label()}\"") end
+ @nodes.each {|k, n| out.write(" "); n.to_graphviz(out) }
+ @edges.each {|k, e| out.write(" "); e.to_graphviz(out) }
+ out.puts(" }")
+ end
+
+ def label() nil end
end
class Node < Element
def id() "" end
def to_graphviz(out)