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

Introduced properties

fun add(element: DotElement)

dot :: DotGraph :: add

Add a node to the graph
fun add_edge(from: DotElement, to: DotElement): DotEdge

dot :: DotGraph :: add_edge

Add an edge to the graph
fun add_node(id: String): DotNode

dot :: DotGraph :: add_node

Add a new node to the graph
init defaultinit(id: String, kind: String)

dot :: DotGraph :: defaultinit

fun edges: Array[DotEdge]

dot :: DotGraph :: edges

Edge list
protected fun edges=(edges: Array[DotEdge])

dot :: DotGraph :: edges=

Edge list
fun edges_attrs: AttributeMap

dot :: DotGraph :: edges_attrs

Edges attributes
protected fun edges_attrs=(edges_attrs: AttributeMap)

dot :: DotGraph :: edges_attrs=

Edges attributes
fun kind: String

dot :: DotGraph :: kind

Graph kind like graph, digraph, subgraph...
fun kind=(kind: String)

dot :: DotGraph :: kind=

Graph kind like graph, digraph, subgraph...
fun nodes: HashMap[String, DotElement]

dot :: DotGraph :: nodes

Node list by id
protected fun nodes=(nodes: HashMap[String, DotElement])

dot :: DotGraph :: nodes=

Node list by id
fun nodes_attrs: AttributeMap

dot :: DotGraph :: nodes_attrs

Nodes attributes
protected fun nodes_attrs=(nodes_attrs: AttributeMap)

dot :: DotGraph :: nodes_attrs=

Nodes attributes
fun show

dot :: DotGraph :: show

Show dot in graphviz (blocking)
fun to_svg: Text

dot :: DotGraph :: to_svg

Render self as an SVG image

Redefined properties

redef type SELF: DotGraph

dot $ DotGraph :: SELF

Type of this instance, automatically specialized in every class
redef fun to_dot: Text

dot $ DotGraph :: to_dot

Render self to dot format

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
fun [](key: String): Object

dot :: DotElement :: []

Get attribute value for key
fun []=(key: String, value: Object)

dot :: DotElement :: []=

Set attribute value for key
fun add(element: DotElement)

dot :: DotGraph :: add

Add a node to the graph
fun add_edge(from: DotElement, to: DotElement): DotEdge

dot :: DotGraph :: add_edge

Add an edge to the graph
fun add_node(id: String): DotNode

dot :: DotGraph :: add_node

Add a new node to the graph
fun attrs: AttributeMap

dot :: DotElement :: attrs

Element attributes
protected fun attrs=(attrs: AttributeMap)

dot :: DotElement :: attrs=

Element attributes
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
init defaultinit(id: String, kind: String)

dot :: DotGraph :: defaultinit

fun edges: Array[DotEdge]

dot :: DotGraph :: edges

Edge list
protected fun edges=(edges: Array[DotEdge])

dot :: DotGraph :: edges=

Edge list
fun edges_attrs: AttributeMap

dot :: DotGraph :: edges_attrs

Edges attributes
protected fun edges_attrs=(edges_attrs: AttributeMap)

dot :: DotGraph :: edges_attrs=

Edges attributes
fun escape_id: String

dot :: DotElement :: escape_id

Return id.escape_to_dot
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
fun id: String

dot :: DotElement :: id

Element ID
protected fun id=(id: String)

dot :: DotElement :: id=

Element ID
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
fun kind: String

dot :: DotGraph :: kind

Graph kind like graph, digraph, subgraph...
fun kind=(kind: String)

dot :: DotGraph :: kind=

Graph kind like graph, digraph, subgraph...
fun nodes: HashMap[String, DotElement]

dot :: DotGraph :: nodes

Node list by id
protected fun nodes=(nodes: HashMap[String, DotElement])

dot :: DotGraph :: nodes=

Node list by id
fun nodes_attrs: AttributeMap

dot :: DotGraph :: nodes_attrs

Nodes attributes
protected fun nodes_attrs=(nodes_attrs: AttributeMap)

dot :: DotGraph :: nodes_attrs=

Nodes attributes
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
fun show

dot :: DotGraph :: show

Show dot in graphviz (blocking)
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
fun to_dot: Text

dot :: DotElement :: to_dot

Render self to dot format
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
fun to_svg: Text

dot :: DotGraph :: to_svg

Render self as an SVG image
package_diagram dot::DotGraph DotGraph dot::DotElement DotElement dot::DotGraph->dot::DotElement core::Object Object dot::DotElement->core::Object ...core::Object ... ...core::Object->core::Object

Ancestors

interface Object

core :: Object

The root of the class hierarchy.

Parents

abstract class DotElement

dot :: DotElement

Something that can be rendered in dot format.

Class definitions

dot $ DotGraph
# 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