Global

Methods

(async) WFlowchart(inp, optopt) → {Promise}

Description:
  • 產製流程圖 PNG

Source:
Example
import fs from 'fs'
import WFlowchart from 'w-flowchart'

let inp = {
    dir: 'TB',
    nodes: [
        { id: 'A', label: '開始', cls: 'blue' },
        { id: 'G', label: '處理群組', cls: 'greenG' },
        { id: 'B', label: '步驟一', cls: 'green', group: 'G' },
        { id: 'C', title: '服務', items: ['項目一', '項目二'], cls: 'green', group: 'G' },
        { id: 'D', label: '判斷?', cls: 'diamond' },
        { id: 'E', label: '結束', cls: 'orange' },
    ],
    edges: [
        { from: 'A', to: 'B' },
        { from: 'B', to: 'C', label: '呼叫' },
        { from: 'C', to: 'D' },
        { from: 'D', to: 'E', label: '通過' },
        { from: 'D', to: 'B', kind: 'dashed', label: '退回' },
    ],
}

let buf = await WFlowchart(inp) //預設 mode 'p10'; 可用 WFlowchart(inp, { mode: 'p3' }) 指定產線
fs.writeFileSync('flowchart.png', buf)
// => 產出 flowchart.png

let svg = await WFlowchart(inp, { output: 'svg' }) //輸出 standalone SVG 字串(p9 不支援)
fs.writeFileSync('flowchart.svg', svg)
// => 產出 flowchart.svg
Parameters:
Name Type Attributes Default Description
inp Object

輸入正規化繪圖數據物件,格式 { dir, nodes, edges },與繪圖引擎無關

Properties
Name Type Attributes Default Description
dir String <optional>
'TB'

輸入佈局方向字串,可選 'TB'(上而下)或 'LR'(左而右),預設 'TB'

nodes Array

輸入節點陣列,每項為一般節點 { id, label, cls, group? } 或富節點 { id, title, items, cls, group? };cls 為色票鍵(見 src/common/palette.mjs),結尾 G/G2 者為群組容器,group 為所屬容器 id(容器可巢狀);label 過寬會自動斷行,亦可用 '\n' 強制換行(p10 支援,含群組/菱形標籤;其他產線依引擎行為)

edges Array

輸入邊陣列,每項為 { from, to, label?, kind? },kind 給 'dashed' 為虛線;label 同樣支援 '\n' 強制換行(p10)

opt Object <optional>
{}

輸入設定物件,原樣傳遞給產線,預設 {}

Properties
Name Type Attributes Default Description
mode String <optional>
'p10'

輸入產線模式字串,可選 'p1'~'p10',各對應一套繪圖引擎產線(技術概念見各 src/pN/README.md),未指定或非有效字串時預設 'p10'

output String <optional>
'png'

輸入輸出格式字串,可選 'png'(回傳 PNG Buffer)或 'svg'(回傳 standalone SVG 字串),未指定或非有效字串時預設 'png';svg 支援 p1~p8 與 p10,p9(React Flow 之 HTML DOM 渲染)不支援,給 svg 會拋錯

Returns:

回傳 Promise,resolve 依 opt.output 回傳 PNG 圖之 Buffer 或 SVG 字串,reject 回傳錯誤訊息

Type
Promise