Format dependency graphs.
Attributes
| Attribute | Type | Description |
|---|
| scheme | dict | Global visual configuration for graph elements including shapes, arrowheads, and fonts. |
| edge_scheme | dict | Default visual styles for edges, specifying colors and arrow dimensions. |
| node_scheme | dict | Visual styling applied to standard dependency nodes, defining fill and border colors. |
| term_scheme | dict | Visual styling applied specifically to terminal nodes to distinguish them from standard nodes. |
| graph_scheme | dict | Top-level graph configuration defining background colors and root node labels. |
Constructor
Signature
def GraphFormatter(
root: any = None,
type: string = None,
id: string = None,
indent: integer = 0,
inw: string = ' ' * 4,
**scheme: dict = null
) - > null
Parameters
| Name | Type | Description |
|---|
| root | any = None | The root node of the dependency graph. |
| type | string = None | The type of graph, defaulting to 'digraph'. |
| id | string = None | The unique identifier for the graph, defaulting to 'dependencies'. |
| indent | integer = 0 | The starting indentation level for the output. |
| inw | string = ' ' * 4 | The string used for a single level of indentation. |
| **scheme | dict = null | Arbitrary keyword arguments to override default visual scheme settings. |
Methods
attr()
@classmethod
def attr(
name: string,
value: string
) - > bytes
Formats a single graph attribute key-value pair into a quoted string for DOT compatibility.
Parameters
| Name | Type | Description |
|---|
| name | string | The name of the attribute to be defined |
| value | string | The value to assign to the attribute, which will be wrapped in double quotes |
Returns
| Type | Description |
|---|
bytes | The encoded byte string representing the formatted attribute assignment |
attrs()
@classmethod
def attrs(
d: dict,
scheme: dict
) - > string
Aggregates and joins multiple attributes into a single string using the defined separator and optional styling schemes.
Parameters
| Name | Type | Description |
|---|
| d | dict | A dictionary of attribute names and values to format |
| scheme | dict | An optional dictionary of default styles to merge with the provided attributes |
Returns
| Type | Description |
|---|
string | A joined string of formatted attributes separated by the class's attribute separator |
head()
@classmethod
def head(
attrs: kwargs
) - > bytes
Generates the opening header of the graph definition, including the graph type, ID, and global graph attributes.
Parameters
| Name | Type | Description |
|---|
| attrs | kwargs | Arbitrary keyword arguments representing graph-level attributes to include in the header |
Returns
| Type | Description |
|---|
bytes | The encoded byte string for the start of the DOT graph definition |
tail()
@classmethod
def tail() - > bytes
Generates the closing footer of the graph definition.
Returns
| Type | Description |
|---|
bytes | The encoded byte string representing the end of the DOT graph block |
label()
@classmethod
def label(
obj: object
) - > object
Returns the provided object as its own label representation.
Parameters
| Name | Type | Description |
|---|
| obj | object | The object to be labeled |
Returns
| Type | Description |
|---|
object | The original object intended for use as a label |
node()
@classmethod
def node(
obj: object,
attrs: kwargs
) - > bytes
Formats a standard graph node using the default node styling scheme.
Parameters
| Name | Type | Description |
|---|
| obj | object | The object or identifier representing the node |
| attrs | kwargs | Additional attributes to apply to this specific node |
Returns
| Type | Description |
|---|
bytes | The encoded byte string representing the formatted node definition |
terminal_node()
@classmethod
def terminal_node(
obj: object,
attrs: kwargs
) - > bytes
Formats a terminal (leaf) graph node using the specific terminal node styling scheme.
Parameters
| Name | Type | Description |
|---|
| obj | object | The object or identifier representing the terminal node |
| attrs | kwargs | Additional attributes to apply to this specific terminal node |
Returns
| Type | Description |
|---|
bytes | The encoded byte string representing the formatted terminal node definition |
edge()
@classmethod
def edge(
a: object,
b: object,
attrs: kwargs
) - > bytes
Formats a directed edge between two nodes in the graph.
Parameters
| Name | Type | Description |
|---|
| a | object | The source node identifier |
| b | object | The destination node identifier |
| attrs | kwargs | Additional attributes to apply to this specific edge |
Returns
| Type | Description |
|---|
bytes | The encoded byte string representing the formatted edge definition |
FMT()
@classmethod
def FMT(
fmt: string,
args: tuple,
kwargs: dict
) - > bytes
Applies string formatting to a template using provided arguments and internal indentation state, then encodes the result.
Parameters
| Name | Type | Description |
|---|
| fmt | string | The format string template containing placeholders |
| args | tuple | Positional arguments for the format template |
| kwargs | dict | Keyword arguments for the format template, merged with indentation settings |
Returns
| Type | Description |
|---|
bytes | The formatted and UTF-8 encoded byte string |
draw_edge()
@classmethod
def draw_edge(
a: object,
b: object,
scheme: dict,
attrs: dict
) - > bytes
Constructs the DOT representation of an edge between two points with specified schemes and attributes.
Parameters
| Name | Type | Description |
|---|
| a | object | The starting node of the edge |
| b | object | The ending node of the edge |
| scheme | dict | The styling scheme to apply to the edge |
| attrs | dict | Specific attribute overrides for this edge |
Returns
| Type | Description |
|---|
bytes | The encoded byte string for the edge definition |
draw_node()
@classmethod
def draw_node(
obj: object,
scheme: dict,
attrs: dict
) - > bytes
Constructs the DOT representation of a node with specified schemes and attributes.
Parameters
| Name | Type | Description |
|---|
| obj | object | The object to represent as a node |
| scheme | dict | The styling scheme to apply to the node |
| attrs | dict | Specific attribute overrides for this node |
Returns
| Type | Description |
|---|
bytes | The encoded byte string for the node definition |