文檔首頁>>GoJS教程2020>>流程圖控件GoJS教程:調整圖表大小
流程圖控件GoJS教程:調整圖表大小
GoJS是一款功能強大,快速且輕量級的流程圖控件,可幫助你在JavaScript 和HTML5 Canvas程序中創(chuàng)建流程圖,且極大地簡化您的JavaScript / Canvas 程序。
使用Diagram.requestUpdate調整Div的大小
以下示例具有一個按鈕,該按鈕可放大圖的div。單擊時,將明顯調整div的大小,但圖保持不變。
// A minimal Diagram diagram.nodeTemplate = $(go.Node, "Auto", $(go.Shape, "RoundedRectangle", new go.Binding("fill", "color")), $(go.TextBlock, { margin: 3 }, // some room around the text new go.Binding("text", "key")) ); diagram.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" } ]); // Resize the diagram with this button var button1 = document.getElementById('button1'); button1.addEventListener('click', function() { var div = diagram.div; div.style.width = '200px'; });
通常,我們會希望在div調整大小的同時,將Diagram調整為其div的大小。為此,我們在調整div的大小后向Diagram.requestUpdate 添加了一個調用。這將檢查圖的div是否已更改大小,如果已更改,則以適當?shù)男鲁叽缰匦吕L制圖。
除了添加了對Diagram.requestUpdate的調用之外,以下代碼幾乎相同。
// A minimal Diagram diagram.nodeTemplate = $(go.Node, "Auto", $(go.Shape, "RoundedRectangle", new go.Binding("fill", "color")), $(go.TextBlock, { margin: 3 }, // some room around the text new go.Binding("text", "key")) ); diagram.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" } ]); // Resize the diagram with this button var button2 = document.getElementById('button2'); button2.addEventListener('click', function() { var div = diagram.div; div.style.width = '200px'; diagram.requestUpdate(); // Needed! });
====================================================
有關產(chǎn)品的最新消息和最新資訊,歡迎掃描關注下方微信公眾號