graflo.plot.render¶
Turning a networkx graph into a file, and the Graphviz details that needs.
Kept apart from the graphs themselves so every plot in this package builds a
plain :mod:networkx graph — which any test can assert against — and only this
module knows about pygraphviz. Nothing here is specific to what is being drawn.
Attributes¶
OUTPUT_FORMATS = ('svg', 'pdf', 'png', 'dot')
module-attribute
¶
__all__ = ['OUTPUT_FORMATS', 'draw', 'escape', 'resolve_format', 'sanitize_id', 'to_agraph']
module-attribute
¶
Functions:¶
draw(agraph, path, *, output_format=None, prog='dot', dpi=None)
¶
Write agraph to path, creating the directory if it is missing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agraph
|
Any
|
The pygraphviz graph to write. |
required |
path
|
str | PathLike[str]
|
Where to write it; its suffix chooses the format by default. |
required |
output_format
|
str | None
|
Override the format the suffix implies. |
None
|
prog
|
str
|
Graphviz layout program. |
'dot'
|
dpi
|
int | None
|
Raster resolution, for |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
The path written. |
Source code in graflo/plot/render.py
escape(text)
¶
resolve_format(path, output_format)
¶
The format to write, from output_format or the path's own suffix.
Source code in graflo/plot/render.py
sanitize_id(node_id, taken=None)
¶
A Graphviz-safe node id, one-to-one with node_id.
: separates a node from its port and . a record field, so an id
like left:Firm.firm_id cannot be written as it stands. taken carries
the mapping across a whole graph so two different ids that sanitize alike
are still told apart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id
|
str
|
The id to convert. |
required |
taken
|
dict[str, str] | None
|
Accumulating |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The safe id, stable for the same node_id within one taken. |
Source code in graflo/plot/render.py
to_agraph(graph)
¶
graph as a pygraphviz AGraph, or an actionable error.