define style for an element, label that customized element, and reuse it

0 votes
asked Jul 15 in Wanted features by anonymous

It would be cool to be able to define a custom display style for an element (such as an alt grouping), then reuse that customized style throughout a doc.  For example, I feel the alt grouping is more readable with spaces, so I add them like this:

|||
alt valid PIN
 Siteminder -> Siteminder : build response
 |||
else invalid PIN attempt
 Siteminder -> Siteminder : increment FAC stored in loginData and build response
 |||
end
|||

...but that's a lot of clutter in the code, and violates the DRY principle of coding.  Much better if I could define "my_alt" once and then reuse that for the entire doc.

1 Answer

0 votes
answered Jul 17 by Martin

Hi anon,

I don't know if you had any syntax in mind for your idea; I'm sure the developers would be more likely to respond if you have fleshed out the idea a bit.

But did you know that to some extent you can use the preprocessing options to get close to what you want?

1) idea 1 - redefine alt / else /end as functions:

@startuml
!procedure _alt()
|||
alt
!endprocedure
!procedure _else()
|||
else
!endprocedure
!procedure _end()
|||
end
|||
!endprocedure

_alt() valid PIN
Siteminder -> Siteminder : build response
_else() invalid PIN attempt
Siteminder -> Siteminder : increment FAC stored in loginData and build response
_end()
@enduml
http://www.plantuml.com/plantuml/png/VOz1gi9038RtSufqzzxYNU0jfA88RaJm038sGG8pcPB9kEhX7RKMwwAh_m_vaZzfitcr4eDhUaqTOL62im_sy-k6ON3LkOO4f-QCev1f11zsYHHyWu9FdRFkbGat7nZXk3-u4nj55YI5lnLyLFzmAHmGb7AVfAQEPm3BD0tUAj_RqXQMJYcI6EpM6yYMb11O8AGhozQR1o_udJK-qbOfCTm1

2) Redefine alt / else / end as functions that take a text parameter:

@startuml
!unquoted procedure alt_($txt)
|||
alt $txt
!endprocedure
!unquoted procedure else_($txt)
|||
else $txt
!endprocedure
!unquoted procedure end_()
|||
end
|||
!endprocedure
alt_(valid PIN)
Siteminder -> Siteminder : build response
else_(invalid PIN attempt)
Siteminder -> Siteminder : increment FAC stored in loginData and build response
end_()
@enduml

http://www.plantuml.com/plantuml/png/ZOz1oi8m48NtESKK_aMx-2_WGYgAu4O43r1YPv10Cgd9H5pqyAPQIYaYhXvVU5_oKaVHGPApgaXyIru8eGk-9Ko1G5jfoZzvIANwlbSPOI1L4EFK-cYIZJHN1_xPPMpAKMCSSY6frwwxjWRXT3XMwco4d66a0FzhcD4ABibOX42nynn9lNSPdcJGajkTVBt4S1l84GliDrk8uWDXFWJhhuPtMZHenkLJupVgdCdP9m00

3) Create a one-liner function (shame you can't seem to split the call over multiple lines)

@startuml
!unquoted procedure my_alt($a, $b, $c, $d, $e)
|||
alt $b
 $a -> $a: $c
 |||
else $d
 $a -> $a: $e
 |||
end
|||
!endprocedure
my_alt(Siteminder, valid PIN, build response, invalid PIN attempt, increment FAC stored in loginData and build response)
@enduml

http://www.plantuml.com/plantuml/png/NO_1IWH134Jl-OeipC65yGSyo8eYU1713v3if926xlJOdHQ4-NYpiYouXsgQUfKKENINvgDasWtx6jMXlBQwG4S3bvyFoNupoSpJCRI4D8GzRTj6mS8ddeHlx-EzYmJnYI1tHFGVmXcP_WtludDf8ZfNlIT7IQPeCtzBJiflBwyp7qVAoWrzhTOnSx8BP757MVraBWq5vlpyyCZTQuE6oRb-9diI5nRJgrLxEi0qxly5

(note: functions should properly start with $, and the arguments really should be quoted; but I wanted to reduce clutter).

I mean, I do appreciate that you're after the existing syntax, but with your style.  But as I said, I think you need to suggest some syntax as to how that could be implemented.

commented Jul 18 by The-Lu (5,860 points)

Hello M.,

shame you can't seem to split the call over multiple lines

FYI, for split the call over multiple lines, you can use '\', like:

my_alt(Siteminder,\
    valid PIN,\
    build response,\
    invalid PIN attempt,\
    increment FAC stored in loginData and build response)

→ Link to PlantUML online server

See, "Use \ for multiline stuff" on:

Regards,
Th.

commented Jul 18 by Martin

oh that's neat; thank you!

I was thinking some more about the original OP's idea.  The following occurred to me as a proposal:

<style>
  sequenceDiagram {   
      alt {
       AltPrePadding n1
       AltPostPadding n2
       ElsePrePadding n3
       ElsePostPadding n4
       EndPrePadding n5
       EndPostPadding n6
    }
  }
}
</style> 

or, reducing style keywords:

<style>
  sequenceDiagram {  
    alt {
      prePadding n1
      postPadding n2
      altElse {
        prePadding n3
        postPadding n4
      }
      altEnd {
        prePadding n5
        postPadding n6
      }
    }
  }
</style> 

to achieve:

@startuml
||n1||
alt option 1
||n2||
 A -> B
 B -> A
 ||n3||
else option 2
||n4||
 C -> D
 D -> A
 ||n5||
end
||n6||
@enduml

Where these simply add "||n||" in front of or after each of the alt/else/end clauses.  Maybe allow n=Yes/True for the default "|||", and n=0/No/False for no added space (the default).  I chose "Padding" because it's mentioned as an existing concept in the style wiki, an alternative could be "Spacing".

Alternative:

<style>
  sequenceDiagram {  
    alt {
      Padding n1,n2
      altOption {
        Padding n3,n4
      }
    }
  }
</style> 

for:

@startuml
||n1||
alt option 1
||n3||
 A -> B
 B -> A
 ||n4||
else option 2
||n3||
 C -> D
 D -> A
 ||n4||
end
||n2||
@enduml

(if n2 or n4 are omitted then they could default to be the same as n1 and n3 respectively, giving even padding top and bottom).

But as I don't really use sequence diagrams myself, I don't know how useful this would be compared to the effort of implementing it.  And it obviously opens up a whole can worms as to expectations for the Style concept!

commented Jul 20 by anonymous
Awesome, thanks for the input!  Went with option#1.  I only just started with PlantUML and I have to admit that I had not read the section on pre-processing before posting my question.  My bad.
...