Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Custom anchor point between DiagramNode and DiagramLink (Read 313 times)
Kamil
YaBB Newbies
*
Offline



Posts: 22
Joined: Aug 22nd, 2024
Custom anchor point between DiagramNode and DiagramLink
Oct 3rd, 2024 at 10:41am
Print Post  
Hi,
In my code, I'm automatically creating a destination node if a link doesn't have a destination node. I'm using linkCreated event for that:

Code (Javascript)
Select All
export const handleLinkCreated = (diagram, args) => {

    const link = args._link;
    const destination = args._destination;
    link.text = DEFAULT_LINK_TEXT;
    link.brush = ARROW_HEAD_COLOR;
    link.zIndex = LINK_ZINDEX;

    if(!destination) {
        const linkTargetPoint = link.points.at(-1);

        const destinationNode = diagram.factory.createShapeNode(linkTargetPoint._x, linkTargetPoint._y, MOCK_RECTANGLE_UNIT.size, MOCK_RECTANGLE_UNIT.size);
        destinationNode.allowOutgoingLinks = false;

        const anchorPatternTargetNode = new mfDiagramming.AnchorPattern([
            new mfDiagramming.AnchorPoint(MOCK_RECTANGLE_UNIT.inPortPosition.x, MOCK_RECTANGLE_UNIT.inPortPosition.y, true, false, mfDiagramming.MarkStyle.Custom, ANCHOR_POINT_COLOR, ANCHOR_POINT_SIZE),
        ]);
        destinationNode.addLabel(DEFAULT_UNIT_TEXT).setCenterPosition(0, -MOCK_RECTANGLE_UNIT.size / 2 - 2);
        destinationNode.anchorPattern = anchorPatternTargetNode;
        link.setDestination(destinationNode);
    }


    link.route();
}  



and here is my implementation of the function that renders a custom anchor point:

Code (Javascript)
Select All
export const handleDrawAnchorPoint = (_sender, e) => {
    const p = e.location;
    const ctx = e.context;
    const CIRCLE_RADIUS = 0.5;
    const STROKE_WIDTH = 0.5;
    const OFFSET = 0.5;

    ctx.beginPath();
    ctx.fillStyle = 'rgb(0,0,0)';
    ctx.strokeStyle = 'rgb(255,255,255)';
    ctx.lineWidth = STROKE_WIDTH;

    ctx.ellipse(p.x - CIRCLE_RADIUS + OFFSET, p.y - CIRCLE_RADIUS + OFFSET, CIRCLE_RADIUS * 2, CIRCLE_RADIUS * 2, Math.PI / 4, 0, 2 * Math.PI);

    ctx.fill();

    ctx.stroke();

}
 



The problem is that my anchor point in being drawn on top of the link. I want it to be between the destination node and the link (the link should be on top).

The attachment contains my current result.
Could you advise me on how to achieve that?


  

Zrzut_ekranu_2024-10-03_123943.png ( 4 KB | 24 Downloads )
Zrzut_ekranu_2024-10-03_123943.png
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Online


tech.support

Posts: 3343
Joined: Oct 19th, 2005
Re: Custom anchor point between DiagramNode and DiagramLink
Reply #1 - Oct 3rd, 2024 at 11:49am
Print Post  
Hi,

What is the LINK_ZINDEX value? Anchor points are drawn along with their node, and link will draw on top if its zIndex value is large than node.zIndex. That's auto-assigned when you create the new node, so try setting link.zIndex = destinationNode.zIndex + 1.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Kamil
YaBB Newbies
*
Offline



Posts: 22
Joined: Aug 22nd, 2024
Re: Custom anchor point between DiagramNode and DiagramLink
Reply #2 - Oct 4th, 2024 at 7:15am
Print Post  
LINK_ZINDEX value is 1000. I've also added a line for setting zIndex for destination node:

Code (Javascript)
Select All
    if(!destination) {
        const linkTargetPoint = link.points.at(-1);

        const destinationNode = diagram.factory.createShapeNode(linkTargetPoint._x, linkTargetPoint._y, MOCK_RECTANGLE_UNIT.size, MOCK_RECTANGLE_UNIT.size);
        destinationNode.allowOutgoingLinks = false;

        const anchorPatternTargetNode = new mfDiagramming.AnchorPattern([
            new mfDiagramming.AnchorPoint(MOCK_RECTANGLE_UNIT.inPortPosition.x, MOCK_RECTANGLE_UNIT.inPortPosition.y, true, false, mfDiagramming.MarkStyle.Custom, ANCHOR_POINT_COLOR, ANCHOR_POINT_SIZE),
        ]);
        destinationNode.addLabel(DEFAULT_UNIT_TEXT).setCenterPosition(0, -MOCK_RECTANGLE_UNIT.size / 2 - 2);
        destinationNode.anchorPattern = anchorPatternTargetNode;
        link.setDestination(destinationNode);
        destinationNode.zIndex = 0;
    }

 



But nothing changed.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Online


tech.support

Posts: 3343
Joined: Oct 19th, 2005
Re: Custom anchor point between DiagramNode and DiagramLink
Reply #3 - Oct 4th, 2024 at 1:34pm
Print Post  
Right, the diagram sets anchor points as topmost actually. For time being try replacing this method in node prototype:

Code
Select All
var originalAddAP = DiagramNode.prototype.addAnchorPointVisuals;

DiagramNode.prototype.addAnchorPointVisuals = function()
{
	originalAddAP.apply(this);
	this.anchorPatternVisual.zIndex = this.zIndex + 0.1;
} 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Kamil
YaBB Newbies
*
Offline



Posts: 22
Joined: Aug 22nd, 2024
Re: Custom anchor point between DiagramNode and DiagramLink
Reply #4 - Oct 7th, 2024 at 9:14am
Print Post  
Thanks for the solution Smiley Now it works perfectly!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint