6

I am trying to create links programmatically in JointJs to devs.Model objects that have ports.

I've tried to use the addCell for graph from the api (http://jointjs.com/api#joint.dia.Graph:addCell), but for some reason the links created are not pointing to the correct port circles on the source and target devs.Model objects, but rather the entire element themselves.

Here is the code I'm attempting to use:

var link = new joint.dia.Link({
      source: {
        id: srcModel.id,
        port: 'out'
      },
      target: {
        id: dstModel.id,
        port: 'in'
      }
    });
// Assume graph has the srcModel and dstModel with in and out ports.
graph.addCell(link)

The links are created, but not pointing to any ports, so I feel like there is just one little tweak I need to get these links to work.

Joshua
  • 3,055
  • 3
  • 22
  • 37
user3749851
  • 61
  • 1
  • 2
  • This looks correct. Could you provide the full example, including your devs.Model. Do you have a port named 'in' and 'out' in your srcModel/dstModel? – dave Jun 18 '14 at 11:24
  • Disregard please. Turns out there were a few bugs to work out, and this is working. Thanks, @dave. – user3749851 Jun 19 '14 at 16:14

2 Answers2

3

Just Change joint.dia.Link for joint.shapes.devs.Link :

  var link = new joint.shapes.devs.Link({
     source: {
       id: srcModel.id,
       port: 'out'
     },
     target: {
       id: dstModel.id,
       port: 'in'
     }
   });
  // Assume graph has the srcModel and dstModel with in and out ports.
  graph.addCell(link)
Shadow
  • 61
  • 1
  • 5
1

Add connector and router. Example:

var link = new joint.shapes.devs.Link({
   source: {
     id: srcModel.id,
     port: 'out'
   },
   target: {
     id: dstModel.id,
     port: 'in'
   },
  connector: { name: 'rounded' },
  router: { name: 'metro' }
});
graph.addCell(link);
Aung Myat Hein
  • 4,018
  • 1
  • 36
  • 42