org.jfree.chart.axis
Class CategoryAxis

java.lang.Object
  extended byorg.jfree.chart.axis.Axis
      extended byorg.jfree.chart.axis.CategoryAxis
All Implemented Interfaces:
AxisConstants, java.lang.Cloneable, java.io.Serializable
Direct Known Subclasses:
CategoryAxis3D, ExtendedCategoryAxis

public class CategoryAxis
extends Axis
implements java.lang.Cloneable, java.io.Serializable

An axis that displays categories.

Author:
David Gilbert
See Also:
Serialized Form

Field Summary
static double DEFAULT_AXIS_MARGIN
          The default margin for the axis (used for both lower and upper margins).
static double DEFAULT_CATEGORY_MARGIN
          The default margin between categories (a percentage of the overall axis length).
 
Fields inherited from interface org.jfree.chart.axis.AxisConstants
DEFAULT_AXIS_LABEL_FONT, DEFAULT_AXIS_LABEL_INSETS, DEFAULT_AXIS_LABEL_PAINT, DEFAULT_AXIS_LINE_PAINT, DEFAULT_AXIS_LINE_STROKE, DEFAULT_AXIS_VISIBLE, DEFAULT_TICK_LABEL_FONT, DEFAULT_TICK_LABEL_INSETS, DEFAULT_TICK_LABEL_PAINT, DEFAULT_TICK_LABELS_VISIBLE, DEFAULT_TICK_MARK_INSIDE_LENGTH, DEFAULT_TICK_MARK_OUTSIDE_LENGTH, DEFAULT_TICK_MARK_PAINT, DEFAULT_TICK_MARK_STROKE, DEFAULT_TICK_MARKS_VISIBLE
 
Constructor Summary
CategoryAxis(java.lang.String label)
          Constructs a category axis, using default values where necessary.
 
Method Summary
protected  double calculateCategoryGapSize(int categoryCount, java.awt.geom.Rectangle2D area, org.jfree.ui.RectangleEdge edge)
          Calculates the size (width or height, depending on the location of the axis) of a category gap.
protected  double calculateCategorySize(int categoryCount, java.awt.geom.Rectangle2D area, org.jfree.ui.RectangleEdge edge)
          Calculates the size (width or height, depending on the location of the axis) of a category.
protected  double calculateTextBlockHeight(org.jfree.text.TextBlock block, CategoryLabelPosition position, java.awt.Graphics2D g2)
          A utility method for determining the height of a text block.
protected  double calculateTextBlockWidth(org.jfree.text.TextBlock block, CategoryLabelPosition position, java.awt.Graphics2D g2)
          A utility method for determining the width of a text block.
 java.lang.Object clone()
          Creates a clone of the axis.
 void configure()
          Configures the axis against the current plot.
protected  org.jfree.text.TextBlock createLabel(java.lang.Comparable category, float width, org.jfree.ui.RectangleEdge edge, java.awt.Graphics2D g2)
          Creates a label.
 AxisState draw(java.awt.Graphics2D g2, double cursor, java.awt.geom.Rectangle2D plotArea, java.awt.geom.Rectangle2D dataArea, org.jfree.ui.RectangleEdge edge)
          Draws the axis on a Java 2D graphics device (such as the screen or a printer).
protected  AxisState drawCategoryLabels(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D plotArea, java.awt.geom.Rectangle2D dataArea, org.jfree.ui.RectangleEdge edge, AxisState state)
          Draws the category labels when the axis is 'horizontal'.
 boolean equals(java.lang.Object obj)
          Tests this axis for equality with another object.
 CategoryLabelPosition getBottomCategoryLabelPosition()
          Deprecated. Use getCategoryLabelPositions().getLabelPosition(RectangleEdge.BOTTOM).
 double getCategoryEnd(int category, int categoryCount, java.awt.geom.Rectangle2D area, org.jfree.ui.RectangleEdge edge)
          Returns the end coordinate for the specified category.
 double getCategoryJava2DCoordinate(CategoryAnchor anchor, int category, int categoryCount, java.awt.geom.Rectangle2D area, org.jfree.ui.RectangleEdge edge)
          Returns the Java 2D coordinate for a category.
 int getCategoryLabelPositionOffset()
          Returns the offset between the axis and the category labels (before label positioning is taken into account).
 CategoryLabelPositions getCategoryLabelPositions()
          Returns the category label position specification (this contains label positioning info for all four possible axis locations).
 double getCategoryMargin()
          Returns the category margin.
 double getCategoryMiddle(int category, int categoryCount, java.awt.geom.Rectangle2D area, org.jfree.ui.RectangleEdge edge)
          Returns the middle coordinate for the specified category.
 double getCategoryStart(int category, int categoryCount, java.awt.geom.Rectangle2D area, org.jfree.ui.RectangleEdge edge)
          Returns the starting coordinate for the specified category.
 CategoryLabelPosition getLeftCategoryLabelPosition()
          Deprecated. Use getCategoryLabelPositions().getLabelPosition(RectangleEdge.LEFT).
 double getLowerMargin()
          Returns the lower margin for the axis.
 float getMaxCategoryLabelWidthRatio()
          Returns the category label width ratio.
 CategoryLabelPosition getRightCategoryLabelPosition()
          Deprecated. Use getCategoryLabelPositions().getLabelPosition(RectangleEdge.RIGHT).
 boolean getSkipCategoryLabelsToFit()
          Deprecated. No longer supported.
 CategoryLabelPosition getTopCategoryLabelPosition()
          Deprecated. Use getCategoryLabelPositions().getLabelPosition(RectangleEdge.TOP).
 double getUpperMargin()
          Returns the upper margin for the axis.
 boolean isVerticalCategoryLabels()
          Deprecated. Use the get/setXXXCategoryLabelPosition methods.
 java.util.List refreshTicks(java.awt.Graphics2D g2, AxisState state, java.awt.geom.Rectangle2D plotArea, java.awt.geom.Rectangle2D dataArea, org.jfree.ui.RectangleEdge edge)
          Creates a temporary list of ticks that can be used when drawing the axis.
 AxisSpace reserveSpace(java.awt.Graphics2D g2, Plot plot, java.awt.geom.Rectangle2D plotArea, org.jfree.ui.RectangleEdge edge, AxisSpace space)
          Estimates the space required for the axis, given a specific drawing area.
 void setBottomCategoryLabelPosition(CategoryLabelPosition position)
          Deprecated. Use setCategoryLabelPositions(...).
 void setCategoryLabelPositionOffset(int offset)
          Sets the offset between the axis and the category labels (before label positioning is taken into account).
 void setCategoryLabelPositions(CategoryLabelPositions positions)
          Sets the category label position specification for the axis.
 void setCategoryMargin(double margin)
          Sets the category margin.
 void setLeftCategoryLabelPosition(CategoryLabelPosition position)
          Deprecated. Use setCategoryLabelPositions(...).
 void setLowerMargin(double margin)
          Sets the lower margin for the axis.
 void setMaxCategoryLabelWidthRatio(float ratio)
          Sets the maximum category label width ratio.
 void setRightCategoryLabelPosition(CategoryLabelPosition position)
          Deprecated. Use setLabelPositions(...).
 void setSkipCategoryLabelsToFit(boolean flag)
          Deprecated. No longer supported.
 void setTopCategoryLabelPosition(CategoryLabelPosition position)
          Deprecated. Use setCategoryLabelPositions(...).
 void setUpperMargin(double margin)
          Sets the upper margin for the axis.
 void setVerticalCategoryLabels(boolean flag)
          Deprecated. Use the get/setXXXCategoryLabelPosition methods.
 
Methods inherited from class org.jfree.chart.axis.Axis
addChangeListener, drawAxisLine, drawLabel, getAxisLinePaint, getAxisLineStroke, getFixedDimension, getLabel, getLabelAngle, getLabelEnclosure, getLabelFont, getLabelInsets, getLabelPaint, getPlot, getTickLabelFont, getTickLabelInsets, getTickLabelPaint, getTickMarkInsideLength, getTickMarkOutsideLength, getTickMarkPaint, getTickMarkStroke, isAxisLineVisible, isTickLabelsVisible, isTickMarksVisible, isVisible, notifyListeners, removeChangeListener, setAxisLinePaint, setAxisLineStroke, setAxisLineVisible, setFixedDimension, setLabel, setLabelAngle, setLabelFont, setLabelInsets, setLabelPaint, setPlot, setTickLabelFont, setTickLabelInsets, setTickLabelPaint, setTickLabelsVisible, setTickMarkInsideLength, setTickMarkOutsideLength, setTickMarkPaint, setTickMarkStroke, setTickMarksVisible, setVisible
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_AXIS_MARGIN

public static final double DEFAULT_AXIS_MARGIN
The default margin for the axis (used for both lower and upper margins).

See Also:
Constant Field Values

DEFAULT_CATEGORY_MARGIN

public static final double DEFAULT_CATEGORY_MARGIN
The default margin between categories (a percentage of the overall axis length).

See Also:
Constant Field Values
Constructor Detail

CategoryAxis

public CategoryAxis(java.lang.String label)
Constructs a category axis, using default values where necessary.

Parameters:
label - the axis label (null permitted).
Method Detail

getLowerMargin

public double getLowerMargin()
Returns the lower margin for the axis.

Returns:
the margin.

setLowerMargin

public void setLowerMargin(double margin)
Sets the lower margin for the axis. An AxisChangeEvent is sent to all registered listeners.

Parameters:
margin - the margin (a percentage of the axis length).

getUpperMargin

public double getUpperMargin()
Returns the upper margin for the axis.

Returns:
the margin.

setUpperMargin

public void setUpperMargin(double margin)
Sets the upper margin for the axis. An AxisChangeEvent is sent to all registered listeners.

Parameters:
margin - the margin (a percentage of the axis length).

getCategoryMargin

public double getCategoryMargin()
Returns the category margin.

Returns:
the margin.

setCategoryMargin

public void setCategoryMargin(double margin)
Sets the category margin. An AxisChangeEvent is sent to all registered listeners.

The overall category margin is distributed over N-1 gaps, where N is the number of categories on the axis.

Parameters:
margin - the margin (a percentage of the axis length).

getMaxCategoryLabelWidthRatio

public float getMaxCategoryLabelWidthRatio()
Returns the category label width ratio.

Returns:
The category label width ratio.

setMaxCategoryLabelWidthRatio

public void setMaxCategoryLabelWidthRatio(float ratio)
Sets the maximum category label width ratio.

Parameters:
ratio - the ratio.

getCategoryLabelPositionOffset

public int getCategoryLabelPositionOffset()
Returns the offset between the axis and the category labels (before label positioning is taken into account).

Returns:
the offset.

setCategoryLabelPositionOffset

public void setCategoryLabelPositionOffset(int offset)
Sets the offset between the axis and the category labels (before label positioning is taken into account).

Parameters:
offset - the offset.

getCategoryLabelPositions

public CategoryLabelPositions getCategoryLabelPositions()
Returns the category label position specification (this contains label positioning info for all four possible axis locations).

Returns:
The category label position specification.

setCategoryLabelPositions

public void setCategoryLabelPositions(CategoryLabelPositions positions)
Sets the category label position specification for the axis.

Parameters:
positions - the category label position specification.

getTopCategoryLabelPosition

public CategoryLabelPosition getTopCategoryLabelPosition()
Deprecated. Use getCategoryLabelPositions().getLabelPosition(RectangleEdge.TOP).

Returns the category label positioning info that applies when the axis is displayed at the top of the plot area.

Returns:
the position info.

setTopCategoryLabelPosition

public void setTopCategoryLabelPosition(CategoryLabelPosition position)
Deprecated. Use setCategoryLabelPositions(...).

Sets the position info that applies when the axis is displayed at the top of the plot area.

Parameters:
position - the position info.

getBottomCategoryLabelPosition

public CategoryLabelPosition getBottomCategoryLabelPosition()
Deprecated. Use getCategoryLabelPositions().getLabelPosition(RectangleEdge.BOTTOM).

Returns the category label positioning info that applies when the axis is displayed at the bottom of the plot area.

Returns:
the position info.

setBottomCategoryLabelPosition

public void setBottomCategoryLabelPosition(CategoryLabelPosition position)
Deprecated. Use setCategoryLabelPositions(...).

Sets the position info that applies when the axis is displayed at the bottom of the plot area.

Parameters:
position - the position info.

getLeftCategoryLabelPosition

public CategoryLabelPosition getLeftCategoryLabelPosition()
Deprecated. Use getCategoryLabelPositions().getLabelPosition(RectangleEdge.LEFT).

Returns the category label positioning info that applies when the axis is displayed at the left of the plot area.

Returns:
the position info.

setLeftCategoryLabelPosition

public void setLeftCategoryLabelPosition(CategoryLabelPosition position)
Deprecated. Use setCategoryLabelPositions(...).

Sets the position info that applies when the axis is displayed at the left of the plot area.

Parameters:
position - the position info.

getRightCategoryLabelPosition

public CategoryLabelPosition getRightCategoryLabelPosition()
Deprecated. Use getCategoryLabelPositions().getLabelPosition(RectangleEdge.RIGHT).

Returns the category label positioning info that applies when the axis is displayed at the right of the plot area.

Returns:
the position info.

setRightCategoryLabelPosition

public void setRightCategoryLabelPosition(CategoryLabelPosition position)
Deprecated. Use setLabelPositions(...).

Sets the position info that applies when the axis is displayed at the right of the plot area.

Parameters:
position - the position info.

getCategoryJava2DCoordinate

public double getCategoryJava2DCoordinate(CategoryAnchor anchor,
                                          int category,
                                          int categoryCount,
                                          java.awt.geom.Rectangle2D area,
                                          org.jfree.ui.RectangleEdge edge)
Returns the Java 2D coordinate for a category.

Parameters:
anchor - the anchor point.
category - the category index.
categoryCount - the category count.
area - the data area.
edge - the location of the axis.
Returns:
The coordinate.

getCategoryStart

public double getCategoryStart(int category,
                               int categoryCount,
                               java.awt.geom.Rectangle2D area,
                               org.jfree.ui.RectangleEdge edge)
Returns the starting coordinate for the specified category.

Parameters:
category - the category.
categoryCount - the number of categories.
area - the data area.
edge - the axis location.
Returns:
the coordinate.

getCategoryMiddle

public double getCategoryMiddle(int category,
                                int categoryCount,
                                java.awt.geom.Rectangle2D area,
                                org.jfree.ui.RectangleEdge edge)
Returns the middle coordinate for the specified category.

Parameters:
category - the category.
categoryCount - the number of categories.
area - the data area.
edge - the axis location.
Returns:
the coordinate.

getCategoryEnd

public double getCategoryEnd(int category,
                             int categoryCount,
                             java.awt.geom.Rectangle2D area,
                             org.jfree.ui.RectangleEdge edge)
Returns the end coordinate for the specified category.

Parameters:
category - the category.
categoryCount - the number of categories.
area - the data area.
edge - the axis location.
Returns:
the coordinate.

calculateCategorySize

protected double calculateCategorySize(int categoryCount,
                                       java.awt.geom.Rectangle2D area,
                                       org.jfree.ui.RectangleEdge edge)
Calculates the size (width or height, depending on the location of the axis) of a category.

Parameters:
categoryCount - the number of categories.
area - the area within which the categories will be drawn.
edge - the axis location.
Returns:
the category size.

calculateCategoryGapSize

protected double calculateCategoryGapSize(int categoryCount,
                                          java.awt.geom.Rectangle2D area,
                                          org.jfree.ui.RectangleEdge edge)
Calculates the size (width or height, depending on the location of the axis) of a category gap.

Parameters:
categoryCount - the number of categories.
area - the area within which the categories will be drawn.
edge - the axis location.
Returns:
the category gap width.

reserveSpace

public AxisSpace reserveSpace(java.awt.Graphics2D g2,
                              Plot plot,
                              java.awt.geom.Rectangle2D plotArea,
                              org.jfree.ui.RectangleEdge edge,
                              AxisSpace space)
Estimates the space required for the axis, given a specific drawing area.

Specified by:
reserveSpace in class Axis
Parameters:
g2 - the graphics device (used to obtain font information).
plot - the plot that the axis belongs to.
plotArea - the area within which the axis should be drawn.
edge - the axis location (top or bottom).
space - the space already reserved.
Returns:
the estimated height required for the axis.

configure

public void configure()
Configures the axis against the current plot. Nothing required in this class.

Specified by:
configure in class Axis

draw

public AxisState draw(java.awt.Graphics2D g2,
                      double cursor,
                      java.awt.geom.Rectangle2D plotArea,
                      java.awt.geom.Rectangle2D dataArea,
                      org.jfree.ui.RectangleEdge edge)
Draws the axis on a Java 2D graphics device (such as the screen or a printer).

Specified by:
draw in class Axis
Parameters:
g2 - the graphics device.
cursor - the cursor location.
plotArea - the area within which the axis should be drawn.
dataArea - the area within which the plot is being drawn.
edge - the location of the axis.
Returns:
The new cursor location.

drawCategoryLabels

protected AxisState drawCategoryLabels(java.awt.Graphics2D g2,
                                       java.awt.geom.Rectangle2D plotArea,
                                       java.awt.geom.Rectangle2D dataArea,
                                       org.jfree.ui.RectangleEdge edge,
                                       AxisState state)
Draws the category labels when the axis is 'horizontal'.

Parameters:
g2 - the graphics device.
plotArea - the plot area.
dataArea - the area inside the axes.
edge - the axis location.
state - the axis state.
Returns:
The revised axis state.

refreshTicks

public java.util.List refreshTicks(java.awt.Graphics2D g2,
                                   AxisState state,
                                   java.awt.geom.Rectangle2D plotArea,
                                   java.awt.geom.Rectangle2D dataArea,
                                   org.jfree.ui.RectangleEdge edge)
Creates a temporary list of ticks that can be used when drawing the axis.

Specified by:
refreshTicks in class Axis
Parameters:
g2 - the graphics device (used to get font measurements).
state - the axis state.
plotArea - the area where the plot and axes will be drawn.
dataArea - the area inside the axes.
edge - the location of the axis.
Returns:
A list of ticks.

createLabel

protected org.jfree.text.TextBlock createLabel(java.lang.Comparable category,
                                               float width,
                                               org.jfree.ui.RectangleEdge edge,
                                               java.awt.Graphics2D g2)
Creates a label.

Parameters:
category - the category.
width - the available width.
edge - the edge on which the axis appears.
g2 - the graphics device.
Returns:
a label.

calculateTextBlockWidth

protected double calculateTextBlockWidth(org.jfree.text.TextBlock block,
                                         CategoryLabelPosition position,
                                         java.awt.Graphics2D g2)
A utility method for determining the width of a text block.

Parameters:
block - the text block.
position - the position.
g2 - the graphics device.
Returns:
the width.

calculateTextBlockHeight

protected double calculateTextBlockHeight(org.jfree.text.TextBlock block,
                                          CategoryLabelPosition position,
                                          java.awt.Graphics2D g2)
A utility method for determining the height of a text block.

Parameters:
block - the text block.
position - the label position.
g2 - the graphics device.
Returns:
the height.

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Creates a clone of the axis.

Overrides:
clone in class Axis
Returns:
A clone.
Throws:
java.lang.CloneNotSupportedException - if some component of the axis does not support cloning.

equals

public boolean equals(java.lang.Object obj)
Tests this axis for equality with another object.

Overrides:
equals in class Axis
Parameters:
obj - the object.
Returns:
true or false.

isVerticalCategoryLabels

public boolean isVerticalCategoryLabels()
Deprecated. Use the get/setXXXCategoryLabelPosition methods.

Returns a flag indicating whether the category labels are rotated to vertical.

Returns:
The flag.

setVerticalCategoryLabels

public void setVerticalCategoryLabels(boolean flag)
Deprecated. Use the get/setXXXCategoryLabelPosition methods.

Sets the flag that determines whether the category labels are rotated to vertical.

Parameters:
flag - the flag.

getSkipCategoryLabelsToFit

public boolean getSkipCategoryLabelsToFit()
Deprecated. No longer supported.

Returns the flag that determines whether the category labels are to be skipped to avoid overlapping.

Returns:
The flag.

setSkipCategoryLabelsToFit

public void setSkipCategoryLabelsToFit(boolean flag)
Deprecated. No longer supported.

Sets the flag that determines whether the category labels are to be skipped to avoid overlapping.

Parameters:
flag - the new value of the flag.