Creating nodes

In this section, you are going to learn how to create and manage nodes in your graph.
To create and manage nodes:
  1. Create four nodes with the method createNode() of the Graph or the Diagram.
    If you use a Diagram widget, make sure to use the createNode 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.
  2. Set the label on each node with the method setLabel(label).
  3. Move the nodes with the method move(x, y).
Use the following code if you use a Graph directly in a GFX surface:
var createNode = function(label, x, y){
         var node = graph.createNode();
         node.setLabel(label);
         node.move(x, y);
         return node;
      };
Use the following code if you use a Diagram widget:
var createNode = function(label, x, y){
         var node = diag.createNode();
         node.setLabel(label);
         node.move(x, y);
         return node;
      };
At this stage, the graph looks as follows:
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.