翻譯|使用教程|編輯:王香|2019-02-14 10:01:46.000|閱讀 382 次
概述:我們將構建一個新的鏈接模板,以更好地適應我們廣泛的節點。一個鏈接是一種不同的部分,而不是像一個節點。Link的主要元素是Link的形狀,并且必須是一個由GoJS動態計算其幾何形狀的Shape。我們的鏈接將僅由這種形狀組成,其筆劃比正常情況稍厚,而深灰色則不是黑色。與默認鏈接模板不同,我們沒有箭頭。我們將鏈接routing屬性從“正常” 更改為“正交”,并為其賦予一個corner值,以便對角度進行舍入。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
我們將構建一個新的鏈接模板,以更好地適應我們廣泛的節點。一個鏈接是一種不同的部分,而不是像一個節點。Link的主要元素是Link的形狀,并且必須是一個由GoJS動態計算其幾何形狀的Shape。我們的鏈接將僅由這種形狀組成,其筆劃比正常情況稍厚,而深灰色則不是黑色。與默認鏈接模板不同,我們沒有箭頭。我們將鏈接routing屬性從“正常” 更改為“正交”,并為其賦予一個corner值,以便對角度進行舍入。
// define a Link template that routes orthogonally, with no arrowhead myDiagram.linkTemplate = $(go.Link, // default routing is go.Link.Normal // default corner is 0 { routing: go.Link.Orthogonal, corner: 5 }, $(go.Shape, { strokeWidth: 3, stroke: "#555" }) // the link shape // if we wanted an arrowhead we would also add another Shape with toArrow defined: // $(go.Shape, { toArrow: "Standard", stroke: null } );
將Link模板與Node模板,TreeModel和TreeLayout相結合,我們最終得到了完整的組織圖。下面重復完整的代碼,結果圖如下:
var $ = go.GraphObject.make; var myDiagram = $(go.Diagram, "myDiagramDiv", { "undoManager.isEnabled": true, // enable Ctrl-Z to undo and Ctrl-Y to redo layout: $(go.TreeLayout, // specify a Diagram.layout that arranges trees { angle: 90, layerSpacing: 35 }) }); // the template we defined earlier myDiagram.nodeTemplate = $(go.Node, "Horizontal", { background: "#44CCFF" }, $(go.Picture, { margin: 10, width: 50, height: 50, background: "red" }, new go.Binding("source")), $(go.TextBlock, "Default Text", { margin: 12, stroke: "white", font: "bold 16px sans-serif" }, new go.Binding("text", "name")) ); // define a Link template that routes orthogonally, with no arrowhead myDiagram.linkTemplate = $(go.Link, { routing: go.Link.Orthogonal, corner: 5 }, $(go.Shape, { strokeWidth: 3, stroke: "#555" })); // the link shape var model = $(go.TreeModel); model.nodeDataArray = [ { key: "1", name: "Don Meow", source: "cat1.png" }, { key: "2", parent: "1", name: "Demeter", source: "cat2.png" }, { key: "3", parent: "1", name: "Copricat", source: "cat3.png" }, { key: "4", parent: "3", name: "Jellylorum", source: "cat4.png" }, { key: "5", parent: "3", name: "Alonzo", source: "cat5.png" }, { key: "6", parent: "2", name: "Munkustrap", source: "cat6.png" } ]; myDiagram.model = model;
購買GoJS正版授權,請點擊“”喲!
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn