Typora绘制-需求图
**注意**需求图的高亮正常显示旧版本目前没有示例推荐使用新版语法。需求图mermaid官方网站文档教程链接(英文)社区维护的中文文档站1、新版本语法requirementDiagram如下仅是基础的常用功能语法如需更全面内容可参考官网教程文档需求图有三种类型的组件需求、元素和关系。word user_defined_...用尖括号表示的单词如word是枚举关键字其选项在表格中详细说明。user_defined_...用于任何需要用户输入的地方。要求Requirementtype user_defined_name { id: user_defined_id text: user_defined text risk: risk verifymethod: method }需求定义包含需求类型、名称、ID、文本、风险和验证方法关键字选项类型需求, 功能需求, 接口需求, 性能需求, 物理需求, 设计约束风险低, 中, 高验证方法分析, 检查, 测试, 演示元素Elementelement 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、代码示例示例1requirementDiagram 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示例2requirementDiagram 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_entity23、效果示例示例1«satisfies»Requirementtest_reqID: 1Text: the test text.Risk: HighVerification: TestElementtest_entityType: simulation示例2«satisfies»«traces»«contains»«contains»«derives»«refines»«verifies»«copies»Requirementtest_reqID: 1Text: the test text.Risk: HighVerification: TestFunctional Requirementtest_req2ID: 1.1Text: the second test text.Risk: LowVerification: InspectionPerformance Requirementtest_req3ID: 1.2Text: the third test text.Risk: MediumVerification: DemonstrationInterface Requirementtest_req4ID: 1.2.1Text: the fourth test text.Risk: MediumVerification: AnalysisPhysical Requirementtest_req5ID: 1.2.2Text: the fifth test text.Risk: MediumVerification: AnalysisDesign Constrainttest_req6ID: 1.2.3Text: the sixth test text.Risk: MediumVerification: AnalysisElementtest_entityType: simulationElementtest_entity2Type: word docDoc Ref: reqs/test_entityElementtest_entity3Type: test suiteDoc Ref: github.com/all_the_testsrequirementDiagram新版本功能可以支持更丰富的内容旧版写法差异明显头部声明没有变化不推荐使用就不介绍太多了。4、新旧版本差异新旧版本写法差异比较大如下对比维度旧版语法v8.x新版语法v9.x核心关键字仅支持req定义需求支持requirement/actor/interface等多关键字关系定义仅支持简单箭头--/..新增语义化关系implements/derives/satisfies等属性配置无属性仅能定义名称支持id/status/description等属性语法结构扁平结构无分组支持package分组逻辑更清晰兼容性仅旧版 Mermaid 支持新版逐步废弃v9.x 原生支持是官方推荐写法基础场景语法规则差异明显高级场景requirementDiagram新增专属功能5、版本兼容性Typora 版本 1.7主要看什么版本可能部分支持新增 quadrantChartreq/requirement 双兼容可能支持 quadrantChart 基础语法、兼容新旧版 requirementDiagramTypora 版本 ≥ 1.7全面支持quadrantChart / 新版 requirementDiagram 均支持;支持语义化关系、属性、package 分组等新版特性;如何查版本Typora → 帮助 → 关于 Typora可看到 Typora 版本。