Typora绘制-需求图

📅 2026/7/10 21:50:27 👁️ 阅读次数 📝 编程学习
Typora绘制-需求图

**注意:**需求图的高亮正常显示,旧版本目前没有示例,推荐使用新版语法。

需求图

mermaid官方网站文档教程链接(英文)

社区维护的中文文档站

1、新版本语法

requirementDiagram如下仅是基础的常用功能语法,如需更全面内容可参考官网教程文档

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

    <word> user_defined_...

    用尖括号表示的单词,如<word>,是枚举关键字,其选项在表格中详细说明。user_defined_...用于任何需要用户输入的地方。

  • 要求:Requirement

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

    需求定义包含需求类型、名称、ID、文本、风险和验证方法

    关键字选项
    类型需求, 功能需求, 接口需求, 性能需求, 物理需求, 设计约束
    风险低, 中, 高
    验证方法分析, 检查, 测试, 演示
  • 元素:Element

    element user_defined_name { type: user_defined_type docref: user_defined_ref }

    元素定义包含元素名称、类型和文档引用。这三者都是用户定义的。元素功能旨在保持轻量,同时允许将需求与其他文档的部分内容关联起来。

  • Markdown 格式

    在允许用户自定义文本的地方(如名称、需求文本、元素文档引用等)

    • 将文本用引号括起来:“example text”
    • 在引号内使用 markdown 格式:"**加粗文本** 和 *斜体*"
    requirementDiagram requirement "__test_req__" { id: 1 text: "*italicized text* **bold text**" risk: high verifymethod: test }
  • 关系:Relationship

    {name of source} - <type> -> {name of destination}

    或者

    {name of destination} <- <type> - {name of source}
    • 关系由源节点、目标节点和关系类型组成;
    • 每个都遵循……的定义格式;
    • “来源名称”和“目标名称”应为在其他地方定义的需求或元素节点的名称;
    • 关系类型可以是包含、复制、派生、满足、验证、细化或追踪之一。
  • 方向

    可以使用direction语句以不同方向呈现图表。有效值为:

    • TB- 从上到下(默认)
    • BT- 从下到上
    • LR- 从左到右
    • RL- 从右到左
  • 注释规则

    • 单行注释:%% 注释内容(必须以%%开头,可放在行首 / 行尾);
    • 多行注释:无原生支持,需每行加%%

2、代码示例

示例1

requirementDiagram direction LR requirement test_req { id: 1 text: the test text. risk: high verifymethod: test } element test_entity { type: simulation } test_entity - satisfies -> test_req

示例2

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

3、效果示例

示例1

«satisfies»

<<Requirement>>

test_req

ID: 1

Text: the test text.

Risk: High

Verification: Test

<<Element>>

test_entity

Type: simulation

示例2

«satisfies»

«traces»

«contains»

«contains»

«derives»

«refines»

«verifies»

«copies»

<<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

<<Element>>

test_entity2

Type: word doc

Doc Ref: reqs/test_entity

<<Element>>

test_entity3

Type: test suite

Doc Ref: github.com/all_the_tests

requirementDiagram新版本功能可以支持更丰富的内容,旧版写法差异明显,头部声明没有变化,不推荐使用就不介绍太多了。

4、新旧版本差异

新旧版本写法差异比较大,如下对比

维度旧版语法(v8.x)新版语法(v9.x+)
核心关键字仅支持req定义需求支持requirement/actor/interface等多关键字
关系定义仅支持简单箭头(-->/..>新增语义化关系(implements/derives/satisfies等)
属性配置无属性,仅能定义名称支持id/status/description等属性
语法结构扁平结构,无分组支持package分组,逻辑更清晰
兼容性仅旧版 Mermaid 支持,新版逐步废弃v9.x+ 原生支持,是官方推荐写法
  • 基础场景:语法规则差异明显
  • 高级场景:requirementDiagram新增专属功能

5、版本兼容性

  1. Typora 版本 < 1.7:(主要看什么版本)

    1. 可能部分支持(新增 quadrantChart,req/requirement 双兼容);

    2. 可能支持 quadrantChart 基础语法、兼容新旧版 requirementDiagram;

  2. Typora 版本 ≥ 1.7

    1. 全面支持(quadrantChart / 新版 requirementDiagram 均支持);

    2. 支持语义化关系、属性、package 分组等新版特性;

  3. 如何查版本:Typora → 帮助 → 关于 Typora(可看到 Typora 版本)。