Implementing the layout method

Depending on the characteristics of the layout algorithm, some of the steps required can be different or unnecessary, or other steps can be required.
Depending on the particular implementation of your layout algorithm, other methods of the base graph layout class must be overridden. For instance, if your subclass supports some of the generic parameters of the base class, you must override the supports[ParameterName] method (see Base class parameters and features).
For further information about the class ibm_ilog.graphlayout.GraphLayout, refer to the class library documentation.
To implement the layout method in the sample custom layout algorithm:
  1. Obtain the graph model (getGraphModel() on the layout instance).
    var model = this.getGraphModel();
    
  2. Obtain the instance of the layout report that is automatically created when the performLayout method from the superclass is called (getLayoutReport() on the layout instance), see Using a graph layout report.
    var report = this.getLayoutReport();
    
  3. Obtain the layout region parameter to compute the area where the nodes will be placed.
    var rect = this.getCalcLayoutRegion();
    
  4. Get a vector of the nodes (nodes property on the graph layout model instance).
    var nds = model.getNodes();
    
  5. Browse the nodes, skipping fixed nodes (isFixed(node) on the layout instance) if requested by the user (isPreserveFixedNodes() on the layout instance).
                    var count = nds.length;
                    for (var i = 0; i < count; i++) {
                        var node = nds[i];
                        ...
                    }
    
    
    (For details on fixed nodes, see Preserve fixed nodes).
  6. Move each node to the newly computed coordinates inside the layout region:
    model.moveNode
    model.moveNode(node, x, y);
    
  7. Notify the listeners on layout events that a new node was positioned. This allows the user to implement, for example, a progress bar if a layout event listener was registered on the layout instance. (For details on event listeners, see Using event listeners.)
    On the layout instance, call:
    this.callLayoutStepPerformedIfNeeded();
    
  8. Finally, set the code in the layout report.
    report.code = ibm_ilog.graphlayout.GraphLayoutReport.LAYOUT_DONE;
    
Once you have implemented your own layout algorithm MyRandomLayout, you can use it directly in Dojo JavaScript.