Can I combine two graphs together? Like a sequence and a state diagram?

+1 vote
asked Dec 22, 2020 in Question / help by rhedin (120 points)
What I'm working on is basically a sequence diagram.  One entity sends another entity messages, in a flow of time.

But sometimes a message changes the state of an entity.  After that point, the entity responds differently to the same messages, and understands some different messages.

If was thinking of somehow placing a state diagram where the entity is in the sequence diagram, and showing the change of state.   Is that possible?

Think of a web page being tested in a player piano fashion.   You click the submit button, the form is accepted, and then a different page is displayed.   If you click the submit button again, something entirely different happens.
commented Dec 24, 2020 by albert (2,940 points)
Please give an example (in plantumlcode) of such a mix.

Did you have a look at allow_mixing? (see also https://forum.plantuml.net/8086/allow-mixing?show=8086#q8086 and search the internet for e.g. plantuml mixed diagrams).

1 Answer

0 votes
answered Dec 25, 2020 by The-Lu (12,780 points)

Hello R.,

You can use embedded diagram or sub-diagram with use of '{{' and '}}' on note (See similar question on /6947/embed-sub-diagrams-in-diagram-like-a-note):

Here is a proposal, with a simple "User State" embedded on a sequence diagram (with adding processing procedure just to avoid to repeat the state wink):

@startuml
actor       Client       as C
participant Server       as S
control     "User state" as U

!procedure $UserState()
  title User state
  D : disconnected
  C : connected
  D -> C : connects
  C -> D : disconnects
!end procedure

== Init ==
note right U
  {{
  $UserState()
  state D #palegreen
  }}
end note

== Exchange ==
C -x S : Attempt to connect
note right U
  {{
  $UserState()
  state D #palegreen
  }}
end note
|||
C -> S : Connects
note right U
  {{
  $UserState()
  state C #palegreen
  }}
end note
S -> C : Ack
|||
@enduml

And the result:


[See on PlantUML online server]

If that can help,
Regards,
Th.

...