Link Marker Offset

by Roman Bruckner

HTML

<html>

  <head>
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" />
  </head>

  <body>
    <!-- content -->
    <div id="paper" style="margin: 20px;"></div>

    <!-- dependencies -->
    <script src="https://cdn.jsdelivr.net/npm/@joint/[email protected]/dist/joint.min.js"></script>
  </body>

</html>

JavaScript

var graph = new joint.dia.Graph({}, {
  cellNamespace: joint.shapes
});

const paper = new joint.dia.Paper({
  el: document.getElementById('paper'),
  width: 800,
  height: 900,
  model: graph,
  cellViewNamespace: joint.shapes,
  gridSize: 10,
  async: true,
  sorting: joint.dia.Paper.sorting.APPROX,
  linkPinning: false,  
  defaultLink: (elementView, magnet) => {
    return new joint.shapes.standard.Link();
  },
  defaultConnectionPoint: {
       name: 'boundary',
       args: {
           offset: 10
       }
  },
  defaultRouter: { name: 'normal' }  
});

paper.scale(2, 2);

// Example

var el1 = new joint.shapes.standard.Rectangle({
  position: {
    x: 10,
    y: 70
  },
  size: {
    width: 100,
    height: 90
  }
});

var el2 = el1.clone().position(300, 50);


const l1 = new joint.shapes.standard.Link({
  source: {
    id: el1.id
  },
  target: {
    id: el2.id
  },
  attrs: {
     line: {
        strokeWidth: 2,
        strokeDasharray: '5,5',
        targetMarker: {
            d: 'M 0 -5 0 5 -10 0',
            stroke: 'red',
            strokeDasharray: 'none'            
        },
        sourceMarker: {
            d: 'M 0 -5 0 5 -10 0',
            stroke: 'red'
        }     
 
     }
  }
});


graph.resetCells([el1, el2, l1]);


paper.unfreeze();