States in Composite states are not correctly rendered

0 votes
asked Oct 18, 2024 in Bug by Tom Mens

PlantUML does not render correctly the nesting of states in composite states. (This problem was not present before, I cannot tell since when the problem is there.) Take the example of the following very simple statechart, containing just 2 states, and one transition between both states:

@startuml
[*] --> StateA
state StateA {
   StateA --> StateB
}
state StateB {

}
@enduml

From the textual notation it is clear that StateA and StateB reside at the same level (StateA is not contained in StateB or vice versa). Still, when visualising this example, StateB will be drawn as if it appears INSIDE StateA, which is clearly not the case.

http://www.plantuml.com/plantuml/png/SoWkIImgAStDuOhMYbNGrRLJ22v9B4brvE8g1j5Gda8rbu82b8rGvCHLYwpAIQ4QAE2GcfS2D0u0

In fact, when you take exactly the same example, but you change the order in which the states appear in the plantuml description (and this order should have no effect on the visualisation, in principle), then the problem no longer appears. (Note that this is not a general solution since I have more complex examples where, regardless of the order, there is always something wrong in the visualisation...)

@startuml
[*] --> StateA
state StateB {
}
state StateA {
   StateA --> StateB
}
@enduml

http://www.plantuml.com/plantuml/png/SoWkIImgAStDuOhMYbNGrRLJ22v9B4brv2e6KH2Eaq8rLosoW2DGG441oaPeSWAgSaZDIm6Q1W00

1 Answer

0 votes
answered Oct 18, 2024 by The-Lu (85,440 points)
commented Oct 18, 2024 by Tom Mens

Yes, issue #1476 seems to be exactly the same issue that we are facing. That currently unassigned issue also explains since when this backward incompatible (and in my view inconsistent) change was introduced in the plantuml rendering of statecharts. The order in which one declares states at the same level should not influence how the statechart is being rendered (i.e., by changing the order, it should not be the case that suddenly states become nested, or no longer become nested, or become nested in a different way...)

In the current implementation, it seems that the only way to avoid these problems is to manually modify one's plantuml statechart model so that all transitions are declared outside, and after the states. But this makes the specification of a statechart model in plantuml less readable (especially for complex statecharts), which should not be the intention.

The rendering of the following example, for instance, looks really weird:

@startuml
[*] --> B

state B {
   B --> A
}
state A {
   A --> B
}
@enduml

image

commented Oct 18, 2024 by plantuml (297,300 points)
...