Control over Arrowheads (in UML sequence diagrsm)

0 votes
asked Jan 22 in Question / help by Jason (120 points)
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.

1 Answer

0 votes
answered Jan 28 by chris (2,540 points)
selected Feb 3 by Jason
 
Best answer

@startuml

' obviously, choose one of these lines
!$showFailures = false
!$showFailures = true

!procedure $mightFail()
!if $showFailures==false
->
!else
->x
!endif
!endprocedure

Bob -> Alice : hello
Charles $mightFail() Alice : MightFail
@enduml

You could also think about changing the arrow to red

commented Feb 3 by Jason (120 points)

Thank you for the reply Chris,

Out of all the options I did end up writing a function that is similar to my Option #2 and what you have outlined.  

In order to maintain readability in my diagrams, what I did was put the function into a separate .puml file and include it when necessary.

P.S. Thank you for the additional tip about changing the arrow to red.  I did included that in the detail.  smiley

...