Search code examples
jointjs

How to make a jointjs.dia.link end in a circle?


I'm migrating an old piece of code that used jointjs v0.9 to the most recent version (2.2.1). There is this part of the code which creates a simple link with a little circle at the end (target marker) but in the most recent version, this code is not working:

 link = new Joint.dia.Link({
    source: { x: x, y: 0 }
    target: { x: x, y: y }
    markup: '<path class="connection" d="M 0 0 0 0"/><circle r="5" />'
    attrs: { '.connection': `connection ${this.getStyleClass()}`
 })

How can I create a link a Join.dia.link with a circle as the target marker?


Solution

  • var link = new joint.dia.Link({
        source: {
            id: srcId
        },
        target: {
            id: destId
        }, 
        router: { name: 'manhattan' },
        connector: { name: 'rounded' },
        toolMarkup: "none"
    });
    link.attr({
        '.marker-target': { fill: 'red', d: 'M 0, 0 m -5, 0 a 5,5 0 1,0 10,0 a 5,5 0 1,0 -10,0', stroke: 'none' },
        '.connection': { stroke: 'red', 'stroke-width': '1px' },
        '.marker-arrowheads': { display: "none" }
    });
    

    In this d:'M 0, 0 m -5, 0 a 5,5 0 1,0 10,0 a 5,5 0 1,0 -10,0' sets the circle to the end of link. If you want any other shape you can write its path code and set it here.