com.jrefinery.chart
Class VerticalNumberAxis

java.lang.Object
  |
  +--com.jrefinery.chart.Axis
        |
        +--com.jrefinery.chart.ValueAxis
              |
              +--com.jrefinery.chart.NumberAxis
                    |
                    +--com.jrefinery.chart.VerticalNumberAxis
All Implemented Interfaces:
AxisConstants, VerticalAxis
Direct Known Subclasses:
VerticalLogarithmicAxis, VerticalNumberAxis3D, VerticalSymbolicAxis

public class VerticalNumberAxis
extends NumberAxis
implements VerticalAxis

A standard linear value axis, for values displayed vertically.

Note that bug 4273469 on the Java Developer Connection talks about why the grid lines don't always line up with the tick marks precisely.

Author:
DG

Fields inherited from class com.jrefinery.chart.NumberAxis
DEFAULT_AUTO_RANGE_INCLUDES_ZERO, DEFAULT_AUTO_RANGE_STICKY_ZERO, DEFAULT_TICK_UNIT
 
Fields inherited from class com.jrefinery.chart.ValueAxis
DEFAULT_AUTO_RANGE, DEFAULT_AUTO_RANGE_MINIMUM_SIZE, DEFAULT_CROSSHAIR_PAINT, DEFAULT_CROSSHAIR_STROKE, DEFAULT_CROSSHAIR_VISIBLE, DEFAULT_GRID_LINE_PAINT, DEFAULT_GRID_LINE_STROKE, DEFAULT_LOWER_BOUND, DEFAULT_LOWER_MARGIN, DEFAULT_RANGE, DEFAULT_UPPER_BOUND, DEFAULT_UPPER_MARGIN, MAXIMUM_TICK_COUNT
 
Fields inherited from class com.jrefinery.chart.Axis
fixedDimension, label, labelFont, labelInsets, labelPaint, plot, tickLabelFont, tickLabelInsets, tickLabelPaint, tickLabelsVisible, tickMarkPaint, 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_PAINT, DEFAULT_TICK_STROKE
 
Constructor Summary
VerticalNumberAxis()
          Constructs a vertical number axis, using default values where necessary.
VerticalNumberAxis(java.lang.String label)
          Constructs a vertical number axis, using default attribute values where necessary.
VerticalNumberAxis(java.lang.String label, java.awt.Font labelFont, double lowerBound, double upperBound)
          Constructs a vertical number axis, using default attribute values where necessary.
VerticalNumberAxis(java.lang.String label, java.awt.Font labelFont, java.awt.Paint labelPaint, java.awt.Insets labelInsets, boolean verticalLabel, boolean tickLabelsVisible, java.awt.Font tickLabelFont, java.awt.Paint tickLabelPaint, java.awt.Insets tickLabelInsets, boolean tickMarksVisible, java.awt.Stroke tickMarkStroke, java.awt.Paint tickMarkPaint, boolean autoRange, java.lang.Number autoRangeMinimumSize, boolean autoRangeIncludesZero, boolean autoRangeStickyZero, double lowerBound, double upperBound, boolean inverted, boolean autoTickUnitSelection, NumberTickUnit tickUnit, boolean gridLinesVisible, java.awt.Stroke gridStroke, java.awt.Paint gridPaint, double anchorValue, boolean crosshairVisible, double crosshairValue, java.awt.Stroke crosshairStroke, java.awt.Paint crosshairPaint)
          Constructs a new VerticalNumberAxis.
 
Method Summary
protected  void autoAdjustRange()
          Sets the axis minimum and maximum values so that all the data is visible.
 void configure()
          Configures the axis to work with the specified plot.
 void draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D drawArea, java.awt.geom.Rectangle2D dataArea)
          Draws the plot on a Java 2D graphics device (such as the screen or a printer).
protected  boolean isCompatiblePlot(Plot plot)
          Returns true if the specified plot is compatible with the axis.
 boolean isVerticalLabel()
          Returns a flag indicating whether or not the axis label is drawn vertically.
 void refreshTicks(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D drawArea, java.awt.geom.Rectangle2D plotArea)
          Calculates the positions of the tick labels for the axis, storing the results in the tick label list (ready for drawing).
 java.awt.geom.Rectangle2D reserveAxisArea(java.awt.Graphics2D g2, Plot plot, java.awt.geom.Rectangle2D drawArea, double reservedHeight)
          Returns area in which the axis will be displayed.
 double reserveWidth(java.awt.Graphics2D g2, Plot plot, java.awt.geom.Rectangle2D drawArea)
          Returns the width required to draw the axis in the specified draw area.
protected  void selectAutoTickUnit(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D drawArea, java.awt.geom.Rectangle2D plotArea)
          Selects an appropriate tick value for the axis.
 void setVerticalLabel(boolean flag)
          Sets a flag indicating whether or not the axis label is drawn vertically.
 double translateJava2DtoValue(float java2DValue, java.awt.geom.Rectangle2D dataArea)
          Converts a coordinate in Java2D space to the corresponding data value, assuming that the axis runs along one edge of the specified dataArea.
 double translateValueToJava2D(double value, java.awt.geom.Rectangle2D dataArea)
          Converts a data value to a coordinate in Java2D space, assuming that the axis runs along one edge of the specified dataArea.
 
Methods inherited from class com.jrefinery.chart.NumberAxis
autoRangeIncludesZero, autoRangeStickyZero, calculateHighestVisibleTickValue, calculateLowestVisibleTickValue, calculateVisibleTickCount, createIntegerTickUnits, createIntegerTickUnits, createStandardTickUnits, createStandardTickUnits, getTickUnit, isInverted, setAutoRangeIncludesZero, setAutoRangeStickyZero, setInverted, setTickUnit, setTickUnitAttribute
 
Methods inherited from class com.jrefinery.chart.ValueAxis
centerRange, getAnchorValue, getAutoRangeMinimumSize, getAutoTickIndex, getCrosshairPaint, getCrosshairStroke, getCrosshairValue, getFixedAutoRange, getGridPaint, getGridStroke, getLowerMargin, getMaximumAxisValue, getMinimumAxisValue, getRange, getStandardTickUnits, getUpperMargin, isAutoRange, isAutoTickUnitSelection, isCrosshairLockedOnData, isCrosshairVisible, isGridLinesVisible, resizeRange, resizeRange, setAnchoredRange, setAnchorValue, setAnchorValueAttribute, setAutoRange, setAutoRangeAttribute, setAutoRangeMinimumSize, setAutoRangeMinimumSizeAttribute, setAutoTickIndex, setAutoTickUnitSelection, setAutoTickUnitSelectionAttribute, setCrosshairLockedOnData, setCrosshairPaint, setCrosshairStroke, setCrosshairValue, setCrosshairValue, setCrosshairValueAttribute, setCrosshairVisible, setFixedAutoRange, setGridLinesVisible, setGridPaint, setGridStroke, setLowerMargin, setMaximumAxisValue, setMinimumAxisValue, setRange, setRange, setRangeAboutValue, setRangeAttribute, setStandardTickUnits, setUpperMargin
 
Methods inherited from class com.jrefinery.chart.Axis
addChangeListener, getFixedDimension, getLabel, getLabelFont, getLabelInsets, getLabelPaint, getMaxTickLabelWidth, getPlot, getTickLabelFont, getTickLabelInsets, getTickLabelPaint, getTickMarkPaint, getTickMarkStroke, isTickLabelsVisible, isTickMarksVisible, isVisible, notifyListeners, removeChangeListener, setFixedDimension, setLabel, setLabelFont, setLabelInsets, setLabelPaint, setPlot, setTickLabelFont, setTickLabelInsets, setTickLabelPaint, setTickLabelsVisible, setTickMarkPaint, setTickMarkStroke, setTickMarksVisible, setVisible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VerticalNumberAxis

public VerticalNumberAxis()
Constructs a vertical number axis, using default values where necessary.

VerticalNumberAxis

public VerticalNumberAxis(java.lang.String label)
Constructs a vertical number axis, using default attribute values where necessary.
Parameters:
label - the axis label (null permitted).

VerticalNumberAxis

public VerticalNumberAxis(java.lang.String label,
                          java.awt.Font labelFont,
                          double lowerBound,
                          double upperBound)
Constructs a vertical number axis, using default attribute values where necessary.
Parameters:
label - the axis label (null permitted).
labelFont - the font for displaying the axis label.
lowerBound - the lowest value shown on the axis.
upperBound - the highest value shown on the axis.

VerticalNumberAxis

public VerticalNumberAxis(java.lang.String label,
                          java.awt.Font labelFont,
                          java.awt.Paint labelPaint,
                          java.awt.Insets labelInsets,
                          boolean verticalLabel,
                          boolean tickLabelsVisible,
                          java.awt.Font tickLabelFont,
                          java.awt.Paint tickLabelPaint,
                          java.awt.Insets tickLabelInsets,
                          boolean tickMarksVisible,
                          java.awt.Stroke tickMarkStroke,
                          java.awt.Paint tickMarkPaint,
                          boolean autoRange,
                          java.lang.Number autoRangeMinimumSize,
                          boolean autoRangeIncludesZero,
                          boolean autoRangeStickyZero,
                          double lowerBound,
                          double upperBound,
                          boolean inverted,
                          boolean autoTickUnitSelection,
                          NumberTickUnit tickUnit,
                          boolean gridLinesVisible,
                          java.awt.Stroke gridStroke,
                          java.awt.Paint gridPaint,
                          double anchorValue,
                          boolean crosshairVisible,
                          double crosshairValue,
                          java.awt.Stroke crosshairStroke,
                          java.awt.Paint crosshairPaint)
Constructs a new VerticalNumberAxis.
Parameters:
label - the axis label.
labelFont - the font for displaying the axis label.
labelPaint - the paint used to draw the axis label.
labelInsets - determines the amount of blank space around the label.
verticalLabel - flag indicating whether or not the label is drawn vertically.
tickLabelsVisible - flag indicating whether or not tick labels are visible.
tickLabelFont - the font used to display tick labels.
tickLabelPaint - the paint used to draw tick labels.
tickLabelInsets - determines the amount of blank space around tick labels.
tickMarksVisible - flag indicating whether or not tick marks are visible.
tickMarkStroke - the stroke used to draw tick marks (if visible).
tickMarkPaint - the paint used to draw tick marks (if visible).
autoRange - flag indicating whether or not the axis is automatically scaled to fit the data.
autoRangeMinimumSize - the smallest range allowed when the axis range is calculated to fit the data.
autoRangeIncludesZero - a flag indicating whether or not zero *must* be displayed on axis.
autoRangeStickyZero - a flag controlling the axis margins around zero.
lowerBound - the lowest value shown on the axis.
upperBound - 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 units are selected automatically.
tickUnit - the tick unit.
gridLinesVisible - flag indicating whether or not grid lines are visible for this axis.
gridStroke - the pen/brush used to display grid lines (if visible).
gridPaint - the color used to display grid lines (if visible).
anchorValue - the anchor value.
crosshairVisible - whether to show a crosshair.
crosshairValue - the value at which to draw an optional crosshair (null permitted).
crosshairStroke - the pen/brush used to draw the crosshair.
crosshairPaint - the color used to draw the crosshair.
Method Detail

isVerticalLabel

public boolean isVerticalLabel()
Returns a flag indicating whether or not the axis label is drawn vertically.
Returns:
the flag.

setVerticalLabel

public void setVerticalLabel(boolean flag)
Sets a flag indicating whether or not the axis label is drawn vertically. If the setting is changed, registered listeners are notified that the axis has changed.
Parameters:
flag - the new flag.

configure

public void configure()
Configures the axis to work with the specified plot. If the axis has auto-scaling, then sets the maximum and minimum values.
Overrides:
configure in class Axis

translateValueToJava2D

public double translateValueToJava2D(double value,
                                     java.awt.geom.Rectangle2D dataArea)
Converts a data value to a coordinate in Java2D space, assuming that the axis runs along one edge of the specified dataArea.

Note that it is possible for the coordinate to fall outside the plotArea.

Overrides:
translateValueToJava2D in class ValueAxis
Parameters:
value - the data value.
dataArea - the area for plotting the data.
Returns:
The Java2D coordinate.

translateJava2DtoValue

public double translateJava2DtoValue(float java2DValue,
                                     java.awt.geom.Rectangle2D dataArea)
Converts a coordinate in Java2D space to the corresponding data value, assuming that the axis runs along one edge of the specified dataArea.
Overrides:
translateJava2DtoValue in class ValueAxis
Parameters:
java2DValue - the coordinate in Java2D space.
dataArea - the area in which the data is plotted.
Returns:
The data value.

autoAdjustRange

protected void autoAdjustRange()
Sets the axis minimum and maximum values so that all the data is visible.

You can control the range calculation in several ways. First, you can define upper and lower margins as a percentage of the data range (the default is a 5% margin for each). Second, you can set a flag that forces the range to include zero. Finally, you can set another flag, the 'sticky zero' flag, that only affects the range when zero falls within the axis margins. When this happens, the margin is truncated so that zero is the upper or lower limit for the axis.

Overrides:
autoAdjustRange in class ValueAxis

draw

public void draw(java.awt.Graphics2D g2,
                 java.awt.geom.Rectangle2D drawArea,
                 java.awt.geom.Rectangle2D dataArea)
Draws the plot on a Java 2D graphics device (such as the screen or a printer).
Overrides:
draw in class Axis
Parameters:
g2 - the graphics device.
drawArea - the area within which the chart should be drawn.
dataArea - the area within which the plot should be drawn (a subset of the drawArea).

reserveWidth

public double reserveWidth(java.awt.Graphics2D g2,
                           Plot plot,
                           java.awt.geom.Rectangle2D drawArea)
Returns the width required to draw the axis in the specified draw area.
Specified by:
reserveWidth in interface VerticalAxis
Parameters:
g2 - the graphics device.
plot - a reference to the plot;
drawArea - the area within which the plot should be drawn.
Returns:
width required to draw the axis.

reserveAxisArea

public java.awt.geom.Rectangle2D reserveAxisArea(java.awt.Graphics2D g2,
                                                 Plot plot,
                                                 java.awt.geom.Rectangle2D drawArea,
                                                 double reservedHeight)
Returns area in which the axis will be displayed.
Specified by:
reserveAxisArea in interface VerticalAxis
Parameters:
g2 - the graphics device.
plot - a reference to the plot.
drawArea - the area in which the plot and axes should be drawn.
reservedHeight - the height reserved for the horizontal axis.
Returns:
area in which the axis will be displayed.

selectAutoTickUnit

protected void selectAutoTickUnit(java.awt.Graphics2D g2,
                                  java.awt.geom.Rectangle2D drawArea,
                                  java.awt.geom.Rectangle2D plotArea)
Selects an appropriate tick value for the axis. The strategy is to display as many ticks as possible (selected from an array of 'standard' tick units) without the labels overlapping.
Parameters:
g2 - the graphics device.
drawArea - the area in which the plot and axes should be drawn.
plotArea - the area in which the plot should be drawn.

refreshTicks

public void refreshTicks(java.awt.Graphics2D g2,
                         java.awt.geom.Rectangle2D drawArea,
                         java.awt.geom.Rectangle2D plotArea)
Calculates the positions of the tick labels for the axis, storing the results in the tick label list (ready for drawing).
Overrides:
refreshTicks in class Axis
Parameters:
g2 - the graphics device.
drawArea - the area in which the plot and the axes should be drawn.
plotArea - the area in which the plot should be drawn.

isCompatiblePlot

protected boolean isCompatiblePlot(Plot plot)
Returns true if the specified plot is compatible with the axis.

This class (VerticalNumberAxis) requires that the plot implements the VerticalValuePlot interface.

Overrides:
isCompatiblePlot in class Axis
Parameters:
plot - The plot.
Returns:
true if the specified plot is compatible with the axis.