sphinx.ext.graphviz -- Graphvizのグラフを追加

Added in version 0.6.

この拡張モジュールを使用すると、 Graphviz のグラフをドキュメント内に埋め込むことができるようになります。

この拡張モジュールは以下のディレクティブを提供します:

.. graphviz::

Graphvizのコードをドキュメント内に直接記述するためのディレクティブです。 ここでコンテンツとして入力された内容は、 dot コマンドで処理されます。 例:

.. graphviz::

   digraph foo {
      "bar" -> "baz";
   }

HTML出力されるときには、PNGのイメージファイルや、SVGイメージとしてレンダリングされます。 LaTeX出力時にはこのコードは埋め込み可能なPDFファイルとしてレンダリングされます。( graphviz_output_format を参照してください。)

graphviz ディレクティブの引数にファイル名を与えて、コンテンツを空にすることで、外部のdotファイルを埋め込むこともできます:

.. graphviz:: external.dot

Sphinx内の他のファイル参照と同様に、絶対パスのファイル名はソースディレクトリからの相対パスとして扱われます。

バージョン 1.1 で変更: 外部ファイルのサポートを追加。

options

:alt: alternate text (text)

The alternate text of the graph. By default, the graph code is used to the alternate text.

Added in version 1.0.

:align: alignment of the graph (left, center or right)

The horizontal alignment of the graph.

Added in version 1.5.

:caption: caption of the graph (text)

The caption of the graph.

Added in version 1.1.

:layout: layout type of the graph (text)

The layout of the graph (ex. dot, neato and so on). A path to the graphviz commands are also allowed. By default, graphviz_dot is used.

Added in version 1.4.

バージョン 2.2 で変更: Renamed from graphviz_dot

:name: label (text)

The label of the graph.

Added in version 1.6.

:class: class names (a list of class names separated by spaces)

The class name of the graph.

Added in version 2.4.

.. graph::

無向グラフをひとつ埋め込むのに使用するディレクティブです。 グラフの名前はディレクティブ引数として渡します。ディレクティブのコンテンツがそのままグラフ作成に使用されます。 このディレクティブは graph <名前> { <コンテンツ> } というグラフを作成するための便利機能です。

例えば:

.. graph:: foo

   "bar" -- "baz";

注釈

グラフの名前はそのままGraphvizに渡されます。名前に英数字でないもの(例えば、ダッシュ記号)が含まれているなら、それをダブルクオートで囲まなければならないでしょう。

options

Same as graphviz.

:alt: alternate text (text)

Added in version 1.0.

:align: alignment of the graph (left, center or right)

Added in version 1.5.

:caption: caption of the graph (text)

Added in version 1.1.

:layout: layout type of the graph (text)

Added in version 1.4.

バージョン 2.2 で変更: Renamed from graphviz_dot

:name: label (text)

Added in version 1.6.

:class: class names (a list of class names separated by spaces)

The class name of the graph.

Added in version 2.4.

.. digraph::

有向グラフをひとつ埋め込むために使用するディレクティブです。 グラフの名前はディレクティブ引数として渡します。ディレクティブのコンテンツがそのままグラフ作成に使用されます。 このディレクティブは digraph <名前> { <コンテンツ> } というグラフを作成するための便利機能です。

例えば:

.. digraph:: foo

   "bar" -> "baz" -> "quux";

options

Same as graphviz.

:alt: alternate text (text)

Added in version 1.0.

:align: alignment of the graph (left, center or right)

Added in version 1.5.

:caption: caption of the graph (text)

Added in version 1.1.

:layout: layout type of the graph (text)

Added in version 1.4.

バージョン 2.2 で変更: Renamed from graphviz_dot

:name: label (text)

Added in version 1.6.

:class: class names (a list of class names separated by spaces)

The class name of the graph.

Added in version 2.4.

There are also these config values:

graphviz_dot

dot を呼び出すときに使用するコマンド名です。デフォルトでは 'dot' です。 もしも dot コマンドが実行時の検索パスに存在していなくて、フルパスを設定する必要がある場合にはこの設定値を変更してください。

この設定はシステム間で共通にはできないため、conf.py の中で設定することは通常行いません。むしろ、次のように sphinx-build コマンドの -D オプションとして与えるほうが望ましいでしょう。

sphinx-build -M html -D graphviz_dot=C:\graphviz\bin\dot.exe . _build
graphviz_dot_args

dot コマンドに渡す、追加のコマンドライン引数です。デフォルト値は空のリストです。 -G, -N, -E オプションを使用して、ドキュメント内のすべてのGraphvizのグラフの、グラフ、ノード、エッジの属性を変更する場合にはこのオプションを使用してください。

graphviz_output_format

HTMLファイルを作成するときのGraphvizの出力形式。これは 'png''svg' のどちらかでなければなりません。デフォルトは 'png' です。 'svg' を使用する場合、URLリンクを正しく動作させるには、 "_top""_blank" などの適切な target 属性を設定する必要があります。たとえば、次のグラフのリンクはsvg出力で機能します。

.. graphviz::

     digraph example {
         a [label="sphinx", href="https://www.sphinx-doc.org/", target="_top"];
         b [label="other"];
         a -> b;
     }

Added in version 1.0: 以前は出力はPNGしかありませんでした。