Skip to main content

GraphFormatter

Format dependency graphs.

Attributes​

AttributeTypeDescription
schemedictGlobal visual configuration for graph elements including shapes, arrowheads, and fonts.
edge_schemedictDefault visual styles for edges, specifying colors and arrow dimensions.
node_schemedictVisual styling applied to standard dependency nodes, defining fill and border colors.
term_schemedictVisual styling applied specifically to terminal nodes to distinguish them from standard nodes.
graph_schemedictTop-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​

NameTypeDescription
rootany = NoneThe root node of the dependency graph.
typestring = NoneThe type of graph, defaulting to 'digraph'.
idstring = NoneThe unique identifier for the graph, defaulting to 'dependencies'.
indentinteger = 0The starting indentation level for the output.
inwstring = ' ' * 4The string used for a single level of indentation.
**schemedict = nullArbitrary 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​

NameTypeDescription
namestringThe name of the attribute to be defined
valuestringThe value to assign to the attribute, which will be wrapped in double quotes

Returns​

TypeDescription
bytesThe 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​

NameTypeDescription
ddictA dictionary of attribute names and values to format
schemedictAn optional dictionary of default styles to merge with the provided attributes

Returns​

TypeDescription
stringA joined string of formatted attributes separated by the class's attribute separator

@classmethod
def head(
attrs: kwargs
) - > bytes

Generates the opening header of the graph definition, including the graph type, ID, and global graph attributes.

Parameters​

NameTypeDescription
attrskwargsArbitrary keyword arguments representing graph-level attributes to include in the header

Returns​

TypeDescription
bytesThe 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​

TypeDescription
bytesThe 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​

NameTypeDescription
objobjectThe object to be labeled

Returns​

TypeDescription
objectThe 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​

NameTypeDescription
objobjectThe object or identifier representing the node
attrskwargsAdditional attributes to apply to this specific node

Returns​

TypeDescription
bytesThe 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​

NameTypeDescription
objobjectThe object or identifier representing the terminal node
attrskwargsAdditional attributes to apply to this specific terminal node

Returns​

TypeDescription
bytesThe 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​

NameTypeDescription
aobjectThe source node identifier
bobjectThe destination node identifier
attrskwargsAdditional attributes to apply to this specific edge

Returns​

TypeDescription
bytesThe 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​

NameTypeDescription
fmtstringThe format string template containing placeholders
argstuplePositional arguments for the format template
kwargsdictKeyword arguments for the format template, merged with indentation settings

Returns​

TypeDescription
bytesThe 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​

NameTypeDescription
aobjectThe starting node of the edge
bobjectThe ending node of the edge
schemedictThe styling scheme to apply to the edge
attrsdictSpecific attribute overrides for this edge

Returns​

TypeDescription
bytesThe 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​

NameTypeDescription
objobjectThe object to represent as a node
schemedictThe styling scheme to apply to the node
attrsdictSpecific attribute overrides for this node

Returns​

TypeDescription
bytesThe encoded byte string for the node definition