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

时间:2015-06-23 09:43:13

标签: documentation-generation plantuml

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

Legend with colors

如果我可以在PlantUML legendendlegend中添加HTML表格,我可以通过更改单元格背景来实现此目的。但是,添加HTML <table>并不起作用。我也尝试使用PlantUML's salt来插入表格,但我找不到任何方法来为表格的单元格着色。

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

3 个答案:

答案 0 :(得分:7)

这不完美,但您可以使用克里奥尔表。 (看到 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

Image showing the legend.

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

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

  

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

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

答案 1 :(得分:4)

我已经尝试过nfec的解决方案而且它不适合我,但它开始让我找到一个有效的解决方案。这就是我得到的。

legend right
    |Color| Type |
    |<#FF0000>| Type A class|
    |<#00FF00>| Type B class|
    |<#0000FF>| Type C class|
endlegend

答案 2 :(得分:1)

似乎没有直接的方法在PlantUML图表中包含颜色编码的图例,但我找到了一个足够接近的解决方法。

  • 在包if len(arr) < 3 { return } var ok bool l := Line{PopMap: map[string][]int{}} if l.Contig, ok = arr[0].(string); !ok { return } if l.Base, ok = arr[1].(string); !ok { return } if m, ok := arr[2].(map[string]interface{}); !ok { return } else { for k, v := range m { var nums []interface{} if nums, ok = v.([]interface{}); !ok { return } pops := make([]int, len(nums)) for i, val := range nums { if f, ok := val.(float64); !ok { return } else { pops[i] = int(f) } } l.PopMap[k] = pops } } fmt.Printf("%+v", l) 中声明类var cell = tableView.cellForRowAtIndexPath(indexPath) let selectionColor = UIView() as UIView selectionColor.layer.borderWidth = 1 selectionColor.layer.borderColor = utility.uicolorFromHex(0xEBEBEB).CGColor selectionColor.backgroundColor = utility.uicolorFromHex(0xEBEBEB) cell!.selectedBackgroundView = selectionColor TypeATypeB
  • 隐藏每个班级的圈子,方法和成员。
  • 附加&#34;隐藏&#34;类之间的连接器。


TypeC

或者,&#34;隐藏&#34;连接器可以替换为LEGEND,如下所示:

package LEGEND <<Rect>> { ' Draw the LEGEND "package" as a rectangular box.
class TypeA as "Type A Class" #LightRed
hide  TypeA circle
hide  TypeA methods
hide  TypeA members

class TypeB as "Type B Class" #LightBlue
hide  TypeB circle
hide  TypeB methods
hide  TypeB members

class TypeC as "Type C Class" #LightGreen
hide  TypeC circle
hide  TypeC methods
hide  TypeC members

' Workaround to prevent PlantUML from positioning the legend blocks randomly.
TypeA -[hidden]- TypeB
TypeB -[hidden]- TypeC
}

这些产生了以下图表。两者都不是完美的,但比在图像编辑器中单独绘制图例更好。 :-)我希望PlantUML在未来的版本中为此提供直接支持。

Legend Vertical Legend Horizontal