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
|
||||||||||||||||||||||
opt |
Object |
<optional> |
{}
|
輸入設定物件,原樣傳遞給產線,預設 {} Properties
|
Returns:
回傳 Promise,resolve 依 opt.output 回傳 PNG 圖之 Buffer 或 SVG 字串,reject 回傳錯誤訊息
- Type
- Promise