Hi,
it's me again
My goal is align the anchor points for the diagram nodes programmatically. Therefore I wrote a method which re-aligns the anchor points for a diagram node (origin and destination).
Just now right, I realized that
diagram.getFactory().createDiagramLink(orig, dest)
does not offer parameters for the new calculated anchorpoints.
Why do I want to do that? The links are not starting from the anchor point and not ending at the destination point. I have followed this tutorial:
https://www.mindfusion.eu/onlinehelp/jsdiagram/index.htm. It seems like the anchors are searching for the shortest way. Nevertheless, I reorder the position of the anchor points at runtime when some specific user interactions happen.
Additionally to the mentioned tutorial, I made some slight changes:
After creating the diagram, I call
diagram.setLinkShape = MindFusion.Diagramming.LinkShape.Cascading;
diagram.showAnchors = ShowAnchor.Always;
I also edited the nodes ForEach, to provide a unique AnchorPattern for each diagram node:
var nodes = graph.nodes;
nodes.forEach(node => {
var diagramNode = diagram.getFactory().createShapeNode(bounds);
nodeMap[node.id] = diagramNode;
diagramNode.setText(node.name);
diagramNode.setTextAlignment(MindFusion.Diagramming.Alignment.Center);
diagramNode.setLineAlignment(MindFusion.Diagramming.Alignment.Near);
diagramNode.setBrush("#e0e9e9");
diagramNode.setAnchorPattern(new AnchorPattern([]));
});
In the links loop, I do the same before, just trying to manage the new alignment now:
var links = graph.links;
links.forEach(link => {
var link = diagram.getFactory().createDiagramLink(
nodeMap[link.origin],
nodeMap[link.target]);
this.manageNewLink(link);
});
The function manageNewLink determine where to play the new AnchorPoint and what to do with already existing ones.
So the result of that method consists of two anchor points, one for the origin, one for the destination.
What I'm looking for, is a way to say
link.setOriginAnchor(anchorPointOrigin);
link.setDestinationAnchor(anchorPointDestination);
but actually this method expects a number as argument, not a AnchorPoint object.
What can I do to assign the anchorpoints to the link?