翻譯|使用教程|編輯:吳園園|2020-05-25 14:59:00.210|閱讀 1822 次
概述:為了您的方便,我們定義了幾個(gè)Panel來(lái)通用。這些包括“按鈕”,“ TreeExpanderButton”,“ SubGraphExpanderButton”,“ PanelExpanderButton”和“ ContextMenuButton”。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷(xiāo)售中 >>
相關(guān)鏈接:
GoJS是一款功能強(qiáng)大,快速且輕量級(jí)的流程圖控件,可幫助你在JavaScript 和HTML5 Canvas程序中創(chuàng)建流程圖,且極大地簡(jiǎn)化您的JavaScript / Canvas 程序。
通用按鈕
預(yù)定義面板中最通用的一種是“按鈕”。
diagram.nodeTemplate = $(go.Node, "Auto", { locationSpot: go.Spot.Center }, $(go.Shape, "Rectangle", { fill: "gold" }), $(go.Panel, "Vertical", { margin: 3 }, $("Button", { margin: 2, click: incrementCounter }, $(go.TextBlock, "Click me!")), $(go.TextBlock, new go.Binding("text", "clickCount", function(c) { return "Clicked " + c + " times."; })) ) ); function incrementCounter(e, obj) { var node = obj.part; var data = node.data; if (data && typeof(data.clickCount) === "number") { node.diagram.model.commit(function(m) { m.set(data, "clickCount", data.clickCount + 1); }, "clicked"); } } diagram.model = new go.GraphLinksModel( [ { clickCount: 0 } ]);
TreeExpanderButtons
想要展開(kāi)和折疊子樹(shù)是很常見(jiàn)的。通過(guò)將“ TreeExpanderButton”的實(shí)例添加到您的節(jié)點(diǎn)模板,很容易讓用戶(hù)控制它。
diagram.nodeTemplate = $(go.Node, "Spot", $(go.Panel, "Auto", $(go.Shape, "Rectangle", { fill: "gold" }), $(go.TextBlock, "Click small button\nto collapse/expand subtree", { margin: 5 }) ), $("TreeExpanderButton", { alignment: go.Spot.Bottom, alignmentFocus: go.Spot.Top }, { visible: true }) ); diagram.layout = $(go.TreeLayout, { angle: 90 }); diagram.model = new go.GraphLinksModel( [ { key: 1 }, { key: 2 } ], [ { from: 1, to: 2 } ] );
SubGraphExpanderButtons
想要展開(kāi)和折疊包含子圖的組也很常見(jiàn)。您可以通過(guò)將“ SubGraphExpanderButton”的實(shí)例添加到組模板來(lái)讓用戶(hù)控制此操作。
diagram.groupTemplate = $(go.Group, "Auto", $(go.Shape, "Rectangle", { fill: "gold" }), $(go.Panel, "Vertical", { margin: 5, defaultAlignment: go.Spot.Left }, $(go.Panel, "Horizontal", $("SubGraphExpanderButton", { margin: new go.Margin(0, 3, 5, 0) }), $(go.TextBlock, "Group") ), $(go.Placeholder) ) ); diagram.model = new go.GraphLinksModel( [ { key: 0, isGroup: true }, { key: 1, group: 0 }, { key: 2, group: 0 }, { key: 3, group: 0 } ] );
PanelExpanderButtons
通常需要擴(kuò)展和折疊一個(gè)節(jié)點(diǎn),從而顯示或隱藏有時(shí)不需要的細(xì)節(jié)。通過(guò)將“ PanelExpanderButton”的實(shí)例添加到您的節(jié)點(diǎn)模板,很容易讓用戶(hù)控制它。GraphObject.make的第二個(gè)參數(shù)應(yīng)該是一個(gè)字符串,該字符串為希望按鈕切換其GraphObject.visible屬性的節(jié)點(diǎn)中的元素命名 。
diagram.nodeTemplate = $(go.Node, "Auto", $(go.Shape, { fill: "gold" }), $(go.Panel, "Table", { defaultAlignment: go.Spot.Top, defaultColumnSeparatorStroke: "black" }, $(go.Panel, "Table", { column: 0 }, $(go.TextBlock, "List 1", { column: 0, margin: new go.Margin(3, 3, 0, 3), font: "bold 12pt sans-serif" }), $("PanelExpanderButton", "LIST1", { column: 1 }), $(go.Panel, "Vertical", { name: "LIST1", row: 1, column: 0, columnSpan: 2 }, new go.Binding("itemArray", "list1")) ), $(go.Panel, "Table", { column: 1 }, $(go.TextBlock, "List 2", { column: 0, margin: new go.Margin(3, 3, 0, 3), font: "bold 12pt sans-serif" }), $("PanelExpanderButton", "LIST2", { column: 1 }), $(go.Panel, "Vertical", { name: "LIST2", row: 1, column: 0, columnSpan: 2 }, new go.Binding("itemArray", "list2")) ) ) ); diagram.model = new go.GraphLinksModel([ { key: 1, list1: [ "one", "two", "three", "four", "five" ], list2: [ "first", "second", "third", "fourth" ] } ]);
ContextMenuButtons
盡管可以以任何選擇的方式實(shí)現(xiàn)上下文菜單,但是通常使用預(yù)定義的“ ContextMenuButton”。
diagram.nodeTemplate = $(go.Node, "Auto", $(go.Shape, "Rectangle", { fill: "gold" }), $(go.TextBlock, "Use ContextMenu!", { margin: 5 }) ); diagram.nodeTemplate.contextMenu = $("ContextMenu", $("ContextMenuButton", $(go.TextBlock, "Shift Left"), { click: function(e, obj) { shiftNode(obj, -20); } }), $("ContextMenuButton", $(go.TextBlock, "Shift Right"), { click: function(e, obj) { shiftNode(obj, +20); } }) ); function shiftNode(obj, dist) { var adorn = obj.part; var node = adorn.adornedPart; node.diagram.commit(function(d) { var pos = node.location.copy(); pos.x += dist; node.location = pos; }, "Shift"); } diagram.model = new go.GraphLinksModel( [ { key: 1 } ] );
按鈕定義
在Extensions目錄的Buttons.js中 提供了所有預(yù)定義按鈕的實(shí)現(xiàn)。創(chuàng)建自己的按鈕時(shí),您可能希望復(fù)制并改寫(xiě)這些定義。
這些定義可能不是GoJS中由GraphObject.make使用的實(shí)際標(biāo)準(zhǔn)按鈕實(shí)現(xiàn)的最新描述。
請(qǐng)注意,這些按鈕的定義使用了GraphObject.defineBuilder靜態(tài)函數(shù)。這擴(kuò)展了GraphObject.make的行為,以允許通過(guò)名稱(chēng)(帶有可選參數(shù))創(chuàng)建相當(dāng)復(fù)雜的可視樹(shù)。您可以在整個(gè)示例和擴(kuò)展中找到各種控件的定義,例如:
====================================================
想要購(gòu)買(mǎi)GoJS正版授權(quán)的朋友可以
有關(guān)產(chǎn)品的最新消息和最新資訊,歡迎掃描關(guān)注下方微信公眾號(hào)
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自: