文檔金喜正規(guī)買球>>GoJS教程2020>>流程圖控件GoJS教程:如何將GoJS與Node.js結(jié)合使用
流程圖控件GoJS教程:如何將GoJS與Node.js結(jié)合使用
GoJS是一款功能強(qiáng)大,快速且輕量級(jí)的流程圖控件,可幫助你在JavaScript 和HTML5 Canvas程序中創(chuàng)建流程圖,且極大地簡(jiǎn)化您的JavaScript / Canvas 程序。
從2.0版本開始,GoJS可以用于沒有DOM的上下文中,例如Node.js。但是,有一些注意事項(xiàng):
- 由于沒有圖DIV,因此必須設(shè)置Diagram.viewSize屬性。這會(huì)影響所有與DIV大小相同的值,例如Diagram.position和視口大小的布局的布局結(jié)果。
- 無(wú)法測(cè)量go.Pictures,必須改為設(shè)置GraphObject.desiredSize。
- 無(wú)法準(zhǔn)確測(cè)量go.TextBlocks,應(yīng)改為設(shè)置GraphObject.desiredSize。
Node.js示例
如果將以下JavaScript另存為nodescript.js,并與節(jié)點(diǎn)(node nodescript.js)一起運(yùn)行,它將在控制臺(tái)中輸出Model JSON結(jié)果,其中包括布局節(jié)點(diǎn)的位置。您可以通過這種方式使用Node.js進(jìn)行大型布局之類的服務(wù)器端操作,然后將JSON發(fā)送給客戶端。
// nodescript.js // This example loads the GoJS library, creates a Diagram with a layout and prints the JSON results. // Load GoJS. This assumes using require and CommonJS: const go = require("gojs"); const $ = go.GraphObject.make; // for conciseness in defining templates const myDiagram = $(go.Diagram, '', // No DOM, so there can be no DIV! { viewSize: new go.Size(400,400), // Set this property in DOM-less environments layout: $(go.LayeredDigraphLayout) }); myDiagram.nodeTemplate = $(go.Node, 'Auto', // specify the size of the node rather than measuring the size of the text { width: 80, height: 40 }, // automatically save the Node.location to the node's data object new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify), $(go.Shape, 'RoundedRectangle', { strokeWidth: 0}, new go.Binding('fill', 'color')), $(go.TextBlock, new go.Binding('text', 'key')) ); // After the layout, output results: myDiagram.addDiagramListener('InitialLayoutCompleted', function() { console.log(myDiagram.model.toJson()); }); // load a model: myDiagram.model = new go.GraphLinksModel( [ { key: 'Alpha', color: 'lightblue' }, { key: 'Beta', color: 'orange' }, { key: 'Gamma', color: 'lightgreen' }, { key: 'Delta', color: 'pink' } ], [ { from: 'Alpha', to: 'Beta' }, { from: 'Alpha', to: 'Gamma' }, { from: 'Gamma', to: 'Delta' }, { from: 'Delta', to: 'Alpha' } ]);另外,如果您的代碼另存為nodescript.mjs或項(xiàng)目為"type": "module",則可以將GoJS用作ES6模塊:
// nodescript.mjs // This example loads the GoJS library, creates a Diagram with a layout and prints the JSON results. // Load GoJS. This assumes using import and ES6 modules: import * as go from "gojs/release/go.mjs"; const $ = go.GraphObject.make; . . .
想要購(gòu)買GoJS正版授權(quán),或了解更多產(chǎn)品信息請(qǐng)點(diǎn)擊