Hello PlantUML Community,
I like to have two separate diagrams when I document my sequence diagrams. One describes the sequence flow (e.g. Diagram 1), while another focuses on the points of failure (e.g. Diagram 2).
Diagram 1 - Sequence flow
@startuml
Bob -> Alice : hello
@enduml
Diagram 2 - Failure points for Sequence
@startuml
Bob ->x Alice : hello
@enduml
Rather than drawing two distinct diagrams in a diagramming tool using layers, I simply overlay an 'X' on a separate layer to render the failure points (and turn on and off the layer selectively).
In PlantUML, the best I have been able to figure this out with my newbie knowledge is using the pre-processing like this:
Diagram 3 - Normal and Failure Sequence flow
@startuml
!$showfailurepoints = false
!if ($showfailurepoints == true)
Bob ->x Alice : hello
!else
Bob -> Alice : hello
!endif
@enduml
However, in a complex sequence diagram, this makes the code unreadable and difficult to maintain.
A couple of ways I have been thinking about this and their different pros and cons is outlined below:
Option 1 - Stylesheet
Conditionally load a stylesheet that would change the layout of select arrow heads such that, for example, without the stylesheet, -> renders normally, while with the stylesheet, the -> renders like ->x
Pros: Simple and readable
Cons: In some cases, more control may be required (ideally it would be accomplished with an inline style)
Mockup:
@startuml
!$showfailurepoints = false
!if ($showfailurepoints == true)
skinparam SynchronousArrowHead "X"
!else
skinparam SynchronousArrowHead ">"
!endif
Bob -> Alice : hello
@enduml
Option #2 - Function
Alternatively, if there was a way to define a function such that the arrow can be dynamically evaluated
Pros: Most control
Cons: Less readable
Mockup:
@startuml
!$showfailurepoints = false
!function DrawArrow($failurepoints,$no, $yes)
!if $failurepoints==false
! return $no
!else
! return $yes
!endif
!endfunction
Bob %call_user_func("DrawArrow", !$showfailurepoints, "->", "-x") Alice : hello
@enduml
Option #3 - Inline conditional
Pros: Similar control to Option #2
Cons: Less readable (arguably) then Option #2
Mockup:
@startuml
!$showfailurepoints = false
Bob !if ($showfailurepoints == true) return "->" else return "-x" endif Alice : hello
@enduml
QUESTION:
Given, I can't seem to figure this out, is there a way to accomplish this using something more readable and similar to the options 1..3 that I provided? I don't see a a skinparam for xxxArrowHead in my research.