How to use text formatting in notes?

0 votes
asked Apr 30, 2020 in Question / help by Lucas Lima
edited May 4, 2020

Hi there!
I'm trying to generate a legend dynamically. To achieve that, I have a global text variable to which I append text each time a new legend is inserted. 

I'm facing two issues, and I'm open to suggestions. The first of them is that I don't know how to use the text formatting (namely, how to insert a new line with \n) inside a right side note - the text simply gets written literally. No good. I'm having to use a component or a cloud to use the formatting, but then I don't know how to position it appropriately - as you can see, I'm anchoring it to a component, which is not good. I wanted it bottom right. How could I do this?

It looks like this currently:
@startuml
!global $legendText = "Notes"
!global $legendIndex = 0

!unquoted function $insertNote(position, element, text)
    !global $legendIndex = $legendIndex + 1
    !global $legendText = $legendText + "\n" + $legendIndex + ". " + text
    note position of element #white
        $legendIndex
    end note
!endfunction

component a
component b

a -> b

$insertNote(left, a, "somewhat long text to be inserted here")

$insertNote(right, b, "A REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY REALLY LLONG NOTE THAT CANNOT BE WRRITEN IN 2 LINES")

component notes as "$legendText" #white
a -[#hidden]down-> notes

@enduml

2 Answers

0 votes
answered May 1, 2020 by The-Lu (64,760 points)

Hello Lucas,

As you used, we can use ‘void function’ (for old version)  or ‘procedure’ (from 19 Apr, 2020: Introducing procedure in preprocessor (V1.2020.7))

With that, on the PlantUML Server (on version 1.2020.09beta11), it seems to work:

[Click on the image to view the code on PlantUML Web Server]

We observe:

  • Only the too large note, but you can change ‘PLANTUML_LIMIT_SIZE’ (see I want to generate huge diagrams! on the FAQ);
  • [and a white line between the component ‘a’ and the component ‘notes’ (come from the hidden arrow), but we can just suppress the ‘#’ before ‘hidden': and the line desappears.]

If that can help,
Regards,
Th.

0 votes
answered May 1, 2020 by The-Lu (64,760 points)

Hello Lucas,

Also (in complement of my first answer), to attemp to answer of your two questions ( wink [hidden] at the end of your code):

I'm facing two issues, and I'm open to suggestions.

The first of them is that I don't know how to use the text formatting (namely, how to insert a new line with \n) inside a right side note - the text simply gets written literally. No good.

I'm having to use a component or a cloud to use the formatting, but then I don't know how to position it appropriately - as you can see, I'm anchoring it to a component, which is not good. I wanted it bottom right.

How could I do this?

As testing with:

It seems that you can use '\n' [only] on one-line notes as :

!$n="1a\n2b\n3c\n"
[a]
note right of a : header_note $n footer_note

but not in multi-line as:

!$n="1a\n2b\n3c\n"
[a]
note left of a 
header_note
$n
footer_note
end note

Here is a sum up of the today's test:


[Click on the image to see on PlantUML Server]


For the different kind of notes, see: Note and floating notes on PlantUML website

If it can help,
Regards,
Th.

commented May 4, 2020 by Lucas Pereira Lima
Thank you for your time and answer!
Only now I've realized that my actual questions got hidden inside the code. I've moved them up, thanks.

I guess it is simply not possible to do what I entered right now. I could also use a legend, but the \n does not get pre-processed as well...

Besides that, do you have any suggestions regarding the positioning of the component holding the text? Anchoring it to another component is very circumstantial, as I might not have a suitable component to place it appropriately.
Once again, thank you!
...