GitHub Discussion #1706

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

by Roman Bruckner

HTML

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

      <!-- dependencies -->
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.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.4.4/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,
  gridSize: 10,
  async: true,
  sorting: joint.dia.Paper.sorting.APPROX
});

// Example

var el1 = new joint.shapes.standard.Rectangle({
  position: {
    x: 10,
    y: 10
  },
  size: {
    width: 100,
    height: 150
  },
  attrs: {
    label: {
      text: 'A'
    }
  },
  ports: {
    groups: {
      right: {
        position: 'right',
        markup: [{
          tagName: 'rect',
          selector: 'portBody',
          attributes: {
            width: 20,
            height: 2
          }
        }]
      }
    },
    items: [{
      id: 'p1',
      group: 'right',
    }, {
      id: 'p2',
      group: 'right',
    }]
  },

});

var el2 = new joint.shapes.standard.Rectangle({
  position: {
    x: 200,
    y: 50
  },
  size: {
    width: 100,
    height: 150
  },
  attrs: {
    label: {
      text: 'B'
    }
  },
  ports: {
    groups: {
      bottom: {
        position: 'left',
        markup: [{
          tagName: 'rect',
          selector: 'portBody',
          attributes: {
            width: 20,
            height: 2,
            x: -20,
          }
        }]
      }
    },
    items: [{
      id: 'p1',
      group: 'bottom',
    }, {
      id: 'p2',
      group: 'bottom',
    }]
  }
});

const l1 = new joint.shapes.standard.Link({
  source: {
    id: el1.id,
    port: 'p2',
    anchor: { name: 'right' }
  },
  target: {
    id: el2.id,
    port: 'p2',
    anchor: { name: 'left' }
  },
  attrs: {
    line: {
      targetMarker: null
    }
  },
  router: { name: 'orthogonal', args: { padding: 1 }}
});


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

paper.unfreeze();