Hi, I’m using genogram code from the example here: Genogram
I defined my own link type, it’s points are affected by the sibling links.
myDiagram.linkTemplate = // for parent-child relationships
$(
CustomLink(),
{
routing: go.Link.Orthogonal,
corner: 5,
layerName: "Background",
selectable: false,
},
$(go.Shape, { stroke: "#424242", strokeWidth: 2 })
);
function CustomLink() {
class CustomLink extends go.Link {
public computePoints(): boolean {
const result = go.Link.prototype.computePoints.call(this);
const pts = this.points;
const parents = this.fromNode;
let childrenCount = 0;
let sumX = 0;
parents?.findNodesOutOf().each((child) => {
childrenCount++;
sumX += child.location.x;
});
const posX = sumX / childrenCount;
const posY = pts.elt(0).y + 57;
pts.setElt(2, new go.Point(pts.elt(0).x, posY));
pts.setElt(3, new go.Point(posX, posY));
pts.setElt(4, pts.elt(5));
return result;
}
}
return CustomLink;
}
I’m using ChangedListener to invalidate the sibling links when a link is being moved, however this ends up in an infinite loop of invalidating links and recomputing points. How can I prevent the infinite loop? Is it possible to pass arguments from invalidateRoute all the way to computePoints so I can prevent it?
myDiagram.addChangedListener((e) => {
if (e.propertyName !== "points") return;
if (!(e.object instanceof go.Link)) return;
const link = e.object;
const siblingLinks = link.fromNode?.findTreeChildrenLinks();
siblingLinks?.each((l) => {
if (l !== e.object) l.invalidateRoute();
});
});