com.ijchart.xychart.axis.category
Class CategoryAxis

java.lang.Object
  extended by com.ijchart.xychart.axis.AbstractAxis
      extended by com.ijchart.xychart.axis.category.CategoryAxis
All Implemented Interfaces:
IAxis, IMarkerChangeListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener
Direct Known Subclasses:
CategoryAxis3D, GroupCategoryAxis

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

Title: IJChart

Description: a chart library for the Java(tm) platform.

An axis that displays categories (X-Axis).

Copyright: Copyright (c) 2013

Company:

Version:
1.0
Author:
zhang feng min,shanghai china. Contract me by email.
See Also:
Serialized Form

Field Summary
protected  double acategoryWidth
           The width of a category.
protected  java.util.Hashtable categoryLabelPosition
           The position of categorys.
static double DEFAULT_CATEGORY_MARGIN
           The default margin between categories (a percentage of the overall axis length).
static HorizontalAlignment DEFAULT_HORIZONTAL_ALIGNMENT
           The default horizontal alignment.
static int DEFAULT_MAX_CATEGORY_LABEL_LINE
           The default maximum number of lines for labels (default is all).
 
Fields inherited from class com.ijchart.xychart.axis.AbstractAxis
DEFAULT_3D_AXIS_FILL_PAINT, DEFAULT_AUTO_SELECT_TICK_LABEL_ALIGN, DEFAULT_AXIS_LABEL_FONT, DEFAULT_AXIS_LABEL_INSETS, DEFAULT_AXIS_LABEL_PAINT, DEFAULT_AXIS_LABEL_TYPE, DEFAULT_AXIS_LABEL_VISIBLE, DEFAULT_AXIS_LINE_PAINT, DEFAULT_AXIS_LINE_STROKE, DEFAULT_AXIS_LINE_VISIBLE, DEFAULT_AXIS_MARGIN, DEFAULT_AXIS_VISIBLE, DEFAULT_DRAW_EMPTY_LABEL_TICK_MARK, DEFAULT_FIXED_AXIS_SPACE, DEFAULT_GRID_LINE_VISIBLE, DEFAULT_LABEL_HORIZONTAL_ALIGNMENT, DEFAULT_MAXIMUM_CATEGORY_LABEL_WIDTH_RATIO, DEFAULT_TICK_LABEL_FONT, DEFAULT_TICK_LABEL_HORIZONTAL_ALIGNMENT, DEFAULT_TICK_LABEL_INSETS, DEFAULT_TICK_LABEL_PAINT, DEFAULT_TICK_LABEL_VERTICAL_ALIGNMENT, 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, WIDTH_TICK_MARK_AND_TICK_LABEL
 
Constructor Summary
CategoryAxis(IMatrixDataset dataset)
           Constructs an axis using a dataset.
CategoryAxis(java.lang.String label, IMatrixDataset dataset)
           Constructs an axis using label and a dataset.
 
Method Summary
 void addCategoryMarker(Layer layer, CategoryMarker marker)
           Calculate the position of category (colKey).
 void clearCategoryMarkers(Layer layer)
           Clears all the category markers for the plot and sends an AxisChangeEvent to all registered listeners.
 java.lang.Object clone()
           Creates a clone of the axis.
protected  IChartShape createChartShape(java.awt.geom.Rectangle2D tickLabelDrawRect, java.lang.String tickLabel, int rowKeyIndex)
           Create a RectangleTextChartShape object.
 void drawGridLine(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D dataArea, RectangleEdge axisEdge, RenderShapeCollection shapeCollection, java.awt.Stroke stroke, java.awt.Paint paint)
           Draw the grid line,only call after IAxis.draw().
protected  double drawTickLabel(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D plotArea, java.awt.geom.Rectangle2D axisArea, RectangleEdge edge, AxisShapeCollection shapeCollection, double cursor)
           Draws tick mark labels in a specified area and edge.
protected  double drawTickMark(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D axisArea, RectangleEdge edge, AxisShapeCollection shapeCollection, double cursor)
           Draws tick marks in a specified area and edge.
 boolean equals(java.lang.Object obj)
           Tests this axis for equality with an arbitrary object.
 HorizontalAlignment getCategoryLabelHorizontalAlignment()
           Returns the category label horizontal alignment.
 double getCategoryMargin()
           Returns the category margin.
 java.util.Collection getCategoryMarkers(Layer layer)
           Returns a collection of category markers for specified layer.
protected  java.lang.String[] getFormatedTickLabels(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D maxAxisArea, RectangleEdge edge)
           Returns the formated tick labels.
protected  double getLabelMaxDrawWidth(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D plotArea, RectangleEdge edge)
           Calculation the width of painting coordinate axis labels required by the maximum width and not more than maximumCategoryLabelWidthRatio determined by the parameters of the entire region of the chart width or height.
 int getMaximumCategoryLabelLines()
           Returns the maximum number of lines to use for each category label.
 int hashCode()
           Returns a hash code for this object.
 void markerChanged(MarkerChangeEvent event)
           Receives notification of an marker change event.
 boolean removeCategoryMarker(Layer layer, CategoryMarker marker)
           Removes a marker for a specific layer and sends an AxisChangeEvent to all registered listeners.
 void setCategoryLabelHorizontalAlignment(HorizontalAlignment align)
           Sets the category label horizontal alignment and sends an AxisChangeEvent to all registered listeners.
 void setCategoryMargin(double margin)
           Sets the category margin and sends an AxisChangeEvent to all registered listeners.
 void setMaximumCategoryLabelLines(int lines)
           Sets the maximum number of lines to use for each category label and sends an AxisChangeEvent to all registered listeners.
 
Methods inherited from class com.ijchart.xychart.axis.AbstractAxis
addChangeListener, calculateAxisSpace, calculateLabelBound, createAxisLabelChartShape, dawAxisLabel, draw, drawAxis3DLine, drawAxisLine, fireAxisChanged, getAxis3DFillPaint, getAxisLabel, getAxisLabelAngle, getAxisLabelFont, getAxisLabelHorizontalAlign, getAxisLabelInsets, getAxisLabelPaint, getAxisLabelType, getAxisLinePaint, getAxisLineStroke, getColKeyFormatter, getDataFormatter, getDataset, getFixedAxisSpace, getLowerMargin, getMaximumCategoryLabelWidthRatio, getRowKeyFormatter, getTickLabelAngle, getTickLabelFont, getTickLabelFont, getTickLabelHorizontalAlign, getTickLabelInsets, getTickLabelLines, getTickLabelPaint, getTickLabelPaint, getTickLabelRotateBound, getTickLabelVerticalAlign, getTickMarkInsideLength, getTickMarkOutsideLength, getTickMarkPaint, getTickMarkStroke, getUpperMargin, hasListener, isAutoSelectTickLabelAlign, isAxisLabelVisible, isAxisLineVisible, isDrawEmptyLabelTickMark, isGridLineVisible, isTickLabelsVisible, isTickMarkVisible, isVisible, notifyListeners, removeAllChangeListener, removeChangeListener, setAutoSelectTickLabelAlign, setAxis3DFillPaint, setAxisLabel, setAxisLabelAngle, setAxisLabelFont, setAxisLabelHorizontalAlign, setAxisLabelInsets, setAxisLabelPaint, setAxisLabelType, setAxisLabelVisible, setAxisLinePaint, setAxisLineStroke, setAxisLineVisible, setColKeyFormatter, setDataFormatter, setDataset, setDrawEmptyLabelTickMark, setFixedAxisSpace, setGridLineVisible, setLowerMargin, setMaximumCategoryLabelWidthRatio, setRowKeyFormatter, setTickLabelAngle, setTickLabelFont, setTickLabelFont, setTickLabelHorizontalAlign, setTickLabelInsets, setTickLabelPaint, setTickLabelPaint, setTickLabelsVisible, setTickLabelVerticalAlign, setTickMarkInsideLength, setTickMarkOutsideLength, setTickMarkPaint, setTickMarkStroke, setTickMarkVisible, setUpperMargin, setVisible
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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

DEFAULT_HORIZONTAL_ALIGNMENT

public static final HorizontalAlignment DEFAULT_HORIZONTAL_ALIGNMENT
The default horizontal alignment.


DEFAULT_MAX_CATEGORY_LABEL_LINE

public static final int DEFAULT_MAX_CATEGORY_LABEL_LINE
The default maximum number of lines for labels (default is all).

See Also:
Constant Field Values

categoryLabelPosition

protected java.util.Hashtable categoryLabelPosition
The position of categorys.


acategoryWidth

protected double acategoryWidth
The width of a category.

Constructor Detail

CategoryAxis

public CategoryAxis(IMatrixDataset dataset)
Constructs an axis using a dataset.

Parameters:
dataset - IMatrixDataset The two dimension matrix dataset (null not permitted).

CategoryAxis

public CategoryAxis(java.lang.String label,
                    IMatrixDataset dataset)
Constructs an axis using label and a dataset.

Parameters:
label - The axis label (null permitted).
dataset - IMatrixDataset The two dimension matrix dataset (null not permitted).
Method Detail

getCategoryMargin

public double getCategoryMargin()
Returns the category margin.

Returns:
The margin.

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

getMaximumCategoryLabelLines

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

Returns:
The maximum number of lines.

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.

getCategoryLabelHorizontalAlignment

public HorizontalAlignment getCategoryLabelHorizontalAlignment()
Returns the category label horizontal alignment.

Returns:
HorizontalAlignment The category label horizontal alignment (never null).

setCategoryLabelHorizontalAlignment

public void setCategoryLabelHorizontalAlignment(HorizontalAlignment align)
Sets the category label horizontal alignment and sends an AxisChangeEvent to all registered listeners.

Parameters:
align - HorizontalAlignment The category label horizontal alignment (null not permitted).

drawTickMark

protected double drawTickMark(java.awt.Graphics2D g2,
                              java.awt.geom.Rectangle2D axisArea,
                              RectangleEdge edge,
                              AxisShapeCollection shapeCollection,
                              double cursor)
Draws tick marks in a specified area and edge.

Specified by:
drawTickMark in class AbstractAxis
Parameters:
g2 - Graphics2D The graphics device (null not permitted).
axisArea - Rectangle2D The empty chart area.
edge - RectangleEdge The axis position.
shapeCollection - AxisShapeCollection Collects information about the axis (null permitted).
cursor - The cursor location.
Returns:
double The cursor location after draw tick mark.

drawTickLabel

protected double drawTickLabel(java.awt.Graphics2D g2,
                               java.awt.geom.Rectangle2D plotArea,
                               java.awt.geom.Rectangle2D axisArea,
                               RectangleEdge edge,
                               AxisShapeCollection shapeCollection,
                               double cursor)
Draws tick mark labels in a specified area and edge.

Specified by:
drawTickLabel in class AbstractAxis
Parameters:
g2 - Graphics2D The graphics device (null not permitted).
plotArea - Rectangle2D The area within which the plot should be drawn.
axisArea - Rectangle2D The empty chart area.
edge - RectangleEdge The axis position.
shapeCollection - AxisShapeCollection Collects information about the axis (null permitted).
cursor - The cursor location.
Returns:
double The cursor location after draw tick label.

categoryToJava2D

public double categoryToJava2D(java.lang.Object category,
                               TextAnchor anchor)
Calculate the position of category (colKey).

Parameters:
category - Object The category.
anchor - CategoryAnchor The position of a text (null permitted).
Returns:
double The coordinate,if the category not found,returns -1.

createChartShape

protected IChartShape createChartShape(java.awt.geom.Rectangle2D tickLabelDrawRect,
                                       java.lang.String tickLabel,
                                       int rowKeyIndex)
Create a RectangleTextChartShape object.

Parameters:
tickLabelDrawRect - Rectangle2D The tick label bound.
tickLabel - String The tick label.
rowKeyIndex - The index of rowKey in dataset.
Returns:
IChartShape A IChartShape.

getLabelMaxDrawWidth

protected double getLabelMaxDrawWidth(java.awt.Graphics2D g2,
                                      java.awt.geom.Rectangle2D plotArea,
                                      RectangleEdge edge)
Calculation the width of painting coordinate axis labels required by the maximum width and not more than maximumCategoryLabelWidthRatio determined by the parameters of the entire region of the chart width or height.

Parameters:
g2 - Graphics2D The graphics device (null not permitted).
plotArea - Rectangle2D The area within which the plot should be drawn.
edge - RectangleEdge The axis position.
Returns:
double The width.

getFormatedTickLabels

protected java.lang.String[] getFormatedTickLabels(java.awt.Graphics2D g2,
                                                   java.awt.geom.Rectangle2D maxAxisArea,
                                                   RectangleEdge edge)
Returns the formated tick labels.

Specified by:
getFormatedTickLabels in class AbstractAxis
Parameters:
g2 - Graphics2D The graphics device (null permitted).
maxAxisArea - Rectangle2D The maximum area within which the axis should be drawn (null permitted).
edge - RectangleEdge The axis position (null permitted).
Returns:
String[] The array of tick labels.

addCategoryMarker

public void addCategoryMarker(Layer layer,
                              CategoryMarker marker)
Adds a marker for display by a particular render.

Typically a marker will be drawn by the render as a line perpendicular to a category axis, however this is entirely up to the render.

Parameters:
layer - Layer The layer (foreground or background) (null not permitted).
marker - CategoryMarker The marker (null not permitted).

getCategoryMarkers

public java.util.Collection getCategoryMarkers(Layer layer)
Returns a collection of category markers for specified layer.

Parameters:
layer - The layer (null not permitted).
Returns:
Collection A collection of markers (possibly null).

removeCategoryMarker

public boolean removeCategoryMarker(Layer layer,
                                    CategoryMarker marker)
Removes a marker for a specific layer and sends an AxisChangeEvent to all registered listeners.

Parameters:
layer - Layer The layer (foreground or background) (null not permitted).
marker - CategoryMarker The marker (null not permitted).
Returns:
A boolean indicating whether or not the marker was actually removed.

clearCategoryMarkers

public void clearCategoryMarkers(Layer layer)
Clears all the category markers for the plot and sends an AxisChangeEvent to all registered listeners.

Parameters:
layer - Layer The layer (foreground or background) (null not permitted).

drawGridLine

public void drawGridLine(java.awt.Graphics2D g2,
                         java.awt.geom.Rectangle2D dataArea,
                         RectangleEdge axisEdge,
                         RenderShapeCollection shapeCollection,
                         java.awt.Stroke stroke,
                         java.awt.Paint paint)
Draw the grid line,only call after IAxis.draw().

Specified by:
drawGridLine in class AbstractAxis
Parameters:
g2 - Graphics2D The graphics device (null not permitted).
dataArea - Rectangle2D The area within which the data should be drawn (null not permitted).
axisEdge - RectangleEdge The axis position (null not permitted).
shapeCollection - RenderShapeCollection Collects information about the render (null not permitted).
stroke - Stroke The grid line stroke.
paint - Paint The grid line paint (null not permitted).

markerChanged

public void markerChanged(MarkerChangeEvent event)
Receives notification of an marker change event.

Specified by:
markerChanged in interface IMarkerChangeListener
Parameters:
event - The marker change event.

clone

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

Overrides:
clone in class AbstractAxis
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 an arbitrary object.

Overrides:
equals in class AbstractAxis
Parameters:
obj - The object (null permitted).
Returns:
A boolean.

hashCode

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

Overrides:
hashCode in class AbstractAxis
Returns:
A hash code.