mobile wallpaper 1mobile wallpaper 2mobile wallpaper 3mobile wallpaper 4mobile wallpaper 5mobile wallpaper 6
393 字
1 分钟
Markdown Mermaid
2023-10-01

Markdown 与 Mermaid 图表完整指南#

本文演示如何在 Markdown 文档中使用 Mermaid 创建各种复杂图表,包括流程图、序列图、甘特图、类图和状态图。

流程图示例#

流程图非常适合展示流程或算法步骤。

graph TD A[Start] --> B{Condition Check} B -->|Yes| C[Process Step 1] B -->|No| D[Process Step 2] C --> E[Subprocess] D --> E subgraph E [Subprocess Details] E1[Substep 1] --> E2[Substep 2] E2 --> E3[Substep 3] end E --> F{Another Decision} F -->|Option 1| G[Result 1] F -->|Option 2| H[Result 2] F -->|Option 3| I[Result 3] G --> J[End] H --> J I --> J

序列图示例#

序列图显示了对象在一段时间内的交互情况。

sequenceDiagram participant User participant WebApp participant Server participant Database User->>WebApp: Submit Login Request WebApp->>Server: Send Auth Request Server->>Database: Query User Credentials Database-->>Server: Return User Data Server-->>WebApp: Return Auth Result alt Auth Successful WebApp->>User: Show Welcome Page WebApp->>Server: Request User Data Server->>Database: Get User Preferences Database-->>Server: Return Preferences Server-->>WebApp: Return User Data WebApp->>User: Load Personalized Interface else Auth Failed WebApp->>User: Show Error Message WebApp->>User: Prompt Re-entry end

甘特图示例#

甘特图非常适合展示项目计划和时间表。

gantt title Website Development Project Timeline dateFormat YYYY-MM-DD axisFormat %m/%d section Design Phase Requirements Analysis :a1, 2023-10-01, 7d UI Design :a2, after a1, 10d Prototype Creation :a3, after a2, 5d section Development Phase Frontend Development :b1, 2023-10-20, 15d Backend Development :b2, after a2, 18d Database Design :b3, after a1, 12d section Testing Phase Unit Testing :c1, after b1, 8d Integration Testing :c2, after b2, 10d User Acceptance Testing :c3, after c2, 7d section Deployment Production Deployment :d1, after c3, 3d Launch :milestone, after d1, 0d

类图示例#

类图展示了系统的静态结构,包括类、属性、方法及其之间的关系。

classDiagram class User { +String username +String password +String email +Boolean active +login() +logout() +updateProfile() } class Article { +String title +String content +Date publishDate +Boolean published +publish() +edit() +delete() } class Comment { +String content +Date commentDate +addComment() +deleteComment() } class Category { +String name +String description +addArticle() +removeArticle() } User "1" -- "*" Article : writes User "1" -- "*" Comment : posts Article "1" -- "*" Comment : has Article "1" -- "*" Category : belongs to

状态图示例#

状态图展示了对象在生命周期中所经历的状态序列。

stateDiagram-v2 [*] --> Draft Draft --> UnderReview : submit UnderReview --> Draft : reject UnderReview --> Approved : approve Approved --> Published : publish Published --> Archived : archive Published --> Draft : retract state Published { [*] --> Active Active --> Hidden : temporarily hide Hidden --> Active : restore Active --> [*] Hidden --> [*] } Archived --> [*]

饼图示例#

饼图适合展示比例和百分比数据。

pie title Website Traffic Sources Analysis "Search Engines" : 45.6 "Direct Access" : 30.1 "Social Media" : 15.3 "Referral Links" : 6.4 "Other Sources" : 2.6

总结#

Mermaid 是一个强大的工具,用于在 Markdown 文档中创建各种类型的图表。本文演示了如何使用流程图、序列图、甘特图、类图、状态图和饼图。这些图表可以帮助您更清楚地表达复杂的概念、流程和数据结构。

要使用 Mermaid,只需在代码块中指定 mermaid 语言,并使用简洁的文本语法描述图表即可。Mermaid 会自动将这些描述转换为美观的可视化图表。

在您的下一篇技术博客文章或项目文档中尝试使用 Mermaid 图表——它们将使您的内容更加专业和易于理解!

分享

如果这篇文章对你有帮助,欢迎分享给更多人!

Markdown Mermaid
https://xinvstar.xyz/posts/markdown-mermaid/
作者
新v学员
发布于
2023-10-01
许可协议
CC BY-NC-SA 4.0

部分信息可能已经过时

目录