org.jfree.chart.axis

Class CategoryAxis

public class CategoryAxis extends Axis implements Cloneable, Serializable

An axis that displays categories.
Field Summary
static doubleDEFAULT_AXIS_MARGIN
The default margin for the axis (used for both lower and upper margins).
static doubleDEFAULT_CATEGORY_MARGIN
The default margin between categories (a percentage of the overall axis length).
Constructor Summary
CategoryAxis()
Creates a new category axis with no label.
CategoryAxis(String label)
Constructs a category axis, using default values where necessary.
Method Summary
voidaddCategoryLabelToolTip(Comparable category, String tooltip)
Adds a tooltip to the specified category and sends an AxisChangeEvent to all registered listeners.
protected doublecalculateCategoryGapSize(int categoryCount, Rectangle2D area, RectangleEdge edge)
Calculates the size (width or height, depending on the location of the axis) of a category gap.
protected doublecalculateCategorySize(int categoryCount, Rectangle2D area, RectangleEdge edge)
Calculates the size (width or height, depending on the location of the axis) of a category.
protected doublecalculateTextBlockHeight(TextBlock block, CategoryLabelPosition position, Graphics2D g2)
A utility method for determining the height of a text block.
protected doublecalculateTextBlockWidth(TextBlock block, CategoryLabelPosition position, Graphics2D g2)
A utility method for determining the width of a text block.
voidclearCategoryLabelToolTips()
Clears the category label tooltips and sends an AxisChangeEvent to all registered listeners.
Objectclone()
Creates a clone of the axis.
voidconfigure()
Configures the axis against the current plot.
protected TextBlockcreateLabel(Comparable category, float width, RectangleEdge edge, Graphics2D g2)
Creates a label.
AxisStatedraw(Graphics2D g2, double cursor, Rectangle2D plotArea, Rectangle2D dataArea, RectangleEdge edge, PlotRenderingInfo plotState)
Draws the axis on a Java 2D graphics device (such as the screen or a printer).
protected AxisStatedrawCategoryLabels(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge, AxisState state, PlotRenderingInfo plotState)
Draws the category labels and returns the updated axis state.
protected AxisStatedrawCategoryLabels(Graphics2D g2, Rectangle2D plotArea, Rectangle2D dataArea, RectangleEdge edge, AxisState state, PlotRenderingInfo plotState)
Draws the category labels and returns the updated axis state.
booleanequals(Object obj)
Tests this axis for equality with an arbitrary object.
doublegetCategoryEnd(int category, int categoryCount, Rectangle2D area, RectangleEdge edge)
Returns the end coordinate for the specified category.
doublegetCategoryJava2DCoordinate(CategoryAnchor anchor, int category, int categoryCount, Rectangle2D area, RectangleEdge edge)
Returns the Java 2D coordinate for a category.
intgetCategoryLabelPositionOffset()
Returns the offset between the axis and the category labels (before label positioning is taken into account).
CategoryLabelPositionsgetCategoryLabelPositions()
Returns the category label position specification (this contains label positioning info for all four possible axis locations).
StringgetCategoryLabelToolTip(Comparable category)
Returns the tool tip text for the label belonging to the specified category.
doublegetCategoryMargin()
Returns the category margin.
doublegetCategoryMiddle(int category, int categoryCount, Rectangle2D area, RectangleEdge edge)
Returns the middle coordinate for the specified category.
doublegetCategoryStart(int category, int categoryCount, Rectangle2D area, RectangleEdge edge)
Returns the starting coordinate for the specified category.
doublegetLowerMargin()
Returns the lower margin for the axis.
intgetMaximumCategoryLabelLines()
Returns the maximum number of lines to use for each category label.
floatgetMaximumCategoryLabelWidthRatio()
Returns the category label width ratio.
FontgetTickLabelFont(Comparable category)
Returns the font for the tick label for the given category.
PaintgetTickLabelPaint(Comparable category)
Returns the paint for the tick label for the given category.
doublegetUpperMargin()
Returns the upper margin for the axis.
inthashCode()
Returns a hash code for this object.
ListrefreshTicks(Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge)
Creates a temporary list of ticks that can be used when drawing the axis.
voidremoveCategoryLabelToolTip(Comparable category)
Removes the tooltip for the specified category and sends an AxisChangeEvent to all registered listeners.
AxisSpacereserveSpace(Graphics2D g2, Plot plot, Rectangle2D plotArea, RectangleEdge edge, AxisSpace space)
Estimates the space required for the axis, given a specific drawing area.
voidsetCategoryLabelPositionOffset(int offset)
Sets the offset between the axis and the category labels (before label positioning is taken into account).
voidsetCategoryLabelPositions(CategoryLabelPositions positions)
Sets the category label position specification for the axis and sends an AxisChangeEvent to all registered listeners.
voidsetCategoryMargin(double margin)
Sets the category margin and sends an AxisChangeEvent to all registered listeners.
voidsetLowerMargin(double margin)
Sets the lower margin for the axis and sends an AxisChangeEvent to all registered listeners.
voidsetMaximumCategoryLabelLines(int lines)
Sets the maximum number of lines to use for each category label and sends an AxisChangeEvent to all registered listeners.
voidsetMaximumCategoryLabelWidthRatio(float ratio)
Sets the maximum category label width ratio and sends an AxisChangeEvent to all registered listeners.
voidsetTickLabelFont(Comparable category, Font font)
Sets the font for the tick label for the specified category and sends an AxisChangeEvent to all registered listeners.
voidsetTickLabelPaint(Comparable category, Paint paint)
Sets the paint for the tick label for the specified category and sends an AxisChangeEvent to all registered listeners.
voidsetUpperMargin(double margin)
Sets the upper margin for the axis and sends an AxisChangeEvent to all registered listeners.

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).

DEFAULT_CATEGORY_MARGIN

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

Constructor Detail

CategoryAxis

public CategoryAxis()
Creates a new category axis with no label.

CategoryAxis

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

Parameters: label the axis label (null permitted).

Method Detail

addCategoryLabelToolTip

public void addCategoryLabelToolTip(Comparable category, String tooltip)
Adds a tooltip to the specified category and sends an AxisChangeEvent to all registered listeners.

Parameters: category the category (null not permitted). tooltip the tooltip text (null permitted).

See Also: removeCategoryLabelToolTip

calculateCategoryGapSize

protected double calculateCategoryGapSize(int categoryCount, Rectangle2D area, 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.

calculateCategorySize

protected double calculateCategorySize(int categoryCount, Rectangle2D area, 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.

calculateTextBlockHeight

protected double calculateTextBlockHeight(TextBlock block, CategoryLabelPosition position, 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.

calculateTextBlockWidth

protected double calculateTextBlockWidth(TextBlock block, CategoryLabelPosition position, 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.

clearCategoryLabelToolTips

public void clearCategoryLabelToolTips()
Clears the category label tooltips and sends an AxisChangeEvent to all registered listeners.

See Also: CategoryAxis removeCategoryLabelToolTip

clone

public Object clone()
Creates a clone of the axis.

Returns: A clone.

Throws: CloneNotSupportedException if some component of the axis does not support cloning.

configure

public void configure()
Configures the axis against the current plot.

createLabel

protected TextBlock createLabel(Comparable category, float width, RectangleEdge edge, 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.

draw

public AxisState draw(Graphics2D g2, double cursor, Rectangle2D plotArea, Rectangle2D dataArea, RectangleEdge edge, PlotRenderingInfo plotState)
Draws the axis on a Java 2D graphics device (such as the screen or a printer).

Parameters: g2 the graphics device (null not permitted). cursor the cursor location. plotArea the area within which the axis should be drawn (null not permitted). dataArea the area within which the plot is being drawn (null not permitted). edge the location of the axis (null not permitted). plotState collects information about the plot (null permitted).

Returns: The axis state (never null).

drawCategoryLabels

protected AxisState drawCategoryLabels(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge, AxisState state, PlotRenderingInfo plotState)

Deprecated: Use CategoryAxis.

Draws the category labels and returns the updated axis state.

Parameters: g2 the graphics device (null not permitted). dataArea the area inside the axes (null not permitted). edge the axis location (null not permitted). state the axis state (null not permitted). plotState collects information about the plot (null permitted).

Returns: The updated axis state (never null).

drawCategoryLabels

protected AxisState drawCategoryLabels(Graphics2D g2, Rectangle2D plotArea, Rectangle2D dataArea, RectangleEdge edge, AxisState state, PlotRenderingInfo plotState)
Draws the category labels and returns the updated axis state.

Parameters: g2 the graphics device (null not permitted). plotArea the plot area (null not permitted). dataArea the area inside the axes (null not permitted). edge the axis location (null not permitted). state the axis state (null not permitted). plotState collects information about the plot (null permitted).

Returns: The updated axis state (never null).

equals

public boolean equals(Object obj)
Tests this axis for equality with an arbitrary object.

Parameters: obj the object (null permitted).

Returns: A boolean.

getCategoryEnd

public double getCategoryEnd(int category, int categoryCount, Rectangle2D area, 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.

See Also: CategoryAxis CategoryAxis

getCategoryJava2DCoordinate

public double getCategoryJava2DCoordinate(CategoryAnchor anchor, int category, int categoryCount, Rectangle2D area, 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.

getCategoryLabelPositionOffset

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

Returns: The offset (in Java2D units).

See Also: CategoryAxis

getCategoryLabelPositions

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

Returns: The positions (never null).

See Also: setCategoryLabelPositions

getCategoryLabelToolTip

public String getCategoryLabelToolTip(Comparable category)
Returns the tool tip text for the label belonging to the specified category.

Parameters: category the category (null not permitted).

Returns: The tool tip text (possibly null).

See Also: CategoryAxis removeCategoryLabelToolTip

getCategoryMargin

public double getCategoryMargin()
Returns the category margin.

Returns: The margin.

See Also: CategoryAxis

getCategoryMiddle

public double getCategoryMiddle(int category, int categoryCount, Rectangle2D area, 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.

See Also: CategoryAxis CategoryAxis

getCategoryStart

public double getCategoryStart(int category, int categoryCount, Rectangle2D area, 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.

See Also: CategoryAxis CategoryAxis

getLowerMargin

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

Returns: The margin.

See Also: getUpperMargin CategoryAxis

getMaximumCategoryLabelLines

public int getMaximumCategoryLabelLines()
Returns the maximum number of lines to use for each category label.

Returns: The maximum number of lines.

See Also: CategoryAxis

getMaximumCategoryLabelWidthRatio

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

Returns: The ratio.

See Also: CategoryAxis

getTickLabelFont

public Font getTickLabelFont(Comparable category)
Returns the font for the tick label for the given category.

Parameters: category the category (null not permitted).

Returns: The font (never null).

See Also: CategoryAxis

getTickLabelPaint

public Paint getTickLabelPaint(Comparable category)
Returns the paint for the tick label for the given category.

Parameters: category the category (null not permitted).

Returns: The paint (never null).

See Also: CategoryAxis

getUpperMargin

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

Returns: The margin.

See Also: getLowerMargin CategoryAxis

hashCode

public int hashCode()
Returns a hash code for this object.

Returns: A hash code.

refreshTicks

public List refreshTicks(Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge)
Creates a temporary list of ticks that can be used when drawing the axis.

Parameters: g2 the graphics device (used to get font measurements). state the axis state. dataArea the area inside the axes. edge the location of the axis.

Returns: A list of ticks.

removeCategoryLabelToolTip

public void removeCategoryLabelToolTip(Comparable category)
Removes the tooltip for the specified category and sends an AxisChangeEvent to all registered listeners.

Parameters: category the category (null not permitted).

See Also: CategoryAxis clearCategoryLabelToolTips

reserveSpace

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

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 space required to draw the axis.

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 (in Java2D units).

See Also: getCategoryLabelPositionOffset

setCategoryLabelPositions

public void setCategoryLabelPositions(CategoryLabelPositions positions)
Sets the category label position specification for the axis and sends an AxisChangeEvent to all registered listeners.

Parameters: positions the positions (null not permitted).

See Also: getCategoryLabelPositions

setCategoryMargin

public void setCategoryMargin(double margin)
Sets the category margin and sends an AxisChangeEvent 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 as a percentage of the axis length (for example, 0.05 is five percent).

See Also: getCategoryMargin

setLowerMargin

public void setLowerMargin(double margin)
Sets the lower margin for the axis and sends an AxisChangeEvent to all registered listeners.

Parameters: margin the margin as a percentage of the axis length (for example, 0.05 is five percent).

See Also: getLowerMargin

setMaximumCategoryLabelLines

public void setMaximumCategoryLabelLines(int lines)
Sets the maximum number of lines to use for each category label and sends an AxisChangeEvent to all registered listeners.

Parameters: lines the maximum number of lines.

See Also: getMaximumCategoryLabelLines

setMaximumCategoryLabelWidthRatio

public void setMaximumCategoryLabelWidthRatio(float ratio)
Sets the maximum category label width ratio and sends an AxisChangeEvent to all registered listeners.

Parameters: ratio the ratio.

See Also: getMaximumCategoryLabelWidthRatio

setTickLabelFont

public void setTickLabelFont(Comparable category, Font font)
Sets the font for the tick label for the specified category and sends an AxisChangeEvent to all registered listeners.

Parameters: category the category (null not permitted). font the font (null permitted).

See Also: getTickLabelFont

setTickLabelPaint

public void setTickLabelPaint(Comparable category, Paint paint)
Sets the paint for the tick label for the specified category and sends an AxisChangeEvent to all registered listeners.

Parameters: category the category (null not permitted). paint the paint (null permitted).

See Also: getTickLabelPaint

setUpperMargin

public void setUpperMargin(double margin)
Sets the upper margin for the axis and sends an AxisChangeEvent to all registered listeners.

Parameters: margin the margin as a percentage of the axis length (for example, 0.05 is five percent).

See Also: getUpperMargin