题记

最近对PlantUML/Mermaid 产生了兴趣,花了些时间快速过了一遍官方文档。

不知道画点什么来练手,那就对着常见的图形画一遍。

虽没有那种用sketch或者ps画的漂亮,那么细腻。但是这种可以用代码直接生成图形的感觉很棒。

PlantUML及Mermaid 可以制作多种多样的图,时序图,流程图,泳道图,乃至甘特图。

下面的例子中只用到了流程图,我另外一篇就用到了泳道图。

理想化的研发流程

实例

单项数据流

image.png

PlantUML

PlantUML/Mermaid绘制Vue及Vuex状态图 - 图2

  1. @startuml
  2. skinparam activity {
  3. FontColor white
  4. AttributeFontColor white
  5. FontSize 17
  6. AttributeFontSize 15
  7. AttributeFontname Droid Sans Mono
  8. BackgroundColor #527BC6
  9. BorderColor black
  10. ArrowColor #222266
  11. }
  12. repeat
  13. :State;
  14. note right
  15. 全局的状态维护
  16. end note
  17. :View;
  18. note right
  19. 视图(会根据状态变化刷新)
  20. end note
  21. :Actions;
  22. note right
  23. 行为(可以改动状态)
  24. end note
  25. repeat while(true)
  26. @enduml

Mermaid

PlantUML/Mermaid绘制Vue及Vuex状态图 - 图3

  1. graph LR
  2. View(("View「视图层」👀")) -->|event| Actions
  3. Actions(("Actions「行为层」🤘")) -->|dispatch->commit| State
  4. State(("State「状态层」😆")) -->|re-render| View

Vuex

image.png

PlantUML

PlantUML/Mermaid绘制Vue及Vuex状态图 - 图5

  1. @startuml
  2. skinparam activity {
  3. FontColor white
  4. AttributeFontColor white
  5. FontSize 17
  6. AttributeFontSize 15
  7. AttributeFontname Droid Sans Mono
  8. BackgroundColor #527BC6
  9. BorderColor black
  10. ArrowColor #222266
  11. }
  12. partition Vuex {
  13. "State" --> [render]"Vue Components"
  14. "Vue Components" --> [Dispatch]"Actions"
  15. "Actions" --> [Commit]"Mutations"
  16. "Mutations" --> [Mutate]"State"
  17. }
  18. "Backend Api" --> "Actions"
  19. "Actions" --> "Backend Api"
  20. "Mutations" --> "Devtools"
  21. "Devtools" --> "Mutations"
  22. @enduml

Mermaid

PlantUML/Mermaid绘制Vue及Vuex状态图 - 图6

  1. graph LR
  2. style VueComponents fill:#08b884,stroke:#08b884,stroke-width:4px
  3. style Actions fill:#ffb749,stroke:#ffb749,stroke-width:2px
  4. style Mutations fill:#e25963,stroke:#e25963,stroke-width:4px
  5. style State fill:#8f7cb7,stroke:#8f7cb7,stroke-width:2px
  6. style Backend fill:#577282,stroke:#577282,stroke-width:2px
  7. style Devtools fill:#577282,stroke:#577282,stroke-width:2px
  8. VueComponents -->|Dispatch| Actions((Actions))
  9. subgraph Vuex
  10. Actions --> |Commit| Mutations((Mutations))
  11. Mutations --> |Mutate| State((State))
  12. end
  13. State --> |Render| VueComponents
  14. Backend["Backend Api"] -.-> Actions
  15. Actions -.-> Backend
  16. Devtools -.-> Mutations
  17. Mutations -.-> Devtools

Vue 2.x 生命周期图

image.png

PlantUML

PlantUML/Mermaid绘制Vue及Vuex状态图 - 图8

  1. @startuml
  2. title edit review
  3. skinparam activity {
  4. FontColor white
  5. AttributeFontColor white
  6. FontSize 17
  7. AttributeFontSize 15
  8. AttributeFontname Droid Sans Mono
  9. BackgroundColor #527BC6
  10. BorderColor black
  11. ArrowColor #222266
  12. }
  13. (*)-->"new Vue()"
  14. "new Vue()" --> "Init Events & Lifecycle"
  15. "Init Events & Lifecycle" --> "beforeCreate"
  16. "beforeCreate" --> "Init injections & reactivity"
  17. "Init injections & reactivity" --> "created"
  18. "created" --> "Has 'el' options?"
  19. --> if "" then
  20. --> [YES]"Has 'template' option?"
  21. else
  22. --> [NO]"when vm.$mount(el) is called"
  23. --> "Has 'template' option?"
  24. endif
  25. if "" then
  26. --> "Compile template into render function"
  27. --> "beforeMount"
  28. else
  29. --> "Compile el's outerHTML as template"
  30. --> "beforeMount"
  31. endif
  32. --> "Create vm.$el and replace 'el' with it"
  33. --> Mounted
  34. Mounted --> "Virtual DOM re-render and patch"
  35. "Virtual DOM re-render and patch" --> Mounted
  36. "Virtual DOM re-render and patch" --> beforeUpdate
  37. "Virtual DOM re-render and patch" --> updated
  38. Mounted --> "when vm.$destroy() is called"
  39. --> beforeDestroy
  40. --> "Teardown watchers,child components and event listeners"
  41. --> Destroyed
  42. @enduml

Mermaid

PlantUML/Mermaid绘制Vue及Vuex状态图 - 图9

  1. graph TD
  2. style newVue fill:#31495c,stroke:#31495c,stroke-width:4px
  3. style InitEventsLifecycle fill:#08b884,stroke:#08b884,stroke-width:2px
  4. style breforeCreate fill:#fff,stroke:#ed989c,stroke-width:4px
  5. style created fill:#fff,stroke:#ed989c,stroke-width:4px
  6. style beforeMount fill:#fff,stroke:#ed989c,stroke-width:4px
  7. style Mounted fill:#ed989c,stroke:#ed989c,stroke-width:4px
  8. style beforeUpdate fill:#fff,stroke:#ed989c,stroke-width:4px
  9. style updated fill:#fff,stroke:#ed989c,stroke-width:4px
  10. style beforeDestroy fill:#fff,stroke:#ed989c,stroke-width:4px
  11. style Destoryed fill:#ed989c,stroke:#ed989c,stroke-width:4px
  12. style CTIRF fill:#08b884,stroke:#08b884,stroke-width:2px
  13. style CLOAT fill:#08b884,stroke:#08b884,stroke-width:2px
  14. style VDRP fill:#08b884,stroke:#08b884,stroke-width:2px
  15. style TW fill:#08b884,stroke:#08b884,stroke-width:2px
  16. style InitEventsLifecycle fill:#08b884,stroke:#08b884,stroke-width:2px
  17. newVue["new Vue()"] --> InitEventsLifecycle["Init Events & Lifecycle"]
  18. InitEventsLifecycle -.-> breforeCreate
  19. breforeCreate --> InitInjectionsReactivity["Init injections & reactivity"]
  20. InitInjectionsReactivity -.-> created
  21. created --> HasElOption{"Has 'el' option?"}
  22. HasElOption -.->|"No(when vm.$mounted(el) is called"|HasTemplateOption{"Has 'template' option ?"}
  23. HasElOption -.->|"YES"|HasTemplateOption
  24. HasTemplateOption -->|YES|CTIRF["Compile template into render function"]
  25. HasTemplateOption -->|NO|CLOAT["Compile el's outerHTML as template"]
  26. CTIRF -.-> beforeMount
  27. CLOAT -.-> beforeMount
  28. beforeMount --> CEREWI["Create vm.$el and replace 'el' with it"]
  29. CEREWI -.-> Mounted((Mounted))
  30. Mounted --> VDRP["Virtual DOM re-render and patch"]
  31. VDRP --> Mounted
  32. VDRP -.->|"when data changes"|beforeUpdate
  33. VDRP -.-> updated
  34. Mounted -->|"when vm.$destroy() is called"|beforeDestroy
  35. beforeDestroy --> TW["Teardown watchers,child components and event listeners"]
  36. TW --> Destoryed((Destoryed))