Markdown 需求图绘制详解

✍️作者简介:小北编程(专注于HarmonyOS、Android、Java、Web、TCP/IP等技术方向)
🐳博客主页: 开源中国稀土掘金51cto博客博客园知乎简书慕课网CSDN
🔔如果文章对您有一定的帮助请👉关注✨、点赞👍、收藏📂、评论💬。
🔥如需转载请参考【转载须知】

一、前言

Markdown 的原生语法不支持绘制图形,但通过扩展模块,我们可以将一些格式化的文字渲染成我们需要的图形。常用的图形有 “流程图”、“时序图”、“类图”、“状态图”、“甘特图”、“饼图” 等。

本节将重点介绍如何通过 Mermaid 绘制「需求图」。

需求图 (Requirement) 提供了需求及其相互之间以及其他已记录元素之间的连接的可视化。

二、语法

需求图包含三种类型的组件: 需求、元素和关系。

用于定义每个的语法定义如下。 尖括号中表示的单词(例如 )是枚举关键字,其选项在表格中详细说明。 user_defined_… 用于任何需要用户输入的地方。

关于用户文本的重要说明: 所有输入都可以用引号引起来,也可以不用引号引起来。 例如,Id: “here is an example” 和 Id: here is an example 都有效。 但是,用户必须小心未加引号的输入。 如果检测到另一个关键字,解析器将失败。

需求

需求定义包含需求类型、名称、id、文本、风险和验证方法。语法如下:

<type> user_defined_name {
    id: user_defined_id
    text: user_defined text
    risk: <risk>
    verifymethod: <method>
}

类型、风险和方法是SysML中定义的枚举值。

关键字选项
type(需求类型)requirement(需求)
functionalRequirement(功能需求)
interfaceRequirement(接口需求)
performanceRequirement(性能需求)
physicalRequirement(物理需求)
designConstraint(设计约束)
risk(风险等级)Low(低风险)
Medium(中风险)
High(高风险)
verifymethod(验证方法)Analysis(分析)
Inspection(检验)
Inspection(检验)
Test(测试)
Demonstration(演示)

元素

元素定义包含元素名称、类型和文档引用。这三个都是用户定义的。元素功能旨在轻巧,但允许将需求连接到其他文档的某些部分。

element user_defined_name {
    type: user_defined_type
    docref: user_defined_ref
}

关系

关系由源节点、目标节点和关系类型组成。

每个都遵循如下定义格式:

<源名称> - <关系类型> -> <目标名称>

或者

<目标名称> <- <关系类型> - <源名称>

源名称目标名称应该是在其他地方定义的需求或元素节点的名称。

关系类型可以是包含,复制,派生,满足,验证,细化或跟踪中的一种。

完整的例子

这个例子使用了需求图的所有特性:

```mermaid
requirementDiagram

requirement test_req {
id: 1
text: the test text.
risk: high
verifymethod: test
}

functionalRequirement test_req2 {
id: 1.1
text: the second test text.
risk: low
verifymethod: inspection
}

performanceRequirement test_req3 {
id: 1.2
text: the third test text.
risk: medium
verifymethod: demonstration
}

interfaceRequirement test_req4 {
id: 1.2.1
text: the fourth test text.
risk: medium
verifymethod: analysis
}

physicalRequirement test_req5 {
id: 1.2.2
text: the fifth test text.
risk: medium
verifymethod: analysis
}

designConstraint test_req6 {
id: 1.2.3
text: the sixth test text.
risk: medium
verifymethod: analysis
}

element test_entity {
type: simulation
}

element test_entity2 {
type: word doc
docRef: reqs/test_entity
}

element test_entity3 {
type: "test suite"
docRef: github.com/all_the_tests
}

test_entity - satisfies -> test_req2
test_req - traces -> test_req2
test_req - contains -> test_req3
test_req3 - contains -> test_req4
test_req4 - derives -> test_req5
test_req5 - refines -> test_req6
test_entity3 - verifies -> test_req5
test_req <- copies - test_entity2
```
<<Requirement>> test_req Id: 1 Text: the test text. Risk: High Verification: Test <<Functional Requirement>> test_req2 Id: 1.1 Text: the second test text. Risk: Low Verification: Inspection <<Performance Requirement>> test_req3 Id: 1.2 Text: the third test text. Risk: Medium Verification: Demonstration <<Interface Requirement>> test_req4 Id: 1.2.1 Text: the fourth test text. Risk: Medium Verification: Analysis <<Physical Requirement>> test_req5 Id: 1.2.2 Text: the fifth test text. Risk: Medium Verification: Analysis <<Design Constraint>> test_req6 Id: 1.2.3 Text: the sixth test text. Risk: Medium Verification: Analysis <<Element>> test_entity Type: simulation Doc Ref: None <<Element>> test_entity2 Type: word doc Doc Ref: reqs/test_entity <<Element>> test_entity3 Type: test suite Doc Ref: github.com/all_the_te sts <<satisfies>> <<traces>> <<contains>> <<contains>> <<derives>> <<refines>> <<verifies>> <<copies>>

三、总结

通过使用 Mermaid 的 requirementDiagram,你可以以清晰而简洁的方式呈现需求图。这种方法对于在文档中快速创建和更新需求图非常方便,使得需求管理变得更加直观和易于维护。

请添加图片描述

文章写作不易,您的支持是我最大的动力,请👉关注✨、点赞👍、收藏📂、评论💬。

无论是哪个阶段,坚持努力都是成功的关键。不要停下脚步,继续前行,即使前路崎岖,也请保持乐观和勇气。相信自己的能力,你所追求的目标定会在不久的将来实现。加油!

  • 18
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小北编程

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值