Debian Codegraph @

doc/usage/extensions/graphviz.rst

raw
1 .. highlight:: rst
2
3 :mod:`sphinx.ext.graphviz` -- Add Graphviz graphs
4 =================================================
5
6 .. module:: sphinx.ext.graphviz
7 :synopsis: Support for Graphviz graphs.
8
9 .. versionadded:: 0.6
10
11 .. role:: code-py(code)
12 :language: Python
13
14 This extension allows you to embed `Graphviz <https://graphviz.org/>`_ graphs in
15 your documents.
16
17 It adds these directives:
18
19 .. rst:directive:: graphviz
20
21 Directive to embed graphviz code. The input code for ``dot`` is given as the
22 content. For example::
23
24 .. graphviz::
25
26 digraph foo {
27 "bar" -> "baz";
28 }
29
30 In HTML output, the code will be rendered to a PNG or SVG image (see
31 :confval:`graphviz_output_format`). In LaTeX output, the code will be
32 rendered to an embeddable PDF file.
33
34 You can also embed external dot files, by giving the file name as an
35 argument to :rst:dir:`graphviz` and no additional content::
36
37 .. graphviz:: external.dot
38
39 As for all file references in Sphinx, if the filename is absolute, it is
40 taken as relative to the source directory.
41
42 .. versionchanged:: 1.1
43 Added support for external files.
44
45 .. rubric:: options
46
47 .. rst:directive:option:: alt: alternate text
48 :type: text
49
50 The alternate text of the graph. By default, the graph code is used to
51 the alternate text.
52
53 .. versionadded:: 1.0
54
55 .. rst:directive:option:: align: alignment of the graph
56 :type: left, center or right
57
58 The horizontal alignment of the graph.
59
60 .. versionadded:: 1.5
61
62 .. rst:directive:option:: caption: caption of the graph
63 :type: text
64
65 The caption of the graph.
66
67 .. versionadded:: 1.1
68
69 .. rst:directive:option:: layout: layout type of the graph
70 :type: text
71
72 The layout of the graph (e.g. ``dot``, ``neato`` and so on). A path to the
73 graphviz commands are also allowed. By default, :confval:`graphviz_dot`
74 is used.
75
76 .. versionadded:: 1.4
77 .. versionchanged:: 2.2
78
79 Renamed from ``graphviz_dot``
80
81 .. rst:directive:option:: name: label
82 :type: text
83
84 The label of the graph.
85
86 .. versionadded:: 1.6
87
88 .. rst:directive:option:: class: class names
89 :type: a list of class names separated by spaces
90
91 The class name of the graph.
92
93 .. versionadded:: 2.4
94
95
96 .. rst:directive:: graph
97
98 Directive for embedding a single undirected graph. The name is given as a
99 directive argument, the contents of the graph are the directive content.
100 This is a convenience directive to generate ``graph <name> { <content> }``.
101
102 For example::
103
104 .. graph:: foo
105
106 "bar" -- "baz";
107
108 .. note:: The graph name is passed unchanged to Graphviz. If it contains
109 non-alphanumeric characters (e.g. a dash), you will have to double-quote
110 it.
111
112 .. rubric:: options
113
114 Same as :rst:dir:`graphviz`.
115
116 .. rst:directive:option:: alt: alternate text
117 :type: text
118
119 .. versionadded:: 1.0
120
121 .. rst:directive:option:: align: alignment of the graph
122 :type: left, center or right
123
124 .. versionadded:: 1.5
125
126 .. rst:directive:option:: caption: caption of the graph
127 :type: text
128
129 .. versionadded:: 1.1
130
131 .. rst:directive:option:: layout: layout type of the graph
132 :type: text
133
134 .. versionadded:: 1.4
135 .. versionchanged:: 2.2
136
137 Renamed from ``graphviz_dot``
138
139 .. rst:directive:option:: name: label
140 :type: text
141
142 .. versionadded:: 1.6
143
144 .. rst:directive:option:: class: class names
145 :type: a list of class names separated by spaces
146
147 The class name of the graph.
148
149 .. versionadded:: 2.4
150
151
152 .. rst:directive:: digraph
153
154 Directive for embedding a single directed graph. The name is given as a
155 directive argument, the contents of the graph are the directive content.
156 This is a convenience directive to generate ``digraph <name> { <content> }``.
157
158 For example::
159
160 .. digraph:: foo
161
162 "bar" -> "baz" -> "quux";
163
164 .. rubric:: options
165
166 Same as :rst:dir:`graphviz`.
167
168 .. rst:directive:option:: alt: alternate text
169 :type: text
170
171 .. versionadded:: 1.0
172
173 .. rst:directive:option:: align: alignment of the graph
174 :type: left, center or right
175
176 .. versionadded:: 1.5
177
178 .. rst:directive:option:: caption: caption of the graph
179 :type: text
180
181 .. versionadded:: 1.1
182
183 .. rst:directive:option:: layout: layout type of the graph
184 :type: text
185
186 .. versionadded:: 1.4
187 .. versionchanged:: 2.2
188
189 Renamed from ``graphviz_dot``
190
191 .. rst:directive:option:: name: label
192 :type: text
193
194 .. versionadded:: 1.6
195
196 .. rst:directive:option:: class: class names
197 :type: a list of class names separated by spaces
198
199 The class name of the graph.
200
201 .. versionadded:: 2.4
202
203
204 There are also these config values:
205
206 .. confval:: graphviz_dot
207 :type: :code-py:`str`
208 :default: :code-py:`'dot'`
209
210 The command name with which to invoke ``dot``.
211 You may need to set this to a full path if ``dot`` is not in the executable
212 search path.
213
214 Since this setting is not portable from system to system, it is normally not
215 useful to set it in ``conf.py``; rather, giving it on the
216 :program:`sphinx-build` command line via the :option:`-D <sphinx-build -D>`
217 option should be preferable, like this::
218
219 sphinx-build -M html -D graphviz_dot=C:\graphviz\bin\dot.exe . _build
220
221 .. confval:: graphviz_dot_args
222 :type: :code-py:`Sequence[str]`
223 :default: :code-py:`()`
224
225 Additional command-line arguments to give to dot, as a list.
226 This is the right place to set global graph, node or edge
227 attributes via dot's ``-G``, ``-N`` and ``-E`` options.
228
229 .. confval:: graphviz_output_format
230 :type: :code-py:`'png' | 'svg'`
231 :default: :code-py:`'png'`
232
233 The output format for Graphviz when building HTML files. This must be either
234 ``'png'`` or ``'svg'``. If ``'svg'`` is used, in
235 order to make the URL links work properly, an appropriate ``target``
236 attribute must be set, such as ``"_top"`` and ``"_blank"``. For example, the
237 link in the following graph should work in the svg output: ::
238
239 .. graphviz::
240
241 digraph example {
242 a [label="sphinx", href="https://www.sphinx-doc.org/", target="_top"];
243 b [label="other"];
244 a -> b;
245 }
246
247 .. versionadded:: 1.0
248 Previously, output always was PNG.