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.

用于显示分类值的坐标轴.

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
          一个系列的宽度.
protected  java.util.Hashtable categoryLabelPosition
          category标签的位置.
static double DEFAULT_CATEGORY_MARGIN
          坐标轴上的所有标签的空白区域之和与坐标轴长度的比值的缺省值,单位为百分比.
static HorizontalAlignment DEFAULT_HORIZONTAL_ALIGNMENT
          缺省水平对齐方式.
 
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)
          由数据集构造对象.
CategoryAxis(java.lang.String label, IMatrixDataset dataset)
          由坐标轴标签和数据集构造对象.
 
Method Summary
 void addCategoryMarker(Layer layer, CategoryMarker marker)
          增加一个marker,并且向所有监听器发送AxisChangeEvent事件.
 double categoryToJava2D(java.lang.Object category, TextAnchor anchor)
          根据分类(colKey)的值计算位置.
 void clearCategoryMarkers(Layer layer)
          删除所有的category marker,并向所有监听器发送AxisChangeEvent 事件.
 java.lang.Object clone()
          克隆本对象.
protected  IChartShape createChartShape(java.awt.geom.Rectangle2D tickLabelDrawRect, java.lang.String tickLabel, int rowKeyIndex)
          创建一个RectangleTextChartShape对象.
 void drawGridLine(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D dataArea, RectangleEdge axisEdge, RenderShapeCollection shapeCollection, java.awt.Stroke stroke, java.awt.Paint paint)
          绘制网格线,须在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)
          绘制坐标轴上的刻度值的标签.
protected  double drawTickMark(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D axisArea, RectangleEdge edge, AxisShapeCollection shapeCollection, double cursor)
          绘制坐标轴上的刻度.
 boolean equals(java.lang.Object obj)
          测试本对象是否和另一个对象相等.
 HorizontalAlignment getCategoryLabelHorizontalAlignment()
          返回标签的水平对齐方式.
 double getCategoryMargin()
          返回坐标轴上的所有标签的空白区域之和与坐标轴长度的比值,单位为百分比.
 java.util.Collection getCategoryMarkers(Layer layer)
          根据Layer对象返回所有的category marker.
protected  java.lang.String[] getFormatedTickLabels(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D maxAxisArea, RectangleEdge edge)
          返回格式化后的在坐标轴上显示的刻度值.
protected  double getLabelMaxDrawWidth(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D plotArea, RectangleEdge edge)
          计算绘制坐标轴上的标签所需要的最大宽度,并且不超过由参数maximumCategoryLabelWidthRatio确定的整个图表区域 的宽度或高度.
 int getMaximumCategoryLabelLines()
          返回标签的最大行数.
 int hashCode()
          计算hashcode.
 void markerChanged(MarkerChangeEvent event)
          收到marker发生变化的事件.
 boolean removeCategoryMarker(Layer layer, CategoryMarker marker)
          根据指定的Layer对象删除marker对象.
 void setCategoryLabelHorizontalAlignment(HorizontalAlignment align)
          设置标签的水平对齐方式,并向所有监听器发送 AxisChangeEvent事件.
 void setCategoryMargin(double margin)
          设置坐标轴上的所有标签的空白区域之和与坐标轴长度的比值,单位为百分比,并向所有监听器发送 AxisChangeEvent事件.
 
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
坐标轴上的所有标签的空白区域之和与坐标轴长度的比值的缺省值,单位为百分比.

See Also:
Constant Field Values

DEFAULT_HORIZONTAL_ALIGNMENT

public static final HorizontalAlignment DEFAULT_HORIZONTAL_ALIGNMENT
缺省水平对齐方式.


DEFAULT_MAX_CATEGORY_LABEL_LINE

public static final int DEFAULT_MAX_CATEGORY_LABEL_LINE
标签缺省的最大显示行数,默认全部显示.

See Also:
Constant Field Values

categoryLabelPosition

protected java.util.Hashtable categoryLabelPosition
category标签的位置.


acategoryWidth

protected double acategoryWidth
一个系列的宽度.

Constructor Detail

CategoryAxis

public CategoryAxis(IMatrixDataset dataset)
由数据集构造对象.

Parameters:
dataset - IMatrixDataset 二维矩阵数据集 (不可为null).

CategoryAxis

public CategoryAxis(java.lang.String label,
                    IMatrixDataset dataset)
由坐标轴标签和数据集构造对象.

Parameters:
label - 坐标轴标签.
dataset - IMatrixDataset 二维矩阵数据集 (不可为null).
Method Detail

getCategoryMargin

public double getCategoryMargin()
返回坐标轴上的所有标签的空白区域之和与坐标轴长度的比值,单位为百分比.

Returns:
坐标轴上的所有标签的空白区域之和与坐标轴长度的比值,单位为百分比.

setCategoryMargin

public void setCategoryMargin(double margin)
设置坐标轴上的所有标签的空白区域之和与坐标轴长度的比值,单位为百分比,并向所有监听器发送 AxisChangeEvent事件.

Parameters:
margin - 坐标轴上的所有标签的空白区域之和与坐标轴长度的比值(单位为百分比),例如:0.05表示5%

getMaximumCategoryLabelLines

public int getMaximumCategoryLabelLines()
返回标签的最大行数.

Returns:
标签的最大行数.

setMaximumCategoryLabelLines

public void setMaximumCategoryLabelLines(int lines)
设置标签的最大行数,并向所有监听器发送AxisChangeEvent事件.

Parameters:
lines - 标签的最大行数

getCategoryLabelHorizontalAlignment

public HorizontalAlignment getCategoryLabelHorizontalAlignment()
返回标签的水平对齐方式.

Returns:
HorizontalAlignment 标签的水平对齐方式(不为null).

setCategoryLabelHorizontalAlignment

public void setCategoryLabelHorizontalAlignment(HorizontalAlignment align)
设置标签的水平对齐方式,并向所有监听器发送 AxisChangeEvent事件.

Parameters:
align - HorizontalAlignment 标签的水平对齐方式 (不可为null).

drawTickMark

protected double drawTickMark(java.awt.Graphics2D g2,
                              java.awt.geom.Rectangle2D axisArea,
                              RectangleEdge edge,
                              AxisShapeCollection shapeCollection,
                              double cursor)
绘制坐标轴上的刻度.

Specified by:
drawTickMark in class AbstractAxis
Parameters:
g2 - Graphics2D 图形设备(打印机或屏幕) (不可为null).
axisArea - Rectangle2D 剩余的空白区域.
edge - RectangleEdge 坐标轴的位置.
shapeCollection - AxisShapeCollection 坐标轴图形集合.
cursor - 光标的位置.
Returns:
double 绘制完坐标刻度光标的位置.

drawTickLabel

protected double drawTickLabel(java.awt.Graphics2D g2,
                               java.awt.geom.Rectangle2D plotArea,
                               java.awt.geom.Rectangle2D axisArea,
                               RectangleEdge edge,
                               AxisShapeCollection shapeCollection,
                               double cursor)
绘制坐标轴上的刻度值的标签.

Specified by:
drawTickLabel in class AbstractAxis
Parameters:
g2 - Graphics2D 图形设备(打印机或屏幕) (不可为null).
plotArea - Rectangle2D 图表的plot区域.
axisArea - Rectangle2D 剩余的空白区域.
edge - RectangleEdge 坐标轴的位置.
shapeCollection - AxisShapeCollection 坐标轴图形集合.
cursor - 光标的位置.
Returns:
double 绘制完坐标轴刻度值后光标的位置.

categoryToJava2D

public double categoryToJava2D(java.lang.Object category,
                               TextAnchor anchor)
根据分类(colKey)的值计算位置.

Parameters:
category - Object 分类值(colKey).
anchor - CategoryAnchor 文字对齐方式 (可为null).
Returns:
double 分类(colKey)的坐标值,如果没有找到返回-1.

createChartShape

protected IChartShape createChartShape(java.awt.geom.Rectangle2D tickLabelDrawRect,
                                       java.lang.String tickLabel,
                                       int rowKeyIndex)
创建一个RectangleTextChartShape对象.

Parameters:
tickLabelDrawRect - Rectangle2D 刻度值的包围矩形.
tickLabel - String 刻度值.
rowKeyIndex - 数据集的rowKey的索引值.
Returns:
IChartShape 图形对象.

getLabelMaxDrawWidth

protected double getLabelMaxDrawWidth(java.awt.Graphics2D g2,
                                      java.awt.geom.Rectangle2D plotArea,
                                      RectangleEdge edge)
计算绘制坐标轴上的标签所需要的最大宽度,并且不超过由参数maximumCategoryLabelWidthRatio确定的整个图表区域 的宽度或高度.

Parameters:
g2 - Graphics2D 图形设备(打印机或屏幕) (不可为null).
plotArea - Rectangle2D 图表的plot区域.
edge - RectangleEdge 坐标轴的位置.
Returns:
double 宽度.

getFormatedTickLabels

protected java.lang.String[] getFormatedTickLabels(java.awt.Graphics2D g2,
                                                   java.awt.geom.Rectangle2D maxAxisArea,
                                                   RectangleEdge edge)
返回格式化后的在坐标轴上显示的刻度值.

Specified by:
getFormatedTickLabels in class AbstractAxis
Parameters:
g2 - Graphics2D 图形设备(打印机或屏幕),可为null.
maxAxisArea - Rectangle2D 坐标轴的最大区域,肯定小于plotArea (可为null).
edge - RectangleEdge 坐标轴的位置 (可为null).
Returns:
String[] 刻度值数组.

addCategoryMarker

public void addCategoryMarker(Layer layer,
                              CategoryMarker marker)
增加一个marker,并且向所有监听器发送AxisChangeEvent事件. 一般情况下marker会垂直于category坐标轴.

Parameters:
layer - Layer 绘制的顺序(前景或背景) (不可为null).
marker - CategoryMarker CategoryMarker对象 (不可为null).

getCategoryMarkers

public java.util.Collection getCategoryMarkers(Layer layer)
根据Layer对象返回所有的category marker.

Parameters:
layer - Layer对象 (不可为null).
Returns:
Collection category marker对象集合 (可能为null).

removeCategoryMarker

public boolean removeCategoryMarker(Layer layer,
                                    CategoryMarker marker)
根据指定的Layer对象删除marker对象.

Parameters:
layer - Layer layer对象 (不可为null).
marker - CategoryMarker CategoryMarker对象 (不可为null).
Returns:
是否真的删除了此对象.

clearCategoryMarkers

public void clearCategoryMarkers(Layer layer)
删除所有的category marker,并向所有监听器发送AxisChangeEvent 事件.

Parameters:
layer - Layer 绘制的顺序(前景或背景) (不可为null).

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)
绘制网格线,须在IAxis.draw()方法之后调用.

Specified by:
drawGridLine in class AbstractAxis
Parameters:
g2 - Graphics2D 图形设备(打印机或屏幕) (不可为null).
dataArea - Rectangle2D 图表的data区域(数据区) (不可为null).
axisEdge - RectangleEdge 坐标轴的位置 (不可为null).
shapeCollection - RenderShapeCollection 坐标轴图形集合 (不可为null).
stroke - Stroke 网格线stroke (不可为null).
paint - Paint 网格线paint (不可为null).

markerChanged

public void markerChanged(MarkerChangeEvent event)
收到marker发生变化的事件.

Specified by:
markerChanged in interface IMarkerChangeListener
Parameters:
event - marker变化的事件.

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
克隆本对象.

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)
测试本对象是否和另一个对象相等.

Overrides:
equals in class AbstractAxis
Parameters:
obj - 要测试的对象 (可为null).
Returns:
A boolean.

hashCode

public int hashCode()
计算hashcode.

Overrides:
hashCode in class AbstractAxis
Returns:
hashcode.