翻譯|使用教程|編輯:王香|2019-02-14 10:01:46.000|閱讀 382 次
概述:我們將構(gòu)建一個(gè)新的鏈接模板,以更好地適應(yīng)我們廣泛的節(jié)點(diǎn)。一個(gè)鏈接是一種不同的部分,而不是像一個(gè)節(jié)點(diǎn)。Link的主要元素是Link的形狀,并且必須是一個(gè)由GoJS動(dòng)態(tài)計(jì)算其幾何形狀的Shape。我們的鏈接將僅由這種形狀組成,其筆劃比正常情況稍厚,而深灰色則不是黑色。與默認(rèn)鏈接模板不同,我們沒(méi)有箭頭。我們將鏈接routing屬性從“正常” 更改為“正交”,并為其賦予一個(gè)corner值,以便對(duì)角度進(jìn)行舍入。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷售中 >>
我們將構(gòu)建一個(gè)新的鏈接模板,以更好地適應(yīng)我們廣泛的節(jié)點(diǎn)。一個(gè)鏈接是一種不同的部分,而不是像一個(gè)節(jié)點(diǎn)。Link的主要元素是Link的形狀,并且必須是一個(gè)由GoJS動(dòng)態(tài)計(jì)算其幾何形狀的Shape。我們的鏈接將僅由這種形狀組成,其筆劃比正常情況稍厚,而深灰色則不是黑色。與默認(rèn)鏈接模板不同,我們沒(méi)有箭頭。我們將鏈接routing屬性從“正常” 更改為“正交”,并為其賦予一個(gè)corner值,以便對(duì)角度進(jìn)行舍入。
// 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相結(jié)合,我們最終得到了完整的組織圖。下面重復(fù)完整的代碼,結(jié)果圖如下:
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;
購(gòu)買(mǎi)GoJS正版授權(quán),請(qǐng)點(diǎn)擊“”喲!
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn