Creating a new graph
var graph = new DotGraph("G", "digraph")
graph["rankdir"] = "BT"
graph["ranksep"] = 0.3
graph["nodesep"] = 0.3
graph.nodes_attrs["fontname"] = "helvetica"
graph.edges_attrs["color"] = "gray"
Creating subgraphs
var sub = new DotGraph("cluster_sub", "subgraph")
sub["label"] = "process #1"
var a0 = sub.add_node("a0")
var a1 = sub.add_node("a1")
sub.add_edge(a0, a1)
graph.add sub
dot :: DotGraph :: defaultinit
dot :: DotGraph :: edges_attrs=
Edges attributesdot :: DotGraph :: nodes_attrs=
Nodes attributescore :: Object :: class_factory
Implementation used byget_class
to create the specific class.
dot :: DotElement :: defaultinit
dot :: DotGraph :: defaultinit
core :: Object :: defaultinit
dot :: DotGraph :: edges_attrs=
Edges attributescore :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
dot :: DotGraph :: nodes_attrs=
Nodes attributescore :: Object :: output_class_name
Display class name on stdout (debug only).
# A Graph representation suited for dot format.
#
# Creating a new graph
# ~~~
# var graph = new DotGraph("G", "digraph")
# graph["rankdir"] = "BT"
# graph["ranksep"] = 0.3
# graph["nodesep"] = 0.3
# graph.nodes_attrs["fontname"] = "helvetica"
# graph.edges_attrs["color"] = "gray"
# ~~~
#
# Creating subgraphs
# ~~~
# var sub = new DotGraph("cluster_sub", "subgraph")
# sub["label"] = "process #1"
#
# var a0 = sub.add_node("a0")
# var a1 = sub.add_node("a1")
# sub.add_edge(a0, a1)
#
# graph.add sub
# ~~~
class DotGraph
super DotElement
# Graph kind like `graph`, `digraph`, `subgraph`...
var kind: String is writable
# Nodes attributes
var nodes_attrs = new AttributeMap
# Edges attributes
var edges_attrs = new AttributeMap
# Node list by id
var nodes = new HashMap[String, DotElement]
# Add a node to the graph
#
# If the graph already contains a node with that ID, it will be replaced.
fun add(element: DotElement) do
nodes[element.id] = element
end
# Edge list
#
# There can be multiple edges between the same couple of nodes.
var edges = new Array[DotEdge]
# Add a new node to the graph
fun add_node(id: String): DotNode do
var node = new DotNode(id)
add node
return node
end
# Add an edge to the graph
fun add_edge(from, to: DotElement): DotEdge do
var edge = new DotEdge(from, to)
add edge
return edge
end
redef fun to_dot do
var dot = new Buffer
dot.append "{kind} \"{id}\" \{\n"
if attrs.not_empty then dot.append attrs.to_dot(";\n")
if nodes_attrs.not_empty then dot.append "node[{nodes_attrs.to_dot(",")}];\n"
if edges_attrs.not_empty then dot.append "edge[{edges_attrs.to_dot(",")}];\n"
for id, node in nodes do
dot.append "{node.to_dot};\n"
end
for edge in edges do
dot.append("{edge.to_dot};\n")
end
dot.append("\}")
return dot
end
# Render `self` as an SVG image
fun to_svg: Text do
var proc = new ProcessDuplex("dot", "-Tsvg")
var svg = proc.write_and_read(to_dot)
proc.close
proc.wait
return svg
end
# Show dot in graphviz (blocking)
fun show do
var f = new ProcessWriter("dot", "-Txlib")
f.write to_dot
f.close
f.wait
end
end
lib/dot/dot.nit:75,1--171,3