Yes, your example also possible… but my need is total tree/map in canvas…
Let me take your ex:
A - B - C
Z - B
Y - C
Is one Tree/map
A - D - E
Z - D - E
Is one tree/map
So both tree/map is in page/canvas…
I need count 2…
Let me take one more example:
Let’s say I have attached tree… in that I need count that is 3 as 3 tree are available which is not shared any node with other tree
You are not using GridLayout, so my understanding of your problem was completely wrong.
The sketches help. But it makes clear that you do not have trees, either. It is not the case that every node has at most one parent. Otherwise there would be a trivial answer, the number of roots.
OK, it is easy enough to partition a set of nodes into a collection of subsets of nodes, where there are no links (in either direction) between any two subsets. Here is some JavaScript code:
function computeSubsets(nodes) {
var allnodes = new go.Set().addAll(nodes);
var colls = new go.Set();
function findSubset(node) {
var it = colls.iterator;
while (it.next()) {
var coll = it.value;
if (coll.has(node)) return coll;
}
return null;
}
while (allnodes.count > 0) {
var node = allnodes.first();
var subset = findSubset(node);
if (!subset) {
var newset = new go.Set();
function followSubset(node) {
if (!newset.has(node)) {
newset.add(node);
allnodes.remove(node);
node.findNodesConnected().each(followSubset);
}
}
colls.add(newset);
followSubset(node);
}
}
return colls;
}
So now you can evaluate computeSubsets(myDiagram.nodes) to get a go.Set
of go.Sets, where each subset holds all of the Nodes that are indirectly connected with each other and not with any other subset.
Thank you Walter for quick support…
I thought some predefined methods will be there to get number of partitions…but this satisfies my need, Iam happy with this…