流程類
圖形化表達方式
思維類
結構化表達方式
筆記類
高效化表達方式

需求圖語法

需求圖

需求圖提供了需求及其相互之間連接關係,以及與其他文件元素關係的視覺化。

代碼
                            
複製
嵌入
requirementDiagram requirement test_req { id: 1 text: the test text. risk: high verifymethod: test } element test_entity { type: simulation } test_entity - satisfies -> test_req

語法

需求圖包含三種元件:需求、元素和關係。

尖括號表示的單字是列舉關鍵字,如 ,其選項在表格中詳細說明。user_defined... 用於任何需要使用者輸入的地方。

關於使用者文字的重要說明:所有輸入都可以用雙引號括起來,也可以不加雙引號。然而,使用者在使用未加引號的輸入時必須小心。如果偵測到其他關鍵字,編輯器將會渲染失敗。

需求

需求定義包含需求類型、名稱、ID、文字、風險和驗證方法。語法如下:

                            
複製
嵌入
<type> user_defined_name { id: user_defined_id text: user_defined text risk: <risk> verifymethod: <method> }

類型、風險和方法是 SysML 中定義的列舉。

關鍵字 選項
類型 需求、功能需求、介面需求、效能需求、實體需求、設計限制
風險 低、中、高
驗證方法 分析、檢查、測試、展示

元素

元素定義包含元素名稱、類型和文件引用,這三個都是使用者定義的。元素功能旨在保持輕量級,同時允許將需求與其他文件的部分內容關聯起來。

                            
複製
嵌入
element myElement { type: string docref: some/doc/path }

Markdown 格式

在允許使用者自訂文字的地方(如名稱、需求文字、元素文件引用等),你可以:

  • 將文字用雙引號括起來
  • 在雙引號內使用 markdown 格式
代碼
                            
複製
嵌入
requirementDiagram requirement "__test_req__" { id: 1 text: "*italicized text* **bold text**" risk: high verifymethod: test }

關係

關係由來源節點、目標節點和關係類型組成。

遵循以下定義格式:

                            
複製
嵌入
{name of source} - <type> -> {name of destination}

或者

                            
複製
嵌入
{name of destination} <- <type> - {name of source}

"來源節點" 和 "目標節點" 應為在其他地方定義的需求或元素節點的名稱。

關係類型可以是包含、複製、衍生、滿足、驗證、細化或追蹤之一。

詳細案例

此範例使用了該圖的所有功能。

代碼
                            
複製
嵌入
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

方向

可以使用 direction 陳述式以設定不同方向渲染圖表,有效值為:

  • TB - 從上到下(預設)
  • BT - 從下到上
  • LR - 從左到右
  • RL - 從右到左
代碼
                            
複製
嵌入
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

樣式

需求和元素可以使用直接樣式或類別來設定樣式。一般來說,在套用樣式或類別時,它接受一個需求或元素名稱的清單以及一個類別名稱清單,從而允許一次指派多個類別。唯一的例外是簡寫語法 :::,運算子可以指派多個類別,但一次只能指派給一個需求或元素。

直接樣式

代碼
                            
複製
嵌入
requirementDiagram requirement test_req { id: 1 text: styling example risk: low verifymethod: test } element test_entity { type: simulation } style test_req fill:#ffa,stroke:#000, color: green style test_entity fill:pink,stroke:#333, color: blue

類別定義如下例所示:

使用 classDef 定義可重複使用的樣式:

代碼
                            
複製
嵌入
requirementDiagram requirement test_req { id: 1 text: "class styling example" risk: low verifymethod: test } element test_entity { type: simulation } classDef important fill:#f96,stroke:#333,stroke-width:4px classDef test fill:#ffa,stroke:#000

預設類別

如果某個類別命名為 default,它將套用於所有節點。特定的樣式和類別應該在此之後定義,以覆寫已套用的預設樣式。

                            
複製
嵌入
classDef default fill:pink,stroke:#333,stroke-width:4px;

應用類別

類別可以透過兩種方式套用:

1. 使用 class 語法:

                            
複製
嵌入
class test_req,test_entity important

2. 在定義過程中或之後使用運算子 ::: 簡寫語法:

                            
複製
嵌入
requirement test_req:::important { id: 1 text: class styling example risk: low verifymethod: test }
                            
複製
嵌入
element test_elem {} test_elem:::myClass

組合範例

代碼
                            
複製
嵌入
requirementDiagram requirement test_req:::important { id: 1 text: "class styling example" risk: low verifymethod: test } element test_entity { type: simulation } classDef important font-weight:bold class test_entity important style test_entity fill:pink,stroke:#333