GitHub Discussion #1968

https://github.com/clientIO/joint/discussions/1968

by Roman Bruckner

HTML

<html>
<head>
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jointjs/3.6.2/joint.css" />
</head>
<body>
      <!-- content -->
      <div id="paper"></div>

      <!-- dependencies -->
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.20/lodash.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.4.0/backbone.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jointjs/3.6.2/joint.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,
  defaultConnectionPoint: {
    name: 'boundary'
  },
  cellViewNamespace: joint.shapes,
  interactive: {
    labelMove: true
  },
  snapLabels: true,
  gridSize: 10,
  async: true,
  sorting: joint.dia.Paper.sorting.APPROX,
  linkPinning: false,
  defaultLink: () => new joint.shapes.standard.DoubleLink()
});

// Example

var el1 = new joint.shapes.standard.Rectangle({
  position: {
    x: 10,
    y: 170
  },
  size: {
    width: 100,
    height: 90
  },
  attrs: {
    label: {
      text: 'A'
    }
  }
});
var el2 = new joint.shapes.standard.Rectangle({
  position: {
    x: 400,
    y: 170
  },
  size: {
    width: 100,
    height: 90
  },
  attrs: {
    label: {
      text: 'B'
    }
  }
});

const l1 = new joint.shapes.standard.Link({
  source: {
    id: el1.id
  },
  target: {
    id: el2.id
  },
  attrs: {
    line: {
      strokeWidth: 3
    }
  },
  labels: [{
    markup: [{
      tagName: 'image',
      selector: 'labelImage'
    }],
    attrs: {
      labelImage: {
        x: -25,
        y: 0,
        width: 50,
        height: 100,
        strokeWidth: 2,
        'xlink:href': 'https://picsum.photos/id/201/50/100',
      }
    },
    position: {
      distance: 0.5,
      args: {
        keepGradient: true
      }
    }
  }, {
    markup: [{
      tagName: 'image',
      selector: 'labelImage'
    }],
    attrs: {
      labelImage: {
        x: -25,
        y: -100,
        width: 50,
        height: 100,
        strokeWidth: 2,
        'xlink:href': 'https://picsum.photos/id/202/50/100',
      }
    },
    position: {
      distance: 0.8,
      args: {
        keepGradient: true
      }
    }
  }, {
    markup: [{
      tagName: 'path',
      selector: 'labelPath'
    }, {
      tagName: 'circle',
      selector: 'labelCircle'
    }],
    attrs: {
     ...