graflo.plot.dot¶
A Graphviz graph as graflo's figures build it, written out as DOT text.
The figures are assembled as :mod:networkx graphs, then grouped into
clusters and written here; nothing in this module needs Graphviz itself.
:class:DotGraph keeps the conventions of networkx.nx_agraph.to_agraph:
graph.graph["graph" | "node" | "edge"] are the default attributes, any
other graph-level key is a graph attribute, and every value is written as its
str.
Attributes¶
__all__ = ['DotGraph', 'DotSubgraph', 'quote']
module-attribute
¶
Classes¶
DotGraph
¶
Nodes, edges, subgraphs and default attributes of one Graphviz graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directed
|
bool
|
|
True
|
strict
|
bool
|
Write |
False
|
name
|
str
|
The graph name. |
''
|
Source code in graflo/plot/dot.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | |
Attributes¶
directed = directed
instance-attribute
¶
edge_attr = {}
instance-attribute
¶
edges = []
instance-attribute
¶
graph_attr = {}
instance-attribute
¶
name = name
instance-attribute
¶
node_attr = {}
instance-attribute
¶
nodes = {}
instance-attribute
¶
strict = strict
instance-attribute
¶
subgraphs = []
instance-attribute
¶
Methods:¶
__init__(*, directed=True, strict=False, name='')
¶
Source code in graflo/plot/dot.py
add_edge(tail, head, **attrs)
¶
Add an edge, adding either endpoint that is missing.
add_node(node, **attrs)
¶
add_subgraph(nodes, name, **attrs)
¶
Group nodes under name; attrs are the subgraph's own attributes.
Source code in graflo/plot/dot.py
from_networkx(graph)
classmethod
¶
graph with every node, edge and attribute carried over as strings.
Source code in graflo/plot/dot.py
node_order()
¶
Nodes in the order the written DOT declares them: subgraph members first.
Graphviz creates a node where it first appears, and layout and
:meth:unflatten both walk nodes in that order.
Source code in graflo/plot/dot.py
to_string()
¶
The graph as DOT source.
Source code in graflo/plot/dot.py
unflatten(*, levels=0, fans=False, chain=0)
¶
Graphviz's unflatten, in place: make a wide directed graph taller.
Edges between a node and its leaves get staggered minlen values
(1..levels), so leaves stack in rows instead of one wide rank; with
fans, so do edges to nodes on a simple chain; isolated nodes are tied
into chains of chain by invisible edges. Edges that already carry a
minlen are left alone. Same as unflatten -l levels [-f] -c chain.
Returns:
| Type | Description |
|---|---|
DotGraph
|
This graph, for chaining. |
Source code in graflo/plot/dot.py
DotSubgraph
dataclass
¶
A named subgraph; a cluster_ name draws it as a box.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The subgraph name. |
nodes |
list[str]
|
Member node ids, in order. |
graph_attr |
dict[str, str]
|
Attributes of the subgraph itself ( |
node_attr |
dict[str, str]
|
Defaults for the member nodes. |
Source code in graflo/plot/dot.py
Functions:¶
quote(value)
¶
value as a DOT quoted string.
Inside quotes DOT treats only \" as an escape and keeps every other
backslash for the label (\n, \l, record escapes), so only quotes
are escaped — plus a trailing lone backslash, which would otherwise
swallow the closing quote.