样式功能仍在测试阶段。
从版本
1.2019.9
开始,默认情况下对
mindmap和
wbs 图表启用样式。
对于旧图表和旧 PlantUML 版本,您必须使用
skinparam useBetaStyle true
来测试此功能。
对于新图表和新 PlantUML 版本,默认情况下启用样式。
本页有一些工作示例。
WARNING
This translation need to be updated. WARNING
目前,
皮肤参数用于更改图表的渲染(字体、颜色......)。
尽管目前的系统还在运行,但它有一些重要的局限性:
- 皮肤参数允许对整个图表进行全局更改
- 每种图表(序列、类、活动)都有自己的皮肤参数、* 活动)都有自己的 skinparam
- 可以使用
<<stereotype>>
为具有相同定型的元素组定义特定设置
- 可以使用克里奥尔语法单独更改某些设置
- 可能的 skinparam种类 繁多(请参阅plantuml-skinparam, 尝试了解它们)
- 某些元素无法定型(例如序列图中的消息)
我们的愿望:
- 可以在任何地方使用单个更改(因此可能会保留 creole 引擎)。
- 同时,可以 更改 特定 图表 类型的 设置(例如 只更改序列图)。
- 语法接近 CSS
- 在 PlantUML 核心库中不再有硬编码值(大小 、颜色......)。
plantuml.skin
- 保持简单:因为没有人会阅读文档(文档通常都是过时的),人们只需阅读示例就能理解样式系统。
- 避免样式命名的组合爆炸。 注意,
即使现有的 skinparam 语法可能会被弃用,所有现有的遗留图仍应能在未来版本的 PlantUML 中使用。
WARNING
This translation need to be updated. WARNING
可以设置样式的属性如下:
- FontName
- FontColor
- FontSize
- FontStyle
- BackGroundColor
- HyperLinkColor
- LineColor(old
BorderColor):似乎更通用
- LineThickness
- LineStyle(旧的
BorderStyle):实数或用-
分隔的两个实数
- Padding
- Margin
- RoundCorner
- 对角线角
- ExportedName: 用于某些格式(SVG),未实现
- Image: 未* 实现
- ImagePosition:* 未实现
- MinimumWidth:* 未实现
- WordWrap(将更名为 MaximumWidth)(如果需要,添加回车)
- HorizontalAlignment : 左、右或居中
...
The current model has moved to work similarly to CSS, using a model of scoping and cascading styles to either element types or user-assigned styles (via
<<stereotype>>
notation).
Style can be inlined using
<style>
and
</style>
separators.
It is also possible to store style definition in some external file and to reference it using
<style file=MyOwnFile.css>
.
Basic example of a Sequence Diagram style
🎉 Copied!
|
@startuml
skinparam useBetaStyle true
' style enclosure declaration
<style>
' scope to sequenceDiagram elements
sequenceDiagram {
' scope to actor element types
actor {
FontColor Blue
}
}
}
</style>
' printed in blue
actor Bob
' also printed in blue
actor Sally
@enduml
|
Basic example of a Work Breakdown Structure style
Let's at a different example, that of a Work Breakdown Structure:
🎉 Copied!
|
@startwbs
<style>
' this time, scoping to wbsDiagram
wbsDiagram {
' Here we introduce a global style, i.e. not targeted to any element
' thus all lines (meaning connector and borders,
' there are no other lines in WBS) are black by default
Linecolor black
' But we can also target a diagram specific element, like arrow
arrow {
' note that Connectors are actually "Arrows"; this may change in the future
' so this means all Connectors and Arrows are now going to be green
LineColor green
}
}
</style>
* World
** America
*** Canada
** Europe
*** England
*** Germany
*** Spain
@endwbs
|
We can extend these examples to start targeting not just element
types, but
specific elements.
Using user defined styles in a Sequence Diagram
🎉 Copied!
|
@startuml
skinparam useBetaStyle true
' style enclosure declaration
<style>
' scope to sequenceDiagram elements
sequenceDiagram {
' scope to actor element types
actor {
FontColor Blue
}
' define a new style, using CSS class syntax
.myStyle {
FontColor Red
}
}
</style>
' printed in blue
actor Bob
' this will now be printed in Red
actor Sally <<myStyle>>
@enduml
|
NOTE: If the <<myStyle>>
is showing, it is likely a bug, resolved in newer betas.
NOTE: This section is still very experimental and may change!
As we are following the CSS model now, then it should be possible to use selectors to simplify targeting groups of elements, like those "children" (or "downstream") of a given element in diagrams like Work Breakdown or MindMaps.
Using the depth selector in a WBS
🎉 Copied!
|
@startwbs
<style>
wbsDiagram {
' all lines (meaning connector and borders, there are no other lines in WBS) are black by default
Linecolor Black
arrow {
' Note that connector are actually "arrows" even if they don't look like arrows
' This is to be consistent with other UML diagrams. Not 100% sure that it's a good idea
' So now connectors are green at this level
LineColor Green
}
:depth(0) {
' will target the "root" (first level) node,
' AND root level elements like Arrows (styled by Line styles)
' Note how it will override the
BackgroundColor White
RoundCorner 10
LineColor red
}
arrow {
:depth(2) {
' Targetting only connector between Mexico-Chihuahua and USA-Texas
LineColor blue
LineStyle 4
LineThickness .5
}
}
node {
:depth(2) {
' Targetting the Lines at a depth of 2
LineStyle 2
LineThickness 2.5
}
}
}
</style>
* World
** America
*** Canada
*** Mexico
**** Chihuahua
*** USA
**** Texas
***< New York
** Europe
*** England
*** Germany
*** Spain
@endwbs
|
Using the "descendant" pseudo selector
Of course, sometimes you want to target all "child" (or "downstream") elements of a given element. The
*
selector works as in CSS, to say: "this element, and all elements of
any type that is it's child".
An example:
🎉 Copied!
|
@startwbs
<style>
wbsDiagram {
Linecolor black
arrow {
LineColor green
}
:depth(1) {
BackgroundColor White
RoundCorner 10
LineColor red
}
.mexicoStyle * {
BackgroundColor Red
FontColor White
RoundCorner 10
}
}
</style>
* World
** America
*** Canada
*** Mexico <<mexicoStyle>>
**** Chihuahua
*** USA
**** Texas
***< New York
** Europe
*** England
*** Germany
*** Spain
@endwbs
|
NOTE: This is still a work in progress, and may not work as expected.
If a file named
plantuml.skin
is found in the same folder as the diagram, it will attempt to be loaded and used during diagram creation. This lays the groundwork--along with scoping styles to specific diagrams, and user defined styles--for creating truly complex and persistent styles, without including them in each of your diagrams.
注意:这仍是一项进行中的工作,可能不会显示每个图表中的每个元素。
您可以使用
-v
(或
-verbose
)命令行参数获取一些调试输出,以帮助您确定哪些元素正在使用中,从而可以锁定它们。
java -jar plantuml.jar -v -tpng diagram.pu
结果如下:
(0.378 - 256 Mo) 238 Mo - Using style node.depth(0).root.wbsdiagram.rootnode.element
(0.546 - 256 Mo) 237 Mo - Using style depth(2).node.root.wbsdiagram.leafnode.element
(0.547 - 256 Mo) 237 Mo - Using style depth(2).node.root.*.wbsdiagram.element
(0.560 - 256 Mo) 236 Mo - Using style node.root.depth(3).wbsdiagram.leafnode.element
(0.561 - 256 Mo) 236 Mo - Using style node.root.depth(3).*.wbsdiagram.mexicostyle.element
(0.562 - 256 Mo) 236 Mo - Using style node.root.depth(3).*.wbsdiagram.element
(0.565 - 256 Mo) 236 Mo - Using style depth(2).node.root.wbsdiagram.mexicostyle.element
(0.569 - 256 Mo) 235 Mo - Using style depth(2).node.root.wbsdiagram.element
(0.571 - 256 Mo) 235 Mo - Using style node.depth(1).root.wbsdiagram.element
(0.572 - 256 Mo) 235 Mo - Using style node.depth(1).root.*.wbsdiagram.element
(1.963 - 256 Mo) 250 Mo - Using style depth(0).arrow.root.wbsdiagram.element
(1.964 - 256 Mo) 250 Mo - Using style depth(1).arrow.root.wbsdiagram.element
(1.965 - 256 Mo) 250 Mo - Using style depth(2).arrow.root.wbsdiagram.element