Multi line text support on macro parameter

0 votes
asked Mar 7, 2019 in Question / help by gbrusella (200 points)

Is there a way to add support for multiline text as a parameter on a macro?

something like this

@startuml Sample

/' Macros '/

!definelong Event(from, to, notes)

from ->> to ++

note left

notes

end note

return

!enddefinelong

'/ End Macros/'

box

participant "Event Stream" as K #LightGreen

participant "A Service" as SRV #Green

end box

Event(K, CRV, "This could\n be a multiline\n text, but it is not.")

@enduml

2 Answers

+1 vote
answered Mar 11, 2019 by mgrol (3,150 points)

Hi,

the problem you are facing is that the kind of note you define requires a text that has already the line breaks in the text. This is difficult if you want to use it within a macro. If you use the other kind of note definition (one line) this would work:

http://www.plantuml.com/plantuml/uml/NOynRy8m44Rt-nLVmv0YqcRlWAWgr85s8HLJ5oUvW2NdZEmpukVN2KYLMDyzlK-tYMg2fj5HNUBRTC57b3NHKy-35NPUZjXUMFHv27wieBw2UEMu99e8NjRh3B5Q4KqSZWU57p0VtsukKM1DGNAMfVyl4vKrjjBVX-kIgFLNehC9QZjxDg8evdKq6jYC1Kp43eilUppfPs2M1_aT3OUBxNWsc_q1YxkMXp77Rz_iAdpi3nMAdvEDw7noFNu5BSDWJ4wjiy8JKRvgXJOfh2AhulMrMD8czzBe_W00

BR,

Michael

commented Mar 12, 2019 by gbrusella (200 points)
Sorry Michael, I cannot access that link.
+1 vote
answered Mar 12, 2019 by zimchaa (1,040 points)

An alternative to @mgrol's correct answer, which makes it much easier to control the 'wrap width' of notes is the skinparam wrapWidth parameter - it works like this:

skinparam wrapwidth approach

(Click through to see the parameter in context and change the values)

It is not something that breaks in Macros, as is shown in the example - so it can be used commonly. Also, it's worth mentioning the maxMessageSize parameter as well - which allows similar control of the messages.


@startuml
skinparam wrapWidth 30
skinparam maxMessageSize 30

/' Macros '/

!definelong Event(from, to, message, notes)

from ->> to : message

note left

notes

endnote

return

!enddefinelong

'/ End Macros/'

box

participant "Event Stream" as K #LightGreen

participant "A Service" as SRV #Green

end box

Event(K, SRV, "This is a long message", "This could be a multiline text, but it is not.")

K ->> SRV: non-macro long message

note right: Here is some more text that could cause a problem and should be wrapped by the wrapWidth skinaparam.
@enduml


commented Mar 12, 2019 by gbrusella (200 points)
Thanks for the tip. It seems to solve my issue. Thanks.
commented Mar 12, 2019 by mgrol (3,150 points)
Hi,

what I said was:

@startuml
/' Macros '/
!definelong Event(from, to, notes)
from ->> to ++
note left of from : notes
return
!enddefinelong
'/ End Macros/'
box
participant "Event Stream" as K #LightGreen
participant "A Service" as SRV #Green
end box
Event(K, CRV, "This could \n be a multiline \n text, but it is not.")
@enduml

Just change your note definition to this one: "note left of from : notes"

Oh well, the link still works for me. By clicking on it I come to the plantuml.com/plantuml website. Anyhow.

BR,
Michael
...