The Dot class

A representation of a graph in the DOT language of Graphviz.

This class facilitates the creation and rendering of graph descriptions in the DOT language of the Graphviz graph drawing software. This class is fairly rudimentary, and is not intended to implement every feature of the DOT language. You can create a Dot object, assemble the graph by adding nodes and edges, attributes, labels, colours, subgraphs, and clusters, and retrieve its DOT source code string (Dot.to_string). Write the source code to a file and render it with the Graphviz installation on your system.

Contents

Dot

A representation of a graph in the DOT language of Graphviz.

Dot.add_attr(…)

Overloaded function.

Dot.add_edge(…)

This function adds an edge from the node named head to the node named tail.

Dot.add_node(…)

This function adds a node with name name.

Dot.add_subgraph(…)

This functions adds the Dot object subgraph as a subgraph of self.

Dot.attrs(…)

Returns a read-only dictionary of the current attributes of the represented graph.

Dot.colors

A list of default HTML/hex colours.

Dot.copy(…)

Copy a Dot object.

Dot.edge(…)

Returns the edge object with head named head and tail named tail.

Dot.edges(…)

Returns a copy of the list of the current edges (Edge objects) in the represented graph.

Dot.is_node(…)

Check if there is a node with a given name.

Dot.kind(…)

Overloaded function.

Dot.name(…)

Overloaded function.

Dot.node(…)

Returns the node object with name name.

Dot.nodes(…)

Returns a copy of the list of the current nodes in the represented graph.

Dot.subgraphs(…)

Returns a copy of the list of the current subgraphs (Dot objects) in the represented graph.

Dot.to_string(…)

Convert a Dot object to a string.

Full API

class Dot
__init__(self: Dot) None

Default constructor that constructs an empty Dot object with no nodes, edges, attributes, or subgraphs.

add_attr(*args, **kwargs)

Overloaded function.

add_attr(self: Dot, key: str, val: str) Dot

Add an attribute to a Dot object.

This function adds a new attribute, or replaces the value of an existing attribute of an Dot.

Parameters:
  • key (str) – the name of the attribute.

  • val (str) – the value of the attribute.

Returns:

self

Return type:

Dot

add_attr(self: Dot, key: str) Dot

Add an attribute to a Dot object.

This function adds a new attribute, or replaces the value of an existing attribute of an Dot.

Parameters:

key (str) – the name of the attribute.

Returns:

self

Return type:

Dot

add_edge(self: Dot, head: str, tail: str) Dot.Edge

This function adds an edge from the node named head to the node named tail.

Parameters:
  • head (str) – the name of the node at the head of the edge.

  • tail (str) – the name of the node at the tail of the edge.

Returns:

a newly created Dot.Edge object.

Return type:

Dot.Edge

Raises:

LibsemigroupsError – if there is no node named head and/or tail.

add_node(self: Dot, name: str) Dot.Node

This function adds a node with name name.

Parameters:

name (str) – the name of the node to add.

Returns:

a newly created Dot.Node object with name name.

Return type:

Dot.Node

Raises:

LibsemigroupsError – if there is already a node with name name.

add_subgraph(self: Dot, subgraph: Dot) Dot

This functions adds the Dot object subgraph as a subgraph of self. The following transformations are performed

  • the label attribute of the added subgraph is the Dot.name of subgraph;

  • the Dot.name of the added subgraph has the prefix "cluster_" added;

  • every node in the added subgraph has the prefix "name_" prepended (where "name" is the return value of Dot.name);

  • the label attribute of every node in the added subgraph is its original name in subgraph;

  • every edge is modified so that its head and tail use the new node names;

  • every edge has the attribute constraint set to false.

Parameters:

subgraph (Dot) – the Dot object to use as a subgraph.

Returns:

self.

Return type:

Dot

attrs(self: Dot) dict[str, str]

Returns a read-only dictionary of the current attributes of the represented graph.

Returns:

A dictionary.

Return type:

dict[str, str]

property colors

A list of default HTML/hex colours.

copy(self: Dot) Dot

Copy a Dot object.

Returns:

A copy.

Return type:

Dot

edge(self: Dot, head: str, tail: str) Dot.Edge

Returns the edge object with head named head and tail named tail.

Parameters:
  • head (str) – the name of the head node of the edge (node where the edge starts).

  • tail (str) – the name of the tail node of the edge (node where the edge ends).

Returns:

The edge from the node named head to the node named tail.

Return type:

Dot.Edge

Raises:
edges(self: Dot) list[Dot.Edge]

Returns a copy of the list of the current edges (Edge objects) in the represented graph.

Returns:

The list of current edges.

Return type:

list[Dot.Edge]

is_node(self: Dot, name: str) bool

Check if there is a node with a given name.

This function returns True if name is currently the name of a node in the represented graph and False otherwise.

Parameters:

name (str) – the name of the node.

Returns:

whether or not name is the name of a node.

Return type:

bool

kind(*args, **kwargs)

Overloaded function.

kind(self: Dot, val: Dot.Kind) Dot

Set the kind of the represented graph.

Parameters:

val (Dot.Kind) – the kind.

Returns:

self.

Return type:

Dot

kind(self: Dot) Dot.Kind

Get the kind of the represented graph.

Returns:

The kind of the graph represented.

Return type:

Dot.Kind

name(*args, **kwargs)

Overloaded function.

name(self: Dot) str

Get the current name of the represented graph.

Returns:

The current name of the represented graph.

Return type:

str

name(self: Dot, val: str) Dot

Set the name of the represented graph.

Parameters:

val (str) – the name.

Returns:

self.

Return type:

Dot

node(self: Dot, name: str) Dot.Node

Returns the node object with name name.

Parameters:

name (str) – the name of the node.

Returns:

The node named name.

Return type:

Dot.Node

Raises:

LibsemigroupsError – if there is no node named name.

nodes(self: Dot) list[Dot.Node]

Returns a copy of the list of the current nodes in the represented graph.

Returns:

The list of current nodes.

Return type:

list[Dot.Node]

subgraphs(self: Dot) list[Dot]

Returns a copy of the list of the current subgraphs (Dot objects) in the represented graph.

Returns:

The list of current subgraphs.

Return type:

list[Dot]

to_string(self: Dot) str

Convert a Dot object to a string. This function returns the string representation of the Dot object. This string contains a representation of the graph in the DOT language for Graphviz.

Returns:

The string representation of self.

Return type:

str