graphviz 可以对 svg 进行分组输出

graphviz 可以对 svg 进行分组输出

我有以下 graphviz 的 .dot 文件

digraph example {

    node [fontsize=24, shape = plaintext];

    1940 -> 1950;
    1950 -> 1955;
    1955 -> 1960;
 
 
    node [fontsize=20, shape = box];
    { rank=same;  1940 test; }
    { rank=same;  1955 test; }

}

它输出的 svg 如下所示

<g id="node1" class="node">
<title>1940</title>
<text text-anchor="middle" x="32.5" y="-803.8" font-family="Times New Roman,serif" font-size="24.00">1940</text>
</g>
<!-- 1950 -->
<g id="node2" class="node">
<title>1950</title>
<text text-anchor="middle" x="32.5" y="-731.8" font-family="Times New Roman,serif" font-size="24.00">1950</text>
</g>

等等。

我想输出一组节点。例如,如果可以在 graphviz 代码中执行类似这样的操作

node [fontsize=20, shape = box, group = boxes];
{ rank=same;  1940 test; }
{ rank=same;  1955 test; }

然后当你输出 svg 时,它会将所有这些节点包装在一个

<g id="boxes">...</g>

答案1

前往以下任一位置:
https://dreampuf.github.io/GraphvizOnline/
http://magjac.com/graphviz-visual-editor/
找一个可以玩耍的地方。

例子:
https://renenyffenegger.ch/notes/tools/Graphviz/examples/index

手动的:
https://graphviz.org/doc/info/lang.html 甚至
https://www.graphviz.org/pdf/dotguide.pdf

常问问题:
https://graphviz.org/faq/

论坛:
https://forum.graphviz.org/

FWIW:Inkscape 不接受您的“SVG”。
从 GraphvizOnline 下载的版本包含更多内容。

如果您希望将节点放在一个框内(在末尾),您可能会成功使用subgraph {}如下所示的方法。
我尝试使用 rankdir 将 1950 和 1960 节点垂直放置,但似乎是徒劳的 ;-)

digraph example {

subgraph cluster_P {
    
    node [fontsize=14, shape = plaintext];

    1940 -> 1950;
    1950 -> 1955;
    1955 -> 1960;
 
    { rank=same; rankdir=TB;  1960 1950 }
    { rank=same; rankdir=LR;  1940  1955 }
   
  }

}

在此处输入图片描述

答案2

不。团体属性在 Graphviz 中有意义,但不会传递到 svg 输出。还有其他方法可以将值传递给 SVG:(评论班级ID属性),但没有一个能满足您的要求。此外,也不能保证节点会连续输出。
您可以使用ID标记属性每个具有相同值的节点。如下所示:

digraph Y{

a b c

node [fontsize=20 shape = box  id=POOL];

{ rank=same;  1940 testA; }
{ rank=same;  1955 testB; }
1940->1955 [style=inviz]

}

附言排序目录仅适用于根图。

相关内容