从超状态到子状态的 DOT 图
DOT graph from superstate to substate
我想生成 DOT 代码来绘制所示的等效状态机图。
我将以编程方式创建,我已经完成了状态和超状态之间的转换。但是我需要一些帮助:
这给了我一个初始转换,但 State1 应该是集群:
digraph {
compound=true;
node [shape=Mrecord]
rankdir="LR"
subgraph clusterOpen
{
label = "State1"
State2
}
State1 -> State2 [style="solid"];
node [shape = point label="" ] i ->State1
}
通常 Graphviz 程序会尽量避免将节点放置在其他节点之上。但是,如果您为每个节点明确提供 pos 属性,则可以将节点放置在任何您喜欢的位置(参见 https://graphviz.org/faq/#FaqDotWithNodeCoords)。
创建输入文件的程序应该为每个节点计算一个 pos 属性。 (请记住,pos 坐标以 points 为单位,而节点大小以 inches 为单位!)。您或许可以跳过计算边的样条曲线,让 neato 这样做。
这个程序:
digraph {
graph [bb="0,0,482.8,337"];
node [label="\N"];
State1 [height=4.0139,
label="{State 1|\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n}",
pos="162,144.5",
shape=Mrecord,
width=4.5];
State2 [height=1.3333,
label="{State 2|\n\n\n\n}",
// pos="403,144.5",
pos="220,88",
shape=Mrecord,
width=1.6944];
xp3 [height=0.05,
label="",
// pos="429,331",
pos="0,194",
shape=point,
// style=dotted,
style=invis,
width=0.05];
r1 [height=0.16667,
label="",
// pos="455,331",
pos="154,194",
shape=square,
width=0.16667];
xp4 [height=0.05,
label="",
// pos="481,331",
pos="0,88",
shape=point,
// style=dotted,
style=invis,
width=0.05];
xp1 [height=0.16,
label="",
pos="162,331",
shape=point,
width=0.16];
xp1 -> State1:n [pos="e,162,288.5 162,325.23 162,319.09 162,308.89 162,298.63",
style=dashed];
xp2 [height=0.16,
label="",
// pos="403,331",
pos="220,194",
shape=point,
width=0.16];
xp2 -> State2:n [pos="e,403,192.5 403,325.19 403,307.39 403,251.8 403,202.57"];
// manually added:
xp3 -> r1 [label="Trigger 1" dir=none ]
xp4 -> State2 [label="Trigger 2" ]
}
运行 使用此命令行:
neato -n -Tpng stateDiagram.dot >stateDiagram.png
生成此图:
我想生成 DOT 代码来绘制所示的等效状态机图。 我将以编程方式创建,我已经完成了状态和超状态之间的转换。但是我需要一些帮助:
这给了我一个初始转换,但 State1 应该是集群:
digraph {
compound=true;
node [shape=Mrecord]
rankdir="LR"
subgraph clusterOpen
{
label = "State1"
State2
}
State1 -> State2 [style="solid"];
node [shape = point label="" ] i ->State1
}
通常 Graphviz 程序会尽量避免将节点放置在其他节点之上。但是,如果您为每个节点明确提供 pos 属性,则可以将节点放置在任何您喜欢的位置(参见 https://graphviz.org/faq/#FaqDotWithNodeCoords)。
创建输入文件的程序应该为每个节点计算一个 pos 属性。 (请记住,pos 坐标以 points 为单位,而节点大小以 inches 为单位!)。您或许可以跳过计算边的样条曲线,让 neato 这样做。
这个程序:
digraph {
graph [bb="0,0,482.8,337"];
node [label="\N"];
State1 [height=4.0139,
label="{State 1|\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n}",
pos="162,144.5",
shape=Mrecord,
width=4.5];
State2 [height=1.3333,
label="{State 2|\n\n\n\n}",
// pos="403,144.5",
pos="220,88",
shape=Mrecord,
width=1.6944];
xp3 [height=0.05,
label="",
// pos="429,331",
pos="0,194",
shape=point,
// style=dotted,
style=invis,
width=0.05];
r1 [height=0.16667,
label="",
// pos="455,331",
pos="154,194",
shape=square,
width=0.16667];
xp4 [height=0.05,
label="",
// pos="481,331",
pos="0,88",
shape=point,
// style=dotted,
style=invis,
width=0.05];
xp1 [height=0.16,
label="",
pos="162,331",
shape=point,
width=0.16];
xp1 -> State1:n [pos="e,162,288.5 162,325.23 162,319.09 162,308.89 162,298.63",
style=dashed];
xp2 [height=0.16,
label="",
// pos="403,331",
pos="220,194",
shape=point,
width=0.16];
xp2 -> State2:n [pos="e,403,192.5 403,325.19 403,307.39 403,251.8 403,202.57"];
// manually added:
xp3 -> r1 [label="Trigger 1" dir=none ]
xp4 -> State2 [label="Trigger 2" ]
}
运行 使用此命令行:
neato -n -Tpng stateDiagram.dot >stateDiagram.png
生成此图: