com.jrefinery.chart
Class NumberAxis

java.lang.Object
  extended by com.jrefinery.chart.Axis
      extended by com.jrefinery.chart.ValueAxis
          extended by com.jrefinery.chart.NumberAxis
All Implemented Interfaces:
AxisConstants
Direct Known Subclasses:
HorizontalNumberAxis, VerticalNumberAxis

public abstract class NumberAxis
extends ValueAxis

The base class for axes that display numerical data.

If the axis is set up to automatically determine its range to fit the data, you can ensure that the range includes zero (statisticians usually prefer this) by setting the autoRangeIncludesZero flag to true.

The NumberAxis class has a mechanism for automatically selecting a tick unit that is appropriate for the current axis range. This mechanism is an adaptation of code suggested by Laurence Vanhelsuwe.

See Also:
HorizontalNumberAxis, VerticalNumberAxis

Field Summary
protected  boolean autoRangeIncludesZero
          A flag that affects the axis range when the range is determined automatically.
protected  java.lang.Number autoRangeMinimumSize
          The minimum size of a range that is determined automatically.
protected  boolean autoRangeStickyZero
          A flag that affects the size of the margins added to the axis range when the range is determined automatically.
static boolean DEFAULT_AUTO_RANGE_INCLUDES_ZERO
          The default value for the autoRangeIncludesZero flag.
static boolean DEFAULT_AUTO_RANGE_STICKY_ZERO
          The default value for the autoRangeStickyZero flag.
static double DEFAULT_LOWER_MARGIN
          The default value for the lower margin (0.05 = 5%).
static java.lang.Number DEFAULT_MINIMUM_AUTO_RANGE
          The default minimum auto range.
static NumberTickUnit DEFAULT_TICK_UNIT
          The default tick unit.
static double DEFAULT_UPPER_MARGIN
          The default value for the upper margin (0.05 = 5%).
protected  boolean inverted
          A flag that affects the orientation of the values on the axis.
protected  double lowerMargin
          The lower margin.
protected  TickUnits standardTickUnits
          The standard tick units for the axis.
protected  NumberTickUnit tickUnit
          The tick unit for the axis.
protected  double upperMargin
          The upper margin.
 
Fields inherited from class com.jrefinery.chart.ValueAxis
anchorValue, autoRange, autoTickIndex, autoTickUnitSelection, crosshairLockedOnData, crosshairPaint, crosshairStroke, crosshairValue, crosshairVisible, DEFAULT_AUTO_RANGE, DEFAULT_CROSSHAIR_PAINT, DEFAULT_CROSSHAIR_STROKE, DEFAULT_CROSSHAIR_VISIBLE, DEFAULT_GRID_LINE_PAINT, DEFAULT_GRID_LINE_STROKE, DEFAULT_MAXIMUM_AXIS_VALUE, DEFAULT_MINIMUM_AXIS_VALUE, fixedAutoRange, gridLinesVisible, gridPaint, gridStroke, maximumRangeLength, minimumRangeLength, range
 
Fields inherited from class com.jrefinery.chart.Axis
fixedDimension, label, labelFont, labelInsets, labelPaint, listeners, plot, tickLabelFont, tickLabelInsets, tickLabelPaint, tickLabelsVisible, tickMarkStroke, tickMarksVisible, ticks, visible
 
Fields inherited from interface com.jrefinery.chart.AxisConstants
DEFAULT_AXIS_LABEL_FONT, DEFAULT_AXIS_LABEL_INSETS, DEFAULT_AXIS_LABEL_PAINT, DEFAULT_TICK_LABEL_FONT, DEFAULT_TICK_LABEL_INSETS, DEFAULT_TICK_LABEL_PAINT, DEFAULT_TICK_STROKE
 
Constructor Summary
protected NumberAxis(java.lang.String label)
          Constructs a number axis, using default values where necessary.
protected NumberAxis(java.lang.String label, java.awt.Font labelFont, java.awt.Paint labelPaint, java.awt.Insets labelInsets, boolean tickLabelsVisible, java.awt.Font tickLabelFont, java.awt.Paint tickLabelPaint, java.awt.Insets tickLabelInsets, boolean tickMarksVisible, java.awt.Stroke tickMarkStroke, boolean autoRange, boolean autoRangeIncludesZero, boolean autoRangeStickyZero, java.lang.Number autoRangeMinimumSize, double minimumAxisValue, double maximumAxisValue, boolean inverted, boolean autoTickUnitSelection, NumberTickUnit tickUnit, boolean gridLinesVisible, java.awt.Stroke gridStroke, java.awt.Paint gridPaint, boolean crosshairVisible, double crosshairValue, java.awt.Stroke crosshairStroke, java.awt.Paint crosshairPaint)
          Constructs a number axis.
 
Method Summary
 boolean autoRangeIncludesZero()
          Returns the flag that indicates whether or not the automatic axis range (if indeed it is determined automatically) is forced to include zero.
 boolean autoRangeStickyZero()
          Returns a flag that affects the auto-range when zero falls outside the data range but inside the margins defined for the axis.
 double calculateHighestVisibleTickValue()
          Calculates the value of the highest visible tick on the axis.
 double calculateLowestVisibleTickValue()
          Calculates the value of the lowest visible tick on the axis.
 int calculateVisibleTickCount()
          Calculates the number of visible ticks.
 java.lang.Number getAutoRangeMinimumSize()
          Returns the minimum size of the automatic axis range (if indeed it is determined automatically).
 double getLowerMargin()
          Returns the margin (as a percentage of the range) by which the minimum axis value is less than the minimum data value.
 TickUnits getStandardTickUnits()
          Returns the standard tick units for the axis.
 NumberTickUnit getTickUnit()
          Returns the tick unit for the axis.
 double getUpperMargin()
          Returns the margin (as a percentage of the range) by which the maximum axis value exceeds the maximum data value.
 boolean isInverted()
          Returns a flag that controls the direction of values on the axis.
 void setAutoRangeIncludesZero(boolean flag)
          Sets the flag that indicates whether or not the automatic axis range is forced to include zero.
 void setAutoRangeMinimumSize(java.lang.Number size)
          Sets the minimum size of the automatic axis range.
 void setAutoRangeStickyZero(boolean flag)
          Sets a flag that affects the auto-range when zero falls outside the data range but inside the margins defined for the axis.
 void setInverted(boolean flag)
          Sets a flag that controls the direction of values on the axis, and notifies registered listeners that the axis has changed.
 void setLowerMargin(double margin)
          Sets the lower margin.
 void setStandardTickUnits(TickUnits collection)
          Sets the collection of tick units for the axis, and notifies registered listeners that the axis has changed.
 void setTickUnit(NumberTickUnit unit)
          Sets a fixed tick unit for the axis, and notifies registered listeners that the axis has been changed.
 void setUpperMargin(double margin)
          Sets the upper margin.
 
Methods inherited from class com.jrefinery.chart.ValueAxis
autoAdjustRange, centerRange, getAnchorValue, getCrosshairPaint, getCrosshairStroke, getCrosshairValue, getFixedAutoRange, getGridPaint, getGridStroke, getMaximumAxisValue, getMinimumAxisValue, getRange, isAutoRange, isAutoTickUnitSelection, isCrosshairLockedOnData, isCrosshairVisible, isGridLinesVisible, resizeRange, resizeRange, setAnchoredRange, setAnchorValue, setAutoRange, setAutoTickUnitSelection, setCrosshairLockedOnData, setCrosshairPaint, setCrosshairStroke, setCrosshairValue, setCrosshairVisible, setFixedAutoRange, setGridLinesVisible, setGridPaint, setGridStroke, setMaximumAxisValue, setMinimumAxisValue, setRange, setRange, setRangeAboutValue, translateJava2DtoValue, translateValueToJava2D
 
Methods inherited from class com.jrefinery.chart.Axis
addChangeListener, configure, draw, getFixedDimension, getLabel, getLabelFont, getLabelInsets, getLabelPaint, getMaxTickLabelWidth, getPlot, getTickLabelFont, getTickLabelInsets, getTickLabelPaint, getTickMarkStroke, isCompatiblePlot, isTickLabelsVisible, isTickMarksVisible, isVisible, notifyListeners, refreshTicks, removeChangeListener, setFixedDimension, setLabel, setLabelFont, setLabelInsets, setLabelPaint, setPlot, setTickLabelFont, setTickLabelInsets, setTickLabelPaint, setTickLabelsVisible, setTickMarkStroke, setTickMarksVisible, setVisible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_AUTO_RANGE_INCLUDES_ZERO

public static final boolean DEFAULT_AUTO_RANGE_INCLUDES_ZERO
The default value for the autoRangeIncludesZero flag.

See Also:
Constant Field Values

DEFAULT_AUTO_RANGE_STICKY_ZERO

public static final boolean DEFAULT_AUTO_RANGE_STICKY_ZERO
The default value for the autoRangeStickyZero flag.

See Also:
Constant Field Values

DEFAULT_UPPER_MARGIN

public static final double DEFAULT_UPPER_MARGIN
The default value for the upper margin (0.05 = 5%).

See Also:
Constant Field Values

DEFAULT_LOWER_MARGIN

public static final double DEFAULT_LOWER_MARGIN
The default value for the lower margin (0.05 = 5%).

See Also:
Constant Field Values

DEFAULT_MINIMUM_AUTO_RANGE

public static final java.lang.Number DEFAULT_MINIMUM_AUTO_RANGE
The default minimum auto range.


DEFAULT_TICK_UNIT

public static final NumberTickUnit DEFAULT_TICK_UNIT
The default tick unit.


inverted

protected boolean inverted
A flag that affects the orientation of the values on the axis.


autoRangeIncludesZero

protected boolean autoRangeIncludesZero
A flag that affects the axis range when the range is determined automatically. If the auto range does NOT include zero and this flag is TRUE, then the range is changed to include zero.


autoRangeStickyZero

protected boolean autoRangeStickyZero
A flag that affects the size of the margins added to the axis range when the range is determined automatically. If the value 0 falls within the margin and this flag is TRUE, then the margin is truncated at zero.


autoRangeMinimumSize

protected java.lang.Number autoRangeMinimumSize
The minimum size of a range that is determined automatically.


upperMargin

protected double upperMargin
The upper margin. This is a percentage that indicates the amount by which the maximum axis value exceeds the maximum data value when the axis range is determined automatically.


lowerMargin

protected double lowerMargin
The lower margin. This is a percentage that indicates the amount by which the minimum axis value is "less than" the minimum data value when the axis range is determined automatically.


tickUnit

protected NumberTickUnit tickUnit
The tick unit for the axis.


standardTickUnits

protected TickUnits standardTickUnits
The standard tick units for the axis.

Constructor Detail

NumberAxis

protected NumberAxis(java.lang.String label)
Constructs a number axis, using default values where necessary.

Parameters:
label - The axis label.

NumberAxis

protected NumberAxis(java.lang.String label,
                     java.awt.Font labelFont,
                     java.awt.Paint labelPaint,
                     java.awt.Insets labelInsets,
                     boolean tickLabelsVisible,
                     java.awt.Font tickLabelFont,
                     java.awt.Paint tickLabelPaint,
                     java.awt.Insets tickLabelInsets,
                     boolean tickMarksVisible,
                     java.awt.Stroke tickMarkStroke,
                     boolean autoRange,
                     boolean autoRangeIncludesZero,
                     boolean autoRangeStickyZero,
                     java.lang.Number autoRangeMinimumSize,
                     double minimumAxisValue,
                     double maximumAxisValue,
                     boolean inverted,
                     boolean autoTickUnitSelection,
                     NumberTickUnit tickUnit,
                     boolean gridLinesVisible,
                     java.awt.Stroke gridStroke,
                     java.awt.Paint gridPaint,
                     boolean crosshairVisible,
                     double crosshairValue,
                     java.awt.Stroke crosshairStroke,
                     java.awt.Paint crosshairPaint)
Constructs a number axis.

Parameters:
label - The axis label.
labelFont - The font for displaying the axis label.
labelPaint - The paint used to display the axis label.
labelInsets - The amount of blank space around the axis label.
tickLabelsVisible - Flag indicating whether or not the tick labels are visible.
tickLabelFont - The font used to display the tick labels.
tickLabelPaint - The paint used to draw the tick labels.
tickLabelInsets - The amount of blank space around the tick labels.
tickMarksVisible - Flag indicating whether or not tick marks are visible;
tickMarkStroke - The stroke used to draw the tick marks (if visible);
autoRange - Flag indicating whether or not the axis range is automatically determined.
autoRangeIncludesZero - A flag indicating whether the auto range must include zero.
autoRangeStickyZero - A flag controlling the axis margins around zero.
autoRangeMinimumSize - The minimum size for the auto range.
minimumAxisValue - The lowest value shown on the axis.
maximumAxisValue - The highest value shown on the axis.
inverted - A flag indicating whether the axis is normal or inverted (inverted means running from positive to negative).
autoTickUnitSelection - A flag indicating whether or not the tick value is automatically selected.
tickUnit - The tick unit for the axis.
gridLinesVisible - Flag indicating whether or not grid lines are visible.
gridStroke - The pen/brush used to display grid lines (if visible).
gridPaint - The color used to display grid lines (if visible).
crosshairValue - The value at which to draw the crosshair line (null permitted).
crosshairStroke - The pen/brush used to draw the data line.
crosshairPaint - The color used to draw the data line.
Method Detail

isInverted

public boolean isInverted()
Returns a flag that controls the direction of values on the axis.

For a regular axis, values increase from left to right (for a horizontal axis) and bottom to top (for a vertical axis). When the axis is 'inverted', the values increase in the opposite direction.

Returns:
The flag.

setInverted

public void setInverted(boolean flag)
Sets a flag that controls the direction of values on the axis, and notifies registered listeners that the axis has changed.

Parameters:
flag - The flag.

autoRangeIncludesZero

public boolean autoRangeIncludesZero()
Returns the flag that indicates whether or not the automatic axis range (if indeed it is determined automatically) is forced to include zero.

Returns:
The flag.

setAutoRangeIncludesZero

public void setAutoRangeIncludesZero(boolean flag)
Sets the flag that indicates whether or not the automatic axis range is forced to include zero.

Parameters:
flag - The new value of the flag.

autoRangeStickyZero

public boolean autoRangeStickyZero()
Returns a flag that affects the auto-range when zero falls outside the data range but inside the margins defined for the axis.

Returns:
The flag.

setAutoRangeStickyZero

public void setAutoRangeStickyZero(boolean flag)
Sets a flag that affects the auto-range when zero falls outside the data range but inside the margins defined for the axis.

Parameters:
flag - The new flag.

getAutoRangeMinimumSize

public java.lang.Number getAutoRangeMinimumSize()
Returns the minimum size of the automatic axis range (if indeed it is determined automatically).

Returns:
The minimum range.

setAutoRangeMinimumSize

public void setAutoRangeMinimumSize(java.lang.Number size)
Sets the minimum size of the automatic axis range.

Parameters:
minimum - The new minimum.

getUpperMargin

public double getUpperMargin()
Returns the margin (as a percentage of the range) by which the maximum axis value exceeds the maximum data value.

Returns:
The upper margin.

setUpperMargin

public void setUpperMargin(double margin)
Sets the upper margin.

Parameters:
margin - The new margin.

getLowerMargin

public double getLowerMargin()
Returns the margin (as a percentage of the range) by which the minimum axis value is less than the minimum data value.

Returns:
The lower margin.

setLowerMargin

public void setLowerMargin(double margin)
Sets the lower margin.

Parameters:
margin - The new margin.

getStandardTickUnits

public TickUnits getStandardTickUnits()
Returns the standard tick units for the axis.

If autoTickUnitSelection is on, the tick unit for the axis will be automatically selected from this collection.

Returns:
The standard tick units.

setStandardTickUnits

public void setStandardTickUnits(TickUnits collection)
Sets the collection of tick units for the axis, and notifies registered listeners that the axis has changed.

If the autoTickUnitSelection flag is true, a tick unit will be selected from this collection automatically (to ensure that labels do not overlap).

Parameters:
collection - The tick unit collection.

getTickUnit

public NumberTickUnit getTickUnit()
Returns the tick unit for the axis.

Returns:
The tick unit for the axis.

setTickUnit

public void setTickUnit(NumberTickUnit unit)
Sets a fixed tick unit for the axis, and notifies registered listeners that the axis has been changed.

This method also sets the autoTickUnitSelection flag to false.

Parameters:
unit - The new tick unit.

calculateLowestVisibleTickValue

public double calculateLowestVisibleTickValue()
Calculates the value of the lowest visible tick on the axis.

Returns:
The value of the lowest visible tick on the axis.

calculateHighestVisibleTickValue

public double calculateHighestVisibleTickValue()
Calculates the value of the highest visible tick on the axis.

Returns:
The value of the highest visible tick on the axis.

calculateVisibleTickCount

public int calculateVisibleTickCount()
Calculates the number of visible ticks.

Returns:
The number of visible ticks on the axis.


Copyright © 2003 MBARI.

The Monterey Bay Aquarium Research Institute (MBARI) provides this documentation and code "as is", with no warranty, express or implied, of its quality or consistency. It is provided without support and without obligation on the part of MBARI to assist in its use, correction, modification, or enhancement.