skip to main content
Diagrammer > Programmer's documentation > Using graph layout algorithms > Automatic label placement > Random Label Layout
 
Random Label Layout
Describes the Random Label Layout algorithm (class IlvRandomLabelLayout from the package ilog.views.graphlayout.labellayout.random).
*Sample
*Gives a sample of the Random Label Layout and an explanation.
*Features
*Lists the features of the Random Label Layout.
*The algorithm
*Describes how the Random Label layout algorithm operates.
*Code sample
*Gives a code sample showing how to use the Random Label Layout.
*Generic features and parameters
*Lists the generic features and parameters of the Random Label Layout.
*Specific parameters
*Lists the specific parameters of the Random Label Layout.
Sample
The Random Label layout can only be used in Java™. It is not available in the label layout renderer of a diagram component, hence there is no way to specify this layout in CSS. It exists only for demonstration purposes.
The following sample drawing was produced with the Random Label Layout.
Label placement produced with the Random Label Layout
Although each label belongs to a circle of the same color, the random label placement does not show this. Instead it places the labels randomly, creating many overlaps. The Random Label Layout can be used to shuffle the labels arbitrarily in a specified area.
Features
*Mainly for demonstration purposes.
*Random placement of the labels inside a specified region.
The algorithm
The Random Label Layout algorithm is not really a useful layout algorithm. It simply places the labels at randomly-computed positions inside a user-defined region. Nevertheless, the Random Label Layout algorithm may be useful for demonstration purposes.
Code sample
Below is a code sample using the IlvRandomLabelLayout class:
 
 ...
import ilog.views.*;
import ilog.views.graphlayout.labellayout.*;
import ilog.views.graphlayout.labellayout.random.*;
 ...
IlvManager manager = new IlvManager();
IlvManagerView view = new IlvManagerView(manager);
 
 ... /* Fill in here code that fills the manager with labels and obstacles */
 
IlvRandomLabelLayout layout = new IlvRandomLabelLayout();
layout.attach(manager);
layout.setLayoutRegion(new IlvRect(0, 0, 200, 200));
IlvLabelLayoutReport layoutReport = layout.performLayout();
if (layoutReport.getCode() == IlvLabelLayoutReport.LAYOUT_DONE)
     System.out.println("Layout done.");
else
     System.out.println("Layout not done, code = " +
                                   layoutReport.getCode());
Generic features and parameters
The IlvRandomLabelLayout class supports the following generic parameters defined in the IlvLabelLayout class:
*Allowed time
*Percentage of completion calculation
*Random generator seed value
*Save parameters to named properties
*Stop immediately
*Use default parameters
The following comments describe the particular way in which these parameters are used by this subclass.
Allowed time
The label layout algorithm stops if the allowed time setting has elapsed. This feature works similarly as in IlvGraphLayout; see Allowed time. If the layout stops early because the allowed time has elapsed, the result code in the layout report is IlvLabelLayoutReport.STOPPED_AND_INVALID.
Percentage of completion calculation
The label layout algorithm calculates the estimated percentage of completion. This value can be obtained from the label layout report during the run of the layout. (For a detailed description of this feature, see Percentage of completion calculation and Layout events and listeners.)
Random generator seed value
The Random Label Layout uses a random number generator to compute the coordinates. For the default behavior, the random generator is initialized using the current system clock. Therefore, different layouts are obtained if you perform the layout repeatedly on the same graph.
You can specify a particular value to be used as a seed value. For example, to specify the seed value 10, call:
 
layout.setUseSeedValueForRandomGenerator(true);
layout.setSeedValueForRandomGenerator(10);
Save parameters to named properties
The label layout algorithm can save its layout parameters into named properties. This can be used to save layout parameters to .ivl files. (For a detailed description of this feature, see Using named properties to save layout parameters.)
Stop immediately
The label layout algorithm stops after cleanup if the method stopImmediately is called. (This method works for the IlvLabelLayout class similarly to the corresponding method in the IlvGraphLayout class. For a description of this method in the IlvGraphLayout class, see Stop immediately. If the layout stops early in this way, the result code in the layout report is IlvLabelLayoutReport.STOPPED_AND_INVALID.
Use default parameters
After modifying any label layout parameter, you may want the layout algorithm to use the default values. You select the default values for all parameters by:
 
layout.setUseDefaultParameters(true);
Rogue Wave  JViews Diagrammer keeps the previous settings when selecting the default values mode. You can switch between back to your own settings by:
 
layout.setUseDefaultParameters(false);
Specific parameters
The following parameter is specific to the IlvRandomLabelLayout class:
Layout region
The Random Label Layout algorithm places the labels randomly in a specified region. You can set this region by:
 
setLayoutRegion(IlvRect region)
You can obtain the current region by:
 
getLayoutRegion()
If no layout region is specified, the default region (0, 0, 100, 100) is used.

Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.