How to add arrows to a legend or a table?

+3 votes
asked May 27, 2020 in Question / help by CaribeLady

I want to create a legend where I give the meaning of the arrows. As follows. However 

legend
   |=|= blah|
   | --> | blah1|
   | -[dashed]-> |blah2|
   | -[dotted]-> | blah3 |
endlegend

Somehow I did not find a way to upload an image, but the arrows do not show. Just the same as the text.

3 Answers

0 votes
answered Aug 31, 2020 by The-Lu (74,900 points)

Hello C.

Adapted from: https://forum.plantuml.net/9142/how-to-explain-used-line-types-associations-in-a-diagram

and from this answer : https://forum.plantuml.net/9142/how-to-explain-used-line-types-associations-in-a-diagram?show=9149#c9149

→ "You can create an image and after use it on all your diagrams [or legend table]"
[With this constraint: the [image] output must be a PNG]

Here is a possible example:


[Code on PlantUML online server]

If that can help,
Regards,
Th.

commented Sep 1, 2020 by anonymous

Thank you very much!, This might work. And I ask for something along these lines. However, looks like the feature of having a diagram inside a table is not enabled yet. If so, these table was a lot easier to do.

+1 vote
answered Dec 16, 2021 by mr.spuratic (140 points)
edited Dec 17, 2021 by mr.spuratic

If you only need simple arrows, then Unicode should work for you (subject to font glyph coverage):

@startuml
legend left
  Legend
  |<color:blue><size:18><&arrow-right></size></color> | some text |
  |<color:green><size:18><&arrow-right></size></color>| other text |
  |<color:red><size:18><U+2B38></size></color>|leftwards dotted arrow|
  |<color:purple><size:18><U+2911></size></color>|rightwards dotted arrow|
  |<color:orange><size:18><U+21E0></size></color>|leftwards dashed arrow|
  |<color:black><size:18><U+21E2></size></color>|rightwards dashed arrow|
end legend
@enduml

Sample legend
[source online]

A more flexible alternative is to (ab)use a sub-diagram:

legend left
{{
  scale 0.75

  card Relations {
    together  {
      label "some label"
      (a) -[#blue;#green,dashed,thickness=4]right-> (b) : deduced
      (b) -[#purple]left-> (a) : inferred
    }
    together {
      label "more text"
      (c) -[#red,dashed,thickness=1]right-> (d)  : relation
    }
    together {
      label "description"
      (e) -[#green,thickness=2]right-> (f)  : derived
    }
    a -[hidden]d-> c
    c -[hidden]d-> e
}}
Legend
end legend


[source online]

+1 vote
answered Dec 16, 2021 by Martin (9,120 points)

Here's an idea using a map table, which does support sub-diagrams:

(click diagram for online server)

commented Dec 17, 2021 by mr.spuratic (140 points)
Certainly a lot neater and more compact than my card approach (and no layout hacks required :)
...