Creating links

Create links with the createLink function of the Graph or the Diagram. If you use a Diagram widget, make sure to use the createLink function of the Diagram (ibm_ilog.diagram.widget.Diagram) class otherwise some features of the Diagram widget, like event dispatching, navigation, and editing do not work properly.
Each link connects two nodes that you specify through the methods setStartNode() and setEndNode().
To create nodes and links in your graph directly in a GFX surface:
  • Use the following code if you use a Graph directly in a GFX surface:
    var createLink = function(start, end) {
             var link = graph.createLink();
             link.setStartNode(start);
             link.setEndNode(end);
             return link;
          };
          
          var createNodesAndLinks = function() {
             var node1 = createNode("Node 1", 100, 200);
             var node2 = createNode("Node 2", 300, 100);
             var node3 = createNode("Node 3", 300, 300);
             var node4 = createNode("Node 4", 500, 200);
             var link1 = createLink(node1, node2);
             var link2 = createLink(node1, node3);
             var link3 = createLink(node2, node4);
             var link3 = createLink(node3, node4);
          };
          dojo.addOnLoad(createNodesAndLinks);
To create nodes and links in your graph if you use a Diagram widget:
  • Use the following code if you use a Diagram widget:
    var createLink = function(start, end) {
             var link = diag.createLink(start, end);
             link.setStartNode(start);
             link.setEndNode(end);
             return link;
          };
Here is the resulting graph with links:
A graph
made up of four rectangular nodes, each having a label on them: Node
1, Node 2, Node 3, Node 4. Node 1 is located on the left, Node 2 at
the top, Node 3 at the bottom, and Node 4 on the right of the graph.
Node 1 is connected to Node 2 and to Node 3 by links with an arrow
tip. Node 2 and Node 3 are connected to Node 4 by links with an arrow
tip.