By default, the BI Beans graph automatically lays out its components, based on the data in the graph. The graph determines the size of the plot area and of the legend area, based on the amount of space that is needed to display labels. The graph also places the legend area. The automatic layout might also enable word wrapping in labels, for example, or it might change the orientation of the legend area. The graph does not automatically lay out components in a three-dimensional graph.
When the graph automatically lays out components, users of the Java-client graph cannot use the mouse to resize or move components. (Users of the thin graph cannot move or resize components in any case.)
By default, the graph always performs automatic layout. You can set the graph to perform automatic layout only when there is a problem, such as when components overlap each other or when labels are too large to fit in the legend boundary. Or, you can disable the automatic layout altogether and have more control over the customization of the legend, customization of tick labels, and the placement of components.
If you disable the automatic layout, then you can have the graph do a single layout optimization, which you can then customize.
Your application should have a single strategy with regard to automatic layout. Enabling and disabling automatic layout at runtime requires a thorough knowledge of the interaction between the automatic layout code and the graph properties.
When the graph automatically lays out its components, you still have control over the following:
The horizontal alignment of the title, subtitle, and footnote of the graph
The position of the legend, including whether the legend lies along the edge of the graph
The fonts in graph components, such as tick labels and legend text
The continuous automatic layout respects these settings. You can specify whether the single layout optimization respects these settings or resets them to automatic settings.
If you manage layout in your code, you might want to use automatic layout as
a safeguard against a situation that your code does not cover. To have the graph
lay out components automatically only when components overlap or there is another
layout problem, set the AutoLayout
property of the graph to AL_AS_NEEDED
:
graph.setAutoLayout(Graph.AL_AS_NEEDED);
To disable the automatic layout of the graph altogether, set the AutoLayout
property of the graph to AL_NEVER
, as shown in this example:
graph.setAutoLayout(Graph.AL_NEVER); // you might also want to enable mouse movement graph.setMouseMovingEnabled(true);
Note: Automatic graph layout ignores the values of a number of properties that affect the appearance of the graph. When you disable automatic layout, these property values are used to display the graph. For this reason, the appearance of the graph may change if you disable automatic layout.
To have the graph do one optimization for automatic layout, which you can then
adjust, set AutoLayout
to AL_NEVER
and then call the
doAutoLayout
method of the graph. This method does the same optimization
that the automatic layout performs, but only once. Also, where the automatic
layout ignores property settings that determine the appearance of some components,
the doAutoLayout
method sets these properties, so you can examine
the property values and adjust them as necessary. For example, the continual
automatic layout ignores the value of the LegendTextPosition
property
of the LegendArea
. The doAutoLayout
method sets this
property, so you can examine its value after the graph has been automatically
arranged.
The javadoc for the doAutoLayout
method lists the properties that
the method sets.
The following code performs a single optimization for a good layout. Then it checks to see if the legend is horizontal. If it is horizontal, then this example moves the legend text to below the legend markers. The code then enables mouse movement, so users can move and resize items.
// disable automatic layout graph.setAutoLayout(Graph.AL_NEVER); // do one layout optimization // RESET_PROPERTIES, to treat properties as automatic graph.doAutoLayout(Graph.RESET_PROPERTIES); // check legend orientation, and set text position according to it if (legend.getLegendOrientation() == BaseGraphComponent.LO_HORIZONTAL) legend.setLegendTextPosition(BaseGraphComponent.LTP_BELOW); // allow users to move components with the mouse graph.setMouseMovingEnabled(true);