I currently have functionality where when you click on a node that selected node and all connected nodes are set to a different color then the rest. I would like to incorporate functionality where I take all nodes that are not connected to the currently selected node and sets the opacity to 50% of the currently selected nodes, or setting the stroke to a transulent color would probably do as well. What’s the best way to do this?
Here is my code to set the selected and highlighted nodes:
myDiagram2.nodeTemplate =
graph(go.Node, "Auto",
{margin: new go.Margin(0,30,0,30),
fromSpot: go.Spot.Right,
toSpot: go.Spot.Left},
{
click: function(e, node) { showConnections(node); },
},
new go.Binding("layerName", "isSelected", function(sel) { return sel ? "Foreground" : ""; }).ofObject(),
graph(go.Shape, "RoundedRectangle",
{name: "SHAPE", fill: "#FFF", minSize: new go.Size(200, 100), cursor: "pointer"},
new go.Binding("stroke", "isHighlighted", function(h) { return h ? "#388E3C" : "#009BE1"; })
.ofObject(),
new go.Binding("fill", "isHighlighted", function(h) { return h ? "#E9F9D7" : "#FFF"; })
.ofObject(),
new go.Binding("fill", "isSelected", function(selected) {if (selected) return "#E9F9D7"; else return "#FFF";})
.ofObject(""),
new go.Binding("stroke", "isSelected", function(selected) {if (selected) return "#388E3C"; else return "#009BE1";})
.ofObject("")),
function showConnections(node) {
var diagram = node.diagram;
diagram.startTransaction("highlight");
// remove any previous highlighting
diagram.clearHighlighteds();
// for each Link coming out of the Node, set Link.isHighlighted
node.findLinksOutOf().each(function(l) { l.isHighlighted = true; });
// for each Node destination for the Node, set Node.isHighlighted
node.findNodesOutOf().each(function(n) { n.isHighlighted = true; });
diagram.commitTransaction("highlight");
}
In the screen shot below, I would like to set all nodes that are not currently green, to 50% opacity.