How to merge two disjointed branches in PlantUML activity diagram with new syntax?

+1 vote
asked Mar 26, 2023 in Question / help by Martin

// This is a repost from SO, sorry if that bothers you.

I want to create an Activity Diagram with PlantUML's new beta syntax.

I've got the basic decision logic diagram, but I'm having trouble trying to add a merge node to merge two execution branches. I want branches A1+ and B1+ to lead to a common activity and then end. Unfortunately I only got to the point of having two different activities with the same name.

Current diagram:

@startuml
'https://plantuml.com/activity-diagram-beta
start
:Some Start Activity;
if (Decision AB?) then (A)
    if (Decision A1/A2?) then (A1)
        if (Decision4 A1+/A1-?) then (A1+)
            :Activity for A1+;
            :Activity_2 for A1+;
            :Activity_3 for A1+;
            :Activity_4 for A1+;
            :**TODO Common Activity for A1+, B1+**;
            stop
        else (A1-)
            :Activity for A1-;
            stop
        endif
    else (A2)
    endif
else (B)
    if (Decision B1/B2?) then (B1)
        if (Decision B1+/B1-?) then (B1+)
            :**TODO Common Activity for A1+, B1+**;
            stop
        else (B1-)
        endif
    else (B2)
    endif
endif
:Common activity for A2, B2, B1-;
stop

@enduml

Render:
RenderOfCurrent

Goto/Label workaround attempt

Now, I've tried to solve this with a workaround by using the Goto/Label syntax, but that doesn't really solve the problem. Not only is it ugly, it also breaks the layout, since it draws a line over other elements. With Goto/Label workaround:

@startuml
'https://plantuml.com/activity-diagram-beta
start
:Some Start Activity;
if (Decision AB?) then (A)
    if (Decision A1/A2?) then (A1)
        if (Decision4 A1+/A1-?) then (A1+)
            :Activity for A1+;
            :Activity_2 for A1+;
            :Activity_3 for A1+;
            :Activity_4 for A1+;
            label myLabel
            :**TODO Common Activity for A1+, B1+**;
            stop
        else (A1-)
            :Activity for A1-;
            stop
        endif
    else (A2)
    endif
else (B)
    if (Decision B1/B2?) then (B1)
        if (Decision B1+/B1-?) then (B1+)
            label dummyLabel
            goto myLabel
        else (B1-)
        endif
    else (B2)
    endif
endif
:Common activity for A2, B2, B1-;
stop

@enduml

Render:
enter image description here

How do I force PlantUML to create a simple merge node and join the two execution branches leading to a common Activity for A1+ and B1+?

1 Answer

0 votes
answered Mar 26, 2023 by The-Lu (64,340 points)

Hello M., and all,

Here are some proposal using label (and very very lot dummy label) and goto:

First, with crossing line:

Secondly, without crossing line:

Here is the corresponding source code:

@startuml
start
:Some Start Activity;
if (Decision AB?) then (A)
    if (Decision A1/A2?) then (A2)
    label dummuLabel
    else (A1)
        if (Decision4 A1+/A1-?) then (A1+)
            :Activity for A1+;
            :Activity_2 for A1+;
            :Activity_3 for A1+;
            :Activity_4 for A1+;
            label dummyLabel
            label myLabel
            :**TODO Common Activity for A1+, B1+**;
            stop
        else (A1-)
            :Activity for A1-;
            stop
        endif
    endif
else (B)
    if (Decision B1/B2?) then (B1)
        if (Decision B1+/B1-?) then (B1+)
            label dummyLabel
            label dummyLabel
            label dummyLabel
            label dummyLabel
            label dummyLabel
            label dummyLabel
            label dummyLabel
            label dummyLabel
            goto myLabel
        else (B1-)
        endif
    else (B2)
    endif
endif
:Common activity for A2, B2, B1-;
stop

@enduml

Enjoy,
Regards.

commented Mar 27, 2023 by Martin
Thank you @The-Lu.

Unfortunately, I don't consider this a solution. I don't want to maintain a dozen of invisible labels just to merge two flow paths.
I would like PlantUML to do it without labels and create a merge node instead.

If this is not possible with the new beta syntax, then I proclaim that the syntax is unusable crap, back to the old one.
commented Mar 27, 2023 by The-Lu (64,340 points)

Hi all,

Your are right, this is only a workaround.

PlantUML must be updated with a list of defects or enhancements about this subject.
To put on the todo list and on the wanted feature of PlantUML...

See (the beginning with the) first requests here:

You can complete the list with your wanted feature.

To help of the enhancement of plantuml.
Regards.

...