replace route with vertices

by Roman Bruckner

HTML

<html>

  <head>
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jointjs/3.7.2/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.7.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,
  cellViewNamespace: joint.shapes,
  gridSize: 10,
  async: true,
  sorting: joint.dia.Paper.sorting.APPROX,
  defaultRouter: {
     name: 'orthogonal'
  },
  snapLinks: true,
  linkPinning: false,
  defaultLink: () => new joint.shapes.standard.Link()
});

// 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',
        attrs: {
          portRect: {
            width: 20,
            height: 20,
            fill: '#fff',
            stroke: '#333',
            strokeWidth: 2,
            magnet: true
          }
        },
        markup: [{
          tagName: 'rect',
          selector: 'portBody',
          groupSelector: 'portRect'
        }],
      }
    },
    items: [{
      id: 'p1',
      group: 'right',
    }]
  },

});

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


graph.resetCells([el1, el2]);

paper.unfreeze();

paper.on('link:connect', (linkView) => {
   paper.requireView(linkView);
   const { route, model } = linkView;
   model.vertices(route);
   model.router('normal');
});

paper.on('link:pointerclick', (linkView) => {
  const tools = new joint.dia.ToolsView({
  
     tools: [new joint.linkTools.Vertices(), new joint.linkTools.Segments()]
  });
  linkView.addTools(tools);
});