题记
最近对PlantUML/Mermaid 产生了兴趣,花了些时间快速过了一遍官方文档。
不知道画点什么来练手,那就对着常见的图形画一遍。
虽没有那种用sketch或者ps画的漂亮,那么细腻。但是这种可以用代码直接生成图形的感觉很棒。
PlantUML及Mermaid 可以制作多种多样的图,时序图,流程图,泳道图,乃至甘特图。
下面的例子中只用到了流程图,我另外一篇就用到了泳道图。
实例
单项数据流

PlantUML
@startumlskinparam activity {FontColor whiteAttributeFontColor whiteFontSize 17AttributeFontSize 15AttributeFontname Droid Sans MonoBackgroundColor #527BC6BorderColor blackArrowColor #222266}repeat:State;note right全局的状态维护end note:View;note right视图(会根据状态变化刷新)end note:Actions;note right行为(可以改动状态)end noterepeat while(true)@enduml
Mermaid
graph LRView(("View「视图层」👀")) -->|event| ActionsActions(("Actions「行为层」🤘")) -->|dispatch->commit| StateState(("State「状态层」😆")) -->|re-render| View
Vuex
PlantUML
@startumlskinparam activity {FontColor whiteAttributeFontColor whiteFontSize 17AttributeFontSize 15AttributeFontname Droid Sans MonoBackgroundColor #527BC6BorderColor blackArrowColor #222266}partition Vuex {"State" --> [render]"Vue Components""Vue Components" --> [Dispatch]"Actions""Actions" --> [Commit]"Mutations""Mutations" --> [Mutate]"State"}"Backend Api" --> "Actions""Actions" --> "Backend Api""Mutations" --> "Devtools""Devtools" --> "Mutations"@enduml
Mermaid
graph LRstyle VueComponents fill:#08b884,stroke:#08b884,stroke-width:4pxstyle Actions fill:#ffb749,stroke:#ffb749,stroke-width:2pxstyle Mutations fill:#e25963,stroke:#e25963,stroke-width:4pxstyle State fill:#8f7cb7,stroke:#8f7cb7,stroke-width:2pxstyle Backend fill:#577282,stroke:#577282,stroke-width:2pxstyle Devtools fill:#577282,stroke:#577282,stroke-width:2pxVueComponents -->|Dispatch| Actions((Actions))subgraph VuexActions --> |Commit| Mutations((Mutations))Mutations --> |Mutate| State((State))endState --> |Render| VueComponentsBackend["Backend Api"] -.-> ActionsActions -.-> BackendDevtools -.-> MutationsMutations -.-> Devtools
Vue 2.x 生命周期图

PlantUML
@startumltitle edit reviewskinparam activity {FontColor whiteAttributeFontColor whiteFontSize 17AttributeFontSize 15AttributeFontname Droid Sans MonoBackgroundColor #527BC6BorderColor blackArrowColor #222266}(*)-->"new Vue()""new Vue()" --> "Init Events & Lifecycle""Init Events & Lifecycle" --> "beforeCreate""beforeCreate" --> "Init injections & reactivity""Init injections & reactivity" --> "created""created" --> "Has 'el' options?"--> if "" then--> [YES]"Has 'template' option?"else--> [NO]"when vm.$mount(el) is called"--> "Has 'template' option?"endifif "" then--> "Compile template into render function"--> "beforeMount"else--> "Compile el's outerHTML as template"--> "beforeMount"endif--> "Create vm.$el and replace 'el' with it"--> MountedMounted --> "Virtual DOM re-render and patch""Virtual DOM re-render and patch" --> Mounted"Virtual DOM re-render and patch" --> beforeUpdate"Virtual DOM re-render and patch" --> updatedMounted --> "when vm.$destroy() is called"--> beforeDestroy--> "Teardown watchers,child components and event listeners"--> Destroyed@enduml
Mermaid
graph TDstyle newVue fill:#31495c,stroke:#31495c,stroke-width:4pxstyle InitEventsLifecycle fill:#08b884,stroke:#08b884,stroke-width:2pxstyle breforeCreate fill:#fff,stroke:#ed989c,stroke-width:4pxstyle created fill:#fff,stroke:#ed989c,stroke-width:4pxstyle beforeMount fill:#fff,stroke:#ed989c,stroke-width:4pxstyle Mounted fill:#ed989c,stroke:#ed989c,stroke-width:4pxstyle beforeUpdate fill:#fff,stroke:#ed989c,stroke-width:4pxstyle updated fill:#fff,stroke:#ed989c,stroke-width:4pxstyle beforeDestroy fill:#fff,stroke:#ed989c,stroke-width:4pxstyle Destoryed fill:#ed989c,stroke:#ed989c,stroke-width:4pxstyle CTIRF fill:#08b884,stroke:#08b884,stroke-width:2pxstyle CLOAT fill:#08b884,stroke:#08b884,stroke-width:2pxstyle VDRP fill:#08b884,stroke:#08b884,stroke-width:2pxstyle TW fill:#08b884,stroke:#08b884,stroke-width:2pxstyle InitEventsLifecycle fill:#08b884,stroke:#08b884,stroke-width:2pxnewVue["new Vue()"] --> InitEventsLifecycle["Init Events & Lifecycle"]InitEventsLifecycle -.-> breforeCreatebreforeCreate --> InitInjectionsReactivity["Init injections & reactivity"]InitInjectionsReactivity -.-> createdcreated --> HasElOption{"Has 'el' option?"}HasElOption -.->|"No(when vm.$mounted(el) is called"|HasTemplateOption{"Has 'template' option ?"}HasElOption -.->|"YES"|HasTemplateOptionHasTemplateOption -->|YES|CTIRF["Compile template into render function"]HasTemplateOption -->|NO|CLOAT["Compile el's outerHTML as template"]CTIRF -.-> beforeMountCLOAT -.-> beforeMountbeforeMount --> CEREWI["Create vm.$el and replace 'el' with it"]CEREWI -.-> Mounted((Mounted))Mounted --> VDRP["Virtual DOM re-render and patch"]VDRP --> MountedVDRP -.->|"when data changes"|beforeUpdateVDRP -.-> updatedMounted -->|"when vm.$destroy() is called"|beforeDestroybeforeDestroy --> TW["Teardown watchers,child components and event listeners"]TW --> Destoryed((Destoryed))
