Filter Certains Nodes from Diagram

We have craeted a NodeTemplate which is used to create nodes in our diagram. We are working on some kind filter where we need to show/hide nodes and there links based on some condition (for eg. text = “Decision” ). How to achieve it.

<span =“Apple-tab-span” style=“white-space:pre”> myDiagram.nodeTemplate = G(go.Node, “Auto”, {
<span =“Apple-tab-span” style=“white-space:pre”> selectionChanged : onNodeSelect,
<span =“Apple-tab-span” style=“white-space:pre”> doubleClick : showDecTable,
<span =“Apple-tab-span” style=“white-space:pre”> contextMenu : partContextMenu, // adding context menu to node to group them
<span =“Apple-tab-span” style=“white-space:pre”> resizable : true,
<span =“Apple-tab-span” style=“white-space:pre”> desiredSize : new go.Size(NaN,NaN)
<span =“Apple-tab-span” style=“white-space:pre”> }, G(go.Shape, {
<span =“Apple-tab-span” style=“white-space:pre”> portId : “”,
<span =“Apple-tab-span” style=“white-space:pre”> fromLinkable : true,
<span =“Apple-tab-span” style=“white-space:pre”> name : “DMNNode”
<span =“Apple-tab-span” style=“white-space:pre”> }, new go.Binding(“strokeWidth”, “strokeWidth”).makeTwoWay(),
<span =“Apple-tab-span” style=“white-space:pre”> new go.Binding(“toLinkable”, “to”),
<span =“Apple-tab-span” style=“white-space:pre”> new go.Binding(“figure”, “fig”), new go.Binding(“fill”, “color”)
<span =“Apple-tab-span” style=“white-space:pre”> .makeTwoWay(), new go.Binding(“geometry”, “geo”)), G(
<span =“Apple-tab-span” style=“white-space:pre”> go.TextBlock, {
<span =“Apple-tab-span” style=“white-space:pre”> name : “TextBlk”,
<span =“Apple-tab-span” style=“white-space:pre”> margin : 8,
<span =“Apple-tab-span” style=“white-space:pre”> wrap : go.TextBlock.WrapFit,
<span =“Apple-tab-span” style=“white-space:pre”> editable : true,
<span =“Apple-tab-span” style=“white-space:pre”> font : smallfont,
<span =“Apple-tab-span” style=“white-space:pre”> stroke : “black”
<span =“Apple-tab-span” style=“white-space:pre”> }, new go.Binding(“text”, “text”).makeTwoWay(), new go.Binding(
<span =“Apple-tab-span” style=“white-space:pre”> “stroke”, “stroke”).makeTwoWay(), new go.Binding(“font”,
<span =“Apple-tab-span” style=“white-space:pre”> “font”).makeTwoWay()), new go.Binding(“location”, “loc”,
<span =“Apple-tab-span” style=“white-space:pre”> go.Point.parse).makeTwoWay(go.Point.stringify), new go.Binding(
<span =“Apple-tab-span” style=“white-space:pre”> “selectionAdornmentTemplate”, “selectionAdornmentTemplate”), new go.Binding(“desiredSize”,“desiredSize”).makeTwoWay());

Our solution for the time being is not good, We keep temporary backup of nodeDataArray and remove the nodes which are not required

function filter() {
<span =“Apple-tab-span” style=“white-space:pre”> var nodeArray = myDiagram.model.nodeDataArray;
<span =“Apple-tab-span” style=“white-space:pre”> var linkArray = myDiagram.model.linkDataArray;
<span =“Apple-tab-span” style=“white-space:pre”> var myDataArray=[];
<span =“Apple-tab-span” style=“white-space:pre”> var k=0;
<span =“Apple-tab-span” style=“white-space:pre”> for (i = 0; i < nodeArray.length; i++) {
<span =“Apple-tab-span” style=“white-space:pre”> nodeArrayBackup=nodeArray;
<span =“Apple-tab-span” style=“white-space:pre”> if(nodeArray.text==“Decision”)
<span =“Apple-tab-span” style=“white-space:pre”> {
<span =“Apple-tab-span” style=“white-space:pre”> myDataArray[k]=nodeArray;
<span =“Apple-tab-span” style=“white-space:pre”> k++;
<span =“Apple-tab-span” style=“white-space:pre”> }<span =“Apple-tab-span” style=“white-space:pre”>
<span =“Apple-tab-span” style=“white-space:pre”> }
<span =“Apple-tab-span” style=“white-space:pre”> myDiagram.model = new go.GraphLinksModel(myDataArray, linkArray);

Assuming all of the Nodes and Links are present in the Diagram, you could just set Node.visible to false for some subset of the Nodes.

Alternatively perhaps you could use Layers – putting subsets of Nodes in different Layers and then setting Layer.visible as desired.

Remember to make all changes within a transaction. By default changing the visibility of a Part will result in a new layout being performed. You can control that by setting Part.layoutConditions.