英文:
Bypassing an activity in plantUML activity diagram
问题
我一直在努力弄清楚如何让这张图看起来符合我的喜好。这是我目前为止最接近的一次:
[][1]
它是通过这段代码实现的:
```
@startuml
:A;
split;
-> A 到 B;
:B;
-> B 到 E;
:E;
-> E 到 G;
split again;
-> A 到 C;
:C;
-> C 到 D;
:D;
-> D 到 F;
:F;
-> F 到 G;
end split;
:G;
@enduml
```
但是缺少了一个从 C 到 F 的箭头,但是我无论如何也搞不明白如何在新的语法中制作它。
我曾经使用旧的语法做过类似的事情,就像这样:
```
@startuml
"A" -left->["A 到 B"] "B"
"A" -right->["A 到 C"] "C"
"B"-->[ "B 到 E"] "E"
"C"-->[ "C 到 D"] "D"
"D"-->[ "D 到 F"] "F"
"C"-->[ "C 到 F"] "F"
"F"-->[ "F 到 G"]"G"
"E"-->[ "E 到 G"] "G"
@enduml
```
这导致了这张图片:
[][2]
但是这种方法有它的缺点,它是旧的语法,而我个人认为新的语法产生的“矩形”外观比旧语法的曲线更容易阅读。
所以,如何在新的语法中从 C 到 F 添加箭头呢?有些问题,比如《如何在PlantUML UML活动图中引用先前的活动》 已经让我接近了答案,但它们似乎并不完全是我所寻找的。我还研究了graphViz,但是我无法弄清楚如何产生与新的PlantUML语法给我带来的干净方正外观相同的效果,所以这也是失败的。所以,能帮忙吗?
编辑:我注意到我的标签中有错误,我现在已经修复了它,并且在逻辑连接方面,现在两个图像应该是等价的。我还添加了红色箭头和标签,以更清晰地显示我想要实现的内容。感谢所有表达困惑的人,现在情况应该更清晰了。
英文:
I've been trying to figure for the life of me how to get this graph looking how I like it. Here's the closest I've gotten
and it has been achieved with this code
@startuml
:A;
split;
-> A to B;
:B;
-> B to E;
:E;
-> E to G;
split again;
-> A to C;
:C;
->C to D;
:D;
->D to F;
:F;
->F to G;
end split;
:G;
@enduml
But it's missing an arrow from C to F and I can't for the life of me figure out how to make it in the new syntax.
I did manage to do something like that with the old syntax like this
@startuml
"A" -left->["A to B"] "B"
"A" -right->["A to C"] "C"
"B"-->["B to E"] "E"
"C"-->["C to D"] "D"
"D"-->["D to F"] "F"
"C"-->["C to F"] "F"
"F"-->["F to G"]"G"
"E"-->["E to G"] "G"
@enduml
which results in this image
But this one has the drawbacks of being old syntax and I personally find the "rectangular" look produced by the new syntax much more readable than the curved lines of the old.
So, how to get an arrow from C to F in the new syntax? Some of the questions, like How to reference earlier activity in PlantUML UML Activity Diagram have gotten me close, but they don't quite seem to be what I'm looking for. I also looked into graphViz, but I couldn't figure out how to produce the same kind of clean squared up look that the new plantUML syntax gave me, so that's a bust as well. So, help?
EDIT: I noticed there were mistakes in my labeling, I have hopefully now fixed it and in terms of logical connections, both images shhould now be equivalent. I also added the red arrow and the label on paint to more clearly display what I want to achieve. Thank you to everyone who voiced their confusion, situation should now be much more clear.
答案1
得分: 1
在活动图中,您可以使用`split`来表示绕过。但是,您不能这样做,因为在流程中没有额外的活动绕过该活动。所以,这看起来像是一种条件流。活动图有一种语法(使用菱形节点),所以它看起来像这样:
```plantuml
@startuml diagram name
:A;
split;
-> A 到 B;
:B;
-> B 到 E;
:E;
-> E 到 G;
split again;
-> A 到 C;
:C;
if (条件?) then
:D;
endif
:F;
->F 到 G;
end split;
:G;
@enduml
如果您只是想要一个图表,那么状态图可能更好(这是您的第二个例子,我承认我不理解绕过--它与第一个例子不同)。
无论如何,通常删除left
和right
的规格会使布局更好。我总是从那个开始。这是您的第二个例子(更好吗?)没有那些:
@startuml
"A"-->[ "A 到 B" ] "B"
"A"-->[ "A 到 C" ] "C"
"B"-->[ "B 到 E" ] "E"
"C"-->[ "C 到 D" ] "D"
"D"-->[ "D 到 F" ] "F"
"C"-->[ "C 到 F" ] "F"
"F"-->[ "F 到 G" ] "G"
"E"-->[ "E 到 G" ] "G"
@enduml
<details>
<summary>英文:</summary>
In an activity diagram, you can show a bypass by using `split`. However, you can't because there's no extra activity on the flow that bypasses the activity. So, that seems like a conditional flow. Activity diagrams have a syntax (with diamond nodes) so this is how it looks:
```plantuml
@startuml diagram name
:A;
split;
-> A to B;
:B;
-> B to E;
:E;
-> E to G;
split again;
-> A to C;
:C;
if (condition?) then
:D;
endif
:F;
->F to G;
end split;
:G;
@enduml
If you're just trying to get a graph, then maybe a state diagram is better (it's your second example, which I admit I don't understand the bypass -- it's not the same as the first example).
Anyway, removing the left
and right
specifications usually makes for a better layout. I always start with that. Here's your second example (is it better?) without those:
@startuml
"A"-->["A to B"] "B"
"A"-->["A to C"] "C"
"B"-->["B to E"] "E"
"C"-->["C to D"] "D"
"D"-->["D to F"] "F"
"C"-->["C to F"] "F"
"F"-->["F to G"] "G"
"E"-->["E to G"] "G"
@enduml
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论