In a scenario of top down tree layout where there are multiple outgoing links from a node, We are using the node.findLinksOutOf() to work with accessibility and we use indexing to move from link to link from left to right. The order of the links returned from this function are looking like timestamped as they always follow the sequence in which they are created. Is there a way to order them so the list always gives left to right sequence?
I suggest that you sort the collection so that it has the order that you want. Perhaps something like:
const node = ...
if (node instanceof go.Node) {
const children = new go.List(node.findTreeChildrenNodes());
children.sort((a, b) => a.location.x - b.location.x);
console.log(children.count);
children.each(c => console.log(c.data.text));
}
Hi @walter , I tried your suggestion with node.findLinksOutOf() since i want this behaviour with links not nodes. Seems to work but from i gathered links go not have location by default? Can you help me understand which point on the link is it comparing when we do the below? is it the center of the containing box or which point?
const linkList = new go.List(node.findLinksOutOf());
linkList.sort((a, b) => a.location.x - b.location.x);
Sort the nodes by getting each link’s Link.toNode.
Hi @walter , Is there a reason why we want to sort the nodes instead of the links? or are you suggesting to sort the links based of the locations of the children nodes?
If that is the case. Will that cover the below scenerio?
Which is the first to focus when moving down from action 5?
I assume we need to check both x and y? Please let me know the difference between using .location on link vs .location on node and which one is better to follow?
In this case what order do you want, and why?
Yes, I was suggesting ordering the links by their toNode’s location.x values.
const node = ...
if (node instanceof go.Node) {
const childlinks = new go.List(node.findTreeChildrenLinks());
childlinks.sort((a, b) => a.toNode.location.x - b.toNode.location.x);
console.log(childlinks.count);
childlinks.each(c => console.log(c.toNode.data.text));
}
