PlantUML——定时图
PlantUML定时图
- 1、声明参与者
- 2、二进制及时钟信号
- 3、增加标示
- 4、相对时间
- 5、锚点
- 6、参与者
- 7、设置缩放
- 8、初始状态
- 9、模糊状态
- 9.1、模糊或者未定义鲁棒状态信号
- 9.2、模糊或者未定义二进制信号
- 10、隐藏状态
- 11、隐藏时间轴
- 12、使用日期
- 13、Change Date Format
- 14、Manage time axis labels
- 14.1、Label on each tick (by default)
- 14.2、Manual label (only when the state changes)
- 15、添加约束
- 15.1、= 设置高亮
- 16、添加注释
- 17、添加文本
- 18、完整样例
- 19、数据表示样例
- 20、颜色
- 21、使用(全局)样式
- 21.1、无样式(默认样式)
- 21.2、设置样式
- 22、对特定行着色
UML 中的时序图是一种特定类型的交互图,可视化系统的时序约束。它侧重于事件的时间顺序,展示不
同对象如何随着时间的推移相互影响。定时图在实时系统和嵌入式系统中特别有用,可用于了解对象在
整个给定时间段内的行为。
1、声明参与者
使用以下关键字声明参与者, 可根据需要选择显示样式。
通过 @ 标注, 和 is 动词定义状态.
@startuml robust"Web 浏览器"asWBconcise"Web 用户"asWU@0WUis 空闲WBis 空闲 @100WUis 等待中WBis 处理中 @300WBis 等待中 @enduml@startuml clock"Clock_0"asC0withperiod50clock"Clock_1"asC1withperiod50pulse15offset10binary"Binary"asBconcise"Concise"asCrobust"Robust"asRanalog"Analog"asA@0Cis IdleRis IdleAis0@100Bis highCis WaitingRis ProcessingAis3@300Ris WaitingAis1@enduml2、二进制及时钟信号
使用以下关键字可以绘制二进制及时钟信号:
- binary
- clock
@startuml clock clkwithperiod1binary"Enable"asEN@0ENis low @5ENis high @10ENis low @enduml3、增加标示
使用下述的语法,增加对某一时刻信号变动的描述。
@startuml robust"Web 浏览器"asWBconcise"Web 用户"asWU@0WUis 空闲WBis 空闲 @100WU->WB:URLWUis 等待中WBis 处理中 @300WBis 等待中 @enduml4、相对时间
可以使用@+和@-符号表示相对时间.
@startuml robust"DNS Resolver"asDNSrobust"Web Browser"asWBconcise"Web User"asWU@0WUis IdleWBis IdleDNSis Idle @+100WU->WB:URLWUis WaitingWBis Processing @+200WBis WaitingWB->DNS@+50:ResolveURL@+100DNSis Processing @+300DNSis Idle @enduml5、锚点
在绝对时间上使用绝对时间或相对时间,你可以通过使用 as 关键字和以: 开始的名称来定义一个时间作为锚点。
@XX as :<anchor point name>
@startuml clock clkwithperiod1binary"enable"asENconcise"dataBus"asdb @0as:start @5as:en_high @10as:en_low @:en_high-2as:en_highMinus2 @:startENis low db is"0x0000"@:en_highENis high @:en_lowENis low @:en_highMinus2 db is"0xf23a"@:en_high+6db is"0x0000"@enduml6、参与者
按时间顺序来描述状态变化可能会有些麻烦,不如将每个参与者的变化放在一起。
@startuml robust"Web Browser"asWBconcise"Web User"asWU@WB0is idle+200is Proc.+100is Waiting @WU0is Waiting+500is ok @enduml7、设置缩放
还可以设置缩放比例。
@startuml concise"Web User"asWUscale100as50pixels @WU0is Waiting+500is ok @enduml
当使用绝对时间或者日期时,1 单位为 1 秒。
@startuml concise"季节"asS'这里将30天缩放到50像素 scale2592000as50pixels @2000/11/01Sis"冬"@2001/02/01Sis"春"@2001/05/01Sis"夏"@2001/08/01Sis"秋"@enduml8、初始状态
可以定义初始状态。
@startuml robust"Web Browser"asWBconcise"Web User"asWUWBis InitializingWUis Absent @WB0is idle+200is Processing+100is Waiting @WU0is Waiting+500is ok @enduml9、模糊状态
一个信号在某个时段可能是模糊的,有多个可能的状态区间。
9.1、模糊或者未定义鲁棒状态信号
@startuml robust"Signal1"asS1robust"Signal2"asS2S1has0,1,2,helloS2has0,1,2@0S1is0S2is0@100S1is{0,1}#SlateGreyS2is{0,1}@200S1is1S2is0@300S1is helloS2is{0,2}@enduml9.2、模糊或者未定义二进制信号
@startuml clock"Clock"asCwithperiod2binary"Enable"asEN@0ENis low @1ENis high @3ENis low @5ENis{low,high}@10ENis low @enduml10、隐藏状态
可以隐藏某个时段的状态。
@startuml concise"Web User"asWU@0WUis{-}@100WUisA1@200WUis{-}@300WUis{hidden}@400WUisA3@500WUis{-}@enduml@startuml scale1as50pixels concise state0 concise substate1 robust bit2 bit2 hasHIGH,LOW@state00is 18_start6is s_dPause8is 10_data14is{hidden}@substate10is sSeq4is sPause6is{hidden}8is dSeq12is dPause14is{hidden}@bit20isHIGH2isLOW4is{hidden}8isHIGH10isLOW12is{hidden}@enduml11、隐藏时间轴
可以隐藏时间轴。
@startuml hide time-axis concise"Web User"asWUWUis Absent @WU0is Waiting+500is ok @enduml12、使用日期
时间轴除时间以外也可以改用日期表示。
@startuml robust"Web Browser"asWBconcise"Web User"asWU@2019/07/02WUis IdleWBis Idle @2019/07/04WUis Waiting:some noteWBis Processing:some other note @2019/07/05WBis Waiting @enduml@startuml robust"Web Browser"asWBconcise"Web User"asWU@1:15:00WUis IdleWBis Idle @1:16:30WUis Waiting:some noteWBis Processing:some other note @1:17:30WBis Waiting @enduml13、Change Date Format
@startuml robust"Web Browser"asWBconcise"Web User"asWUuse date format"YY-MM-dd"@2019/07/02WUis IdleWBis Idle @2019/07/04WUis Waiting:some noteWBis Processing:some other note @2019/07/05WBis Waiting @enduml14、Manage time axis labels
14.1、Label on each tick (by default)
@startuml scale31536000as40pixels use date format"yy-MM"concise"OpenGL Desktop"asOD@1992/01/01ODis{hidden}@1992/06/30ODis1.0@1997/03/04ODis1.1@1998/03/16ODis1.2@2001/08/14ODis1.3@2004/09/07ODis3.0@2008/08/01ODis3.0@2017/07/31ODis4.6@enduml14.2、Manual label (only when the state changes)
@startuml scale31536000as40pixels manual time-axis use date format"yy-MM"concise"OpenGL Desktop"asOD@1992/01/01ODis{hidden}@1992/06/30ODis1.0@1997/03/04ODis1.1@1998/03/16ODis1.2@2001/08/14ODis1.3@2004/09/07ODis3.0@2008/08/01ODis3.0@2017/07/31ODis4.6@enduml15、添加约束
可以在图上标示时间约束。
@startuml robust"Web Browser"asWBconcise"Web User"asWUWBis InitializingWUis Absent @WB0is idle+200is Processing+100is WaitingWB@0<->@50:{50ms lag}@WU0is Waiting+500is ok @200<->@+150:{150ms}@enduml15.1、= 设置高亮
可以给图表中的某一时段设置高亮。
@startuml robust"Web Browser"asWBconcise"Web User"asWU@0WUis IdleWBis Idle @100WU->WB:URLWUis Waiting #LightCyan;line:Aqua @200WBis Proc.@300WU->WB@350:URL2WBis Waiting @+200WUis ok @+200WBis Idle highlight200to450#Gold;line:DimGrey:This is my caption @enduml16、添加注释
可以使用 note top of 或 note bottom of 关键字在某一时刻或参与者的上方或下方添加注释 (只可以在 concise 类型的参与者中使用)。
@startuml robust"Web Browser"asWBconcise"Web User"asWU@0WUis IdleWBis Idle @100WUis WaitingWBis Processing note topofWU:first note\non several\nlines note bottomofWU:second note\non several\nlines @300WBis Waiting @enduml17、添加文本
可以选择添加标题、页眉、页脚、图例和说明。
@startuml Title Some titleheader:Some headerfooter:Some footer legend Some legend end legend caption Some caption robust"Web Browser"asWBconcise"Web User"asWU@0WUis IdleWBis Idle @100WUis WaitingWBis Processing @300WBis Waiting @enduml18、完整样例
@startuml concise"Client"asClient concise"Server"asServer concise"Response freshness"asCache Server is idle Client is idle @Client0is send Client->Server@+25:GET+25isawait+75is recv+25is idle+25is send Client->Server@+25:GET\nIf-Modified-Since:150+25isawait+50is recv+25is idle @100<->@275:no need to re-request from server @Server25is recv+25is work+25is send Server->Client@+25:200OK\nExpires:275+25is idle+75is recv+25is send Server->Client@+25:304Not Modified+25is idle @Cache75is fresh+200is stale @enduml19、数据表示样例
@startuml scale5as150pixels clock clkwithperiod1binary"enable"asen binary"R/W"asrw binary"data Valid"asdv concise"dataBus"asdb concise"address bus"asaddr @6as:write_beg @10as:write_end @15as:read_beg @19as:read_end @0en is low db is"0x0"addr is"0x03f"rw is low dv is0@:write_beg-3en is high @:write_beg-2db is"0xDEADBEEF"@:write_beg-1dv is1@:write_beg rw is high @:write_end rw is low dv is low @:write_end+1rw is low db is"0x0"addr is"0x23"@12dv is high @13db is"0xFFFF"@20en is low dv is low @21db is"0x0"highlight:write_beg to:write_end #Gold:Writehighlight:read_beg to:read_end #lightBlue:Read db@:write_beg-1<->@:write_end:setup time db@:write_beg-1->addr@:write_end+1:hold @enduml20、颜色
可以为图表添加颜色。
@startuml concise"LR"asLRconcise"ST"asSTLRis AtPlace #palegreenSTis AtLoad #gray @LR0is Lowering100is Lowered #pink350is Releasing @ST200is Moving @enduml21、使用(全局)样式
21.1、无样式(默认样式)
@startuml robust"Web Browser"asWBconcise"Web User"asWUWBis InitializingWUis Absent @WB0is idle+200is Processing+100is WaitingWB@0<->@50:{50ms lag}@WU0is Waiting+500is ok @200<->@+150:{150ms}@enduml21.2、设置样式
可以使用样式来改变元素的渲染
@startuml<style>timingDiagram{document{BackGroundColor SandyBrown}constraintArrow{LineStyle2-1LineThickness3LineColor Blue}}</style>robust"Web Browser"asWBconcise"Web User"asWUWBis InitializingWUis Absent @WB0is idle+200is Processing+100is WaitingWB@0<->@50:{50ms lag}@WU0is Waiting+500is ok @200<->@+150:{150ms}@enduml22、对特定行着色
可以使用<style>标记和模板将行属性命名
@startuml<style>timingDiagram{.red{LineColor red}.blue{LineColor blue LineThickness5}}</style>clock clkwithperiod1binary"Input Signal 1"asIS1binary"Input Signal 2"asIS2<<blue>>binary"Output Signal 1"asOS1<<red>>@0IS1is lowIS2is highOS1is low @2OS1is high @4OS1is low @5IS1is highOS1is high @6IS2is low @10IS1is lowOS1is low @enduml