如何在PlantUML中生成带颜色的图例?

Mas*_*Man 10 documentation-generation plantuml

我想基于某个标准在我的类图中为类着色,然后显示一个看起来大致如下的图例:

传奇与颜色

如果我能内PlantUML的添加HTML表格legendendlegend,我可以通过更改单元格背景实现这一目标.但是,添加HTML <table>不起作用.我也尝试使用PlantUMLsalt来插入表格,但我找不到任何方法来为表格的单元格着色.

有没有办法实现这个目标?

nfe*_*fec 10

这不是完美的,但你可以使用克里奥尔表.(见 http://plantuml.sourceforge.net/creole.html)

@startuml class foo

 legend |= |= Type | |<back:#FF0000>   </back>| Type A class |
 |<back:#00FF00>   </back>| Type B class | |<back:blue>   </back>| Type
 C class | endlegend

@enduml
Run Code Online (Sandbox Code Playgroud)

显示图例的图像.

有一些绘图工件,但它是你期待的吗?

来自plantuml论坛.他们允许在这里复制这个答案.

是的,请将我们的答案复制/粘贴到StackOverflow:它确实很有帮助

http://plantuml.sourceforge.net/qa/?qa=3596/how-to-generate-a-legend-with-colors-in-plantuml


Ama*_*den 10

我尝试了nfec的解决方案,但该解决方案对我不起作用,但它使我开始尝试了一种可行的解决方案。这就是我得到的。

legend right
    |Color| Type |
    |<#FF0000>| Type A class|
    |<#00FF00>| Type B class|
    |<#0000FF>| Type C class|
endlegend
Run Code Online (Sandbox Code Playgroud)

  • 这对我来说比接受的答案要好得多。另外,值得一提的是,您可以使用颜色名称而不是十六进制值(如下所示:https://github.com/qywx/PlantUML-colors) (2认同)

cry*_*ick 8

以其他答案为基础,获取样式符合原始请求的图例:

传奇

' set legend to have a white background
skinparam legendBackgroundColor #FFFFFF
' remove box around legend
skinparam legendBorderColor #FFFFFF
' remove the lines between the legend items
skinparam legendEntrySeparator #FFFFFF


legend right
'   the <#FFFFFF,#FFFFFF> sets the background color of the legend to white
    <#FFFFFF,#FFFFFF>|<#red>| Type A Classes|
    ' the space between the | and <#blue> is important to make the color column wider
    |<#blue>     | Type B Classes|
    |<#green>| Type C Classes|
endlegend
Run Code Online (Sandbox Code Playgroud)

使用的参考文献,以防有人需要进一步设计样式:1 , 2