翻譯|使用教程|編輯:吳園園|2020-01-15 13:33:20.247|閱讀 816 次
概述:通常通過(guò)以某種方式“突出顯示”節(jié)點(diǎn)(或節(jié)點(diǎn)或鏈接的一部分)使其脫穎而出。顯示選擇裝飾時(shí),選擇會(huì)發(fā)生這種情況。但是,人們經(jīng)常想突出顯示與選擇無(wú)關(guān)的零件??梢酝ㄟ^(guò)以下方式來(lái)實(shí)現(xiàn):更改形狀的填充或筆觸,將圖片源替換為另一個(gè)源,添加或移除陰影,等等。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
GoJS是一款功能強(qiáng)大,快速且輕量級(jí)的流程圖控件,可幫助你在JavaScript 和HTML5 Canvas程序中創(chuàng)建流程圖,且極大地簡(jiǎn)化您的JavaScript / Canvas 程序。
突出顯示時(shí)更改節(jié)點(diǎn)大小
您可能需要增加節(jié)點(diǎn)或節(jié)點(diǎn)中元素的大小以使其突出顯示。例如,您可以在GraphObject.scale或Shape.strokeWidth上具有Binding :
$(go.Node, ... $(go.Shape, ..., new go.Binding("strokeWidth", "isHighlighted", function(h) { return h ? 5 : 1; })), ... )
但是,這樣做會(huì)更改對(duì)象的大小。這可能會(huì)使與該節(jié)點(diǎn)連接的所有鏈接的路由無(wú)效。在許多應(yīng)用中這可能無(wú)關(guān)緊要,但是在某些情況下,某些鏈接的路線可能已由用戶重塑。由于連接的節(jié)點(diǎn)移動(dòng)或大小更改而對(duì)路由進(jìn)行的任何重新計(jì)算都可能會(huì)丟失該路由。
如果這是您應(yīng)用程序中的考慮因素,則可以考慮讓每個(gè)節(jié)點(diǎn)都擁有一個(gè)附加的Shape,該形狀將在顯示時(shí)提供突出顯示,否則將看不見(jiàn)。但是不要切換GraphObject.visible屬性,因?yàn)檫@會(huì)導(dǎo)致節(jié)點(diǎn)更改大小。而是在0.0和1.0之間切換GraphObject.opacity屬性。
diagram.nodeTemplate = $(go.Node, "Auto", { locationSpot: go.Spot.Center, // when the user clicks on a Node, highlight all Links coming out of the node // and all of the Nodes at the other ends of those Links. click: function(e, node) { var diagram = node.diagram; diagram.startTransaction("highlight"); diagram.clearHighlighteds(); node.findLinksOutOf().each(function(l) { l.isHighlighted = true; }); node.findNodesOutOf().each(function(n) { n.isHighlighted = true; }); diagram.commitTransaction("highlight"); } }, $(go.Panel, "Auto", $(go.Shape, "Ellipse", { strokeWidth: 2, portId: "" }, new go.Binding("fill", "color")), $(go.TextBlock, { margin: 5, font: "bold 18px Verdana" }, new go.Binding("text", "key")) ), // the highlight shape, which is always a thick red ellipse $(go.Shape, "Ellipse", // this shape is the "border" of the Auto Panel, but is drawn in front of the // regular Auto Panel holding the black-bordered ellipse and text { isPanelMain: true, spot1: go.Spot.TopLeft, spot2: go.Spot.BottomRight }, { strokeWidth: 6, stroke: "red", fill: null }, // only show this ellipse when Part.isHighlighted is true new go.Binding("opacity", "isHighlighted", function(h) { return h ? 1.0 : 0.0; }) .ofObject()) ); // define the Link template diagram.linkTemplate = $(go.Link, { toShortLength: 4, reshapable: true, resegmentable: true }, $(go.Shape, // when highlighted, draw as a thick red line new go.Binding("stroke", "isHighlighted", function(h) { return h ? "red" : "black"; }) .ofObject(), new go.Binding("strokeWidth", "isHighlighted", function(h) { return h ? 3 : 1; }) .ofObject()), $(go.Shape, { toArrow: "Standard", strokeWidth: 0 }, new go.Binding("fill", "isHighlighted", function(h) { return h ? "red" : "black"; }) .ofObject()) ); // when the user clicks on the background of the Diagram, remove all highlighting diagram.click = function(e) { diagram.startTransaction("no highlighteds"); diagram.clearHighlighteds(); diagram.commitTransaction("no highlighteds"); }; diagram.model = new go.GraphLinksModel( [ { key: "Alpha", color: "#96D6D9" }, { key: "Beta", color: "#96D6D9" }, { key: "Gamma", color: "#EFEBCA" }, { key: "Delta", color: "#EFEBCA" } ], [ { from: "Alpha", to: "Beta" }, { from: "Alpha", to: "Gamma" }, { from: "Beta", to: "Beta" }, { from: "Gamma", to: "Delta" }, { from: "Delta", to: "Alpha" } ]);
高亮的形狀是外部橢圓,始終具有較粗的紅色筆觸。它通常通過(guò)不透明度為零來(lái)隱藏,但是當(dāng)Part.isHighlighted為true 時(shí),Binding會(huì)將其不透明度更改為1 。
突出顯示的“形狀”始終顯示在彩色橢圓和文本面板的前面,方法是將其放在面板的子元素列表之后。但是,由于“自動(dòng)”面板假定第一個(gè)元素充當(dāng)邊框,因此我們需要 在高亮Shape上將GraphObject.isPanelMain設(shè)置為true,以使其成為內(nèi)部面板的邊框。
====================================================
想要購(gòu)買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)載自:GoJS