com.jrefinery.chart
Class CategoryPlot

java.lang.Object
  extended by com.jrefinery.chart.Plot
      extended by com.jrefinery.chart.CategoryPlot
All Implemented Interfaces:
AxisConstants, CategoryPlotConstants, com.jrefinery.chart.event.AxisChangeListener, DatasetChangeListener
Direct Known Subclasses:
HorizontalCategoryPlot, VerticalCategoryPlot

public abstract class CategoryPlot
extends Plot
implements CategoryPlotConstants

A general plotting class that uses data from a CategoryDataset, and uses a plug-in renderer to draw individual data items.

See Also:
Plot, CategoryItemRenderer

Field Summary
protected  double categoryGapsPercent
          The percentage of the overall drawing space allocated to providing gaps between the last item in one category and the first item in the next category.
protected  CategoryAxis domainAxis
          The domain axis.
protected  double introGapPercent
          The gap before the first item in the plot.
protected  double itemGapsPercent
          The gap between items within the same category.
protected  java.awt.Font labelFont
          The value label font.
protected  java.lang.String labelFormatPattern
          The value label format pattern String.
protected  java.text.NumberFormat labelFormatter
          The value label format.
protected  java.awt.Paint labelPaint
          The value label paint.
protected  boolean labelsVisible
          A flag indicating whether or not value labels are shown.
protected  java.util.List markers
          A list of markers (optional) for the range axis.
protected  CategoryPlot parent
          The parent plot (or null if this is not a subplot).
protected  ValueAxis rangeAxis
          The range axis.
protected  CategoryItemRenderer renderer
          The renderer for the data items.
protected  double trailGapPercent
          The gap after the last item in the plot.
protected  boolean verticalLabels
          A flag indicating whether or not value labels are drawn vertically.
 
Fields inherited from class com.jrefinery.chart.Plot
backgroundAlpha, backgroundImage, backgroundPaint, dataset, DEFAULT_BACKGROUND_ALPHA, DEFAULT_BACKGROUND_PAINT, DEFAULT_FOREGROUND_ALPHA, DEFAULT_INSETS, DEFAULT_OUTLINE_PAINT, DEFAULT_OUTLINE_STROKE, firstSeriesIndex, foregroundAlpha, insets, listeners, MINIMUM_HEIGHT_TO_DRAW, MINIMUM_WIDTH_TO_DRAW, outlinePaint, outlineStroke, seriesOutlinePaint, seriesOutlineStroke, seriesPaint, seriesStroke, shapeFactory, ZERO
 
Fields inherited from interface com.jrefinery.chart.CategoryPlotConstants
DEFAULT_CATEGORY_GAPS_PERCENT, DEFAULT_INTRO_GAP_PERCENT, DEFAULT_ITEM_GAPS_PERCENT, DEFAULT_LABEL_FONT, DEFAULT_TRAIL_GAP_PERCENT, MAX_CATEGORY_GAPS_PERCENT, MAX_INTRO_GAP_PERCENT, MAX_ITEM_GAPS_PERCENT, MAX_TRAIL_GAP_PERCENT
 
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_STROKE
 
Constructor Summary
protected CategoryPlot(CategoryDataset data, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryItemRenderer renderer)
          Constructs a category plot, using default values where necessary.
protected CategoryPlot(CategoryDataset data, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryItemRenderer renderer, java.awt.Insets insets, java.awt.Paint backgroundPaint, java.awt.Image backgroundImage, float backgroundAlpha, java.awt.Stroke outlineStroke, java.awt.Paint outlinePaint, float foregroundAlpha, double introGapPercent, double trailGapPercent, double categoryGapsPercent, double itemGapsPercent)
          Constructs a category plot.
 
Method Summary
 void addRangeMarker(Marker marker)
          Adds a marker for the range axis.
 void datasetChanged(DatasetChangeEvent event)
          Receives notification of a change to the plot's dataset.
abstract  double getCategoryCoordinate(int category, java.awt.geom.Rectangle2D area)
          Returns the x or y coordinate (depending on the orientation of the plot) in Java 2D User Space of the center of the specified category.
 CategoryDataset getCategoryDataset()
          A convenience method that returns the dataset for the plot, cast as a CategoryDataset.
 double getCategoryGapsPercent()
          Returns the percentage of the drawing space that is allocated to providing gaps between the categories.
 CategoryAxis getDomainAxis()
          Returns the domain axis for the plot.
 double getIntroGapPercent()
          Returns the gap before the first bar on the chart, as a percentage of the available drawing space (0.05 = 5 percent).
 double getItemGapsPercent()
          Returns the percentage of the drawing space that is allocated to providing gaps between the items in a category.
 java.awt.Font getLabelFont()
          Returns the value label font.
 java.text.NumberFormat getLabelFormatter()
          Returns the value label formatter.
 java.awt.Paint getLabelPaint()
          Returns the value label paint.
 boolean getLabelsVisible()
          Returns a flag that indicates whether or not the value labels are showing.
 java.util.List getLegendItemLabels()
          Returns a list of labels for the legend.
 CategoryPlot getParent()
          Returns the parent plot, or null if this is not a sub-plot.
 ValueAxis getRangeAxis()
          Returns the range axis for the plot.
 CategoryItemRenderer getRenderer()
          Returns a reference to the renderer for the plot.
 int getSeriesCount()
          Returns the number of series in this plot.
 double getTrailGapPercent()
          Returns the gap following the last bar on the chart, as a percentage of the available drawing space.
 boolean getVerticalLabels()
          Returns true if the value labels should be rotated to vertical, and false for standard horizontal labels.
abstract  boolean isCompatibleDomainAxis(CategoryAxis axis)
          Checks the compatibility of a domain axis, returning true if the axis is compatible with the plot, and false otherwise.
abstract  boolean isCompatibleRangeAxis(ValueAxis axis)
          Checks the compatibility of a range axis, returning true if the axis is compatible with the plot, and false otherwise.
 boolean isSubplot()
          Returns true if this plot is part of a combined plot structure, and false otherwise.
 void setCategoryGapsPercent(double percent)
          Sets the gap between the last bar in one category and the first bar in the next category, and notifies registered listeners that the plot has been modified.
 void setDomainAxis(CategoryAxis axis)
          Sets the domain axis for the plot (this must be compatible with the plot type or an exception is thrown).
 void setIntroGapPercent(double percent)
          Sets the gap before the first bar on the chart, and notifies registered listeners that the plot has been modified.
 void setItemGapsPercent(double percent)
          Sets the gap between one bar and the next within the same category, and notifies registered listeners that the plot has been modified.
 void setLabelFont(java.awt.Font font)
          Sets the value label font.
 void setLabelFormatString(java.lang.String format)
          Sets the format string for the value labels.
 void setLabelPaint(java.awt.Paint paint)
          Sets the value label paint.
 void setLabelsVisible(boolean flag)
          Sets the flag that indicates whether or not the value labels are showing.
 void setParent(CategoryPlot parent)
          Sets the parent plot.
 void setRangeAxis(ValueAxis axis)
          Sets the range axis for the plot.
 void setRenderer(CategoryItemRenderer renderer)
          Sets the renderer for the plot.
 void setTrailGapPercent(double percent)
          Sets the gap after the last bar on the chart, and notifies registered listeners that the plot has been modified.
 void setVerticalLabels(boolean flag)
          Sets the flag that determines the orientation of the value labels.
 void zoom(double percent)
          Zooms (in or out) on the plot's value axis.
 
Methods inherited from class com.jrefinery.chart.Plot
addChangeListener, axisChanged, draw, drawOutlineAndBackground, getBackgroundAlpha, getBackgroundPaint, getDataset, getFirstSeriesIndex, getForegroundAlpha, getInsets, getOutlinePaint, getOutlineStroke, getPlotType, getSeriesOutlinePaint, getSeriesOutlineStroke, getSeriesPaint, getSeriesStroke, getShape, getShape, getShapeFactory, handleClick, notifyListeners, removeChangeListener, setBackgroundAlpha, setBackgroundImage, setBackgroundPaint, setDataset, setFirstSeriesIndex, setForegroundAlpha, setInsets, setOutlinePaint, setOutlineStroke, setSeriesOutlinePaint, setSeriesOutlineStroke, setSeriesOutlineStroke, setSeriesPaint, setSeriesPaint, setSeriesStroke, setSeriesStroke, setShapeFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parent

protected CategoryPlot parent
The parent plot (or null if this is not a subplot).


domainAxis

protected CategoryAxis domainAxis
The domain axis.


rangeAxis

protected ValueAxis rangeAxis
The range axis.


markers

protected java.util.List markers
A list of markers (optional) for the range axis.


renderer

protected CategoryItemRenderer renderer
The renderer for the data items.


introGapPercent

protected double introGapPercent
The gap before the first item in the plot.


trailGapPercent

protected double trailGapPercent
The gap after the last item in the plot.


categoryGapsPercent

protected double categoryGapsPercent
The percentage of the overall drawing space allocated to providing gaps between the last item in one category and the first item in the next category.


itemGapsPercent

protected double itemGapsPercent
The gap between items within the same category.


labelsVisible

protected boolean labelsVisible
A flag indicating whether or not value labels are shown.


labelFont

protected java.awt.Font labelFont
The value label font.


labelPaint

protected java.awt.Paint labelPaint
The value label paint.


labelFormatPattern

protected java.lang.String labelFormatPattern
The value label format pattern String.


labelFormatter

protected java.text.NumberFormat labelFormatter
The value label format.


verticalLabels

protected boolean verticalLabels
A flag indicating whether or not value labels are drawn vertically.

Constructor Detail

CategoryPlot

protected CategoryPlot(CategoryDataset data,
                       CategoryAxis domainAxis,
                       ValueAxis rangeAxis,
                       CategoryItemRenderer renderer)
Constructs a category plot, using default values where necessary.

Parameters:
data - The dataset.
domainAxis - The domain axis.
rangeAxis - The range axis.
renderer - The item renderer.

CategoryPlot

protected CategoryPlot(CategoryDataset data,
                       CategoryAxis domainAxis,
                       ValueAxis rangeAxis,
                       CategoryItemRenderer renderer,
                       java.awt.Insets insets,
                       java.awt.Paint backgroundPaint,
                       java.awt.Image backgroundImage,
                       float backgroundAlpha,
                       java.awt.Stroke outlineStroke,
                       java.awt.Paint outlinePaint,
                       float foregroundAlpha,
                       double introGapPercent,
                       double trailGapPercent,
                       double categoryGapsPercent,
                       double itemGapsPercent)
Constructs a category plot.

Parameters:
domainAxis - The domain axis.
rangeAxis - The range axis.
renderer - The item renderer.
insets - The insets for the plot.
backgroundPaint - An optional color for the plot's background.
backgroundImage - An optional image for the plot's background.
backgroundAlpha - Alpha-transparency for the plot's background.
outlineStroke - The stroke used to draw the plot outline.
outlinePaint - The paint used to draw the plot outline.
foregroundAlpha - The alpha transparency.
introGapPercent - The gap before the first item in the plot, as a percentage of the available drawing space.
trailGapPercent - The gap after the last item in the plot, as a percentage of the available drawing space.
categoryGapsPercent - The percentage of drawing space allocated to the gap between the last item in one category and the first item in the next category.
itemGapsPercent - The gap between items within the same category.
Method Detail

isSubplot

public boolean isSubplot()
Returns true if this plot is part of a combined plot structure, and false otherwise.

Overrides:
isSubplot in class Plot
Returns:
A flag indicating if this plot is a subplot.

getParent

public CategoryPlot getParent()
Returns the parent plot, or null if this is not a sub-plot.

Returns:
The parent plot.

setParent

public void setParent(CategoryPlot parent)
Sets the parent plot.

Only used if this plot is a sub-plot within a combination plot.

Parameters:
parent - The parent plot.

getSeriesCount

public int getSeriesCount()
Returns the number of series in this plot.

This gets used when the plot is part of a combined chart...there may be a better mechanism in the future.

Returns:
The series count.

getLegendItemLabels

public java.util.List getLegendItemLabels()
Returns a list of labels for the legend.

Specified by:
getLegendItemLabels in class Plot
Returns:
The list of labels.

getRenderer

public CategoryItemRenderer getRenderer()
Returns a reference to the renderer for the plot.

Returns:
The renderer.

setRenderer

public void setRenderer(CategoryItemRenderer renderer)
Sets the renderer for the plot.

If you set the renderer to null, no data will be plotted on the chart.

Parameters:
renderer - The renderer (null permitted).

getIntroGapPercent

public double getIntroGapPercent()
Returns the gap before the first bar on the chart, as a percentage of the available drawing space (0.05 = 5 percent).

Returns:
The "intro gap" (percentage).

setIntroGapPercent

public void setIntroGapPercent(double percent)
Sets the gap before the first bar on the chart, and notifies registered listeners that the plot has been modified.

Parameters:
percent - The new gap value, expressed as a percentage of the width of the plot area (0.05 = 5 percent).

getTrailGapPercent

public double getTrailGapPercent()
Returns the gap following the last bar on the chart, as a percentage of the available drawing space.

Returns:
The "trail gap" (percentage);

setTrailGapPercent

public void setTrailGapPercent(double percent)
Sets the gap after the last bar on the chart, and notifies registered listeners that the plot has been modified.

Parameters:
percent - The new gap value, expressed as a percentage of the width of the plot area (0.05 = 5 percent).

getCategoryGapsPercent

public double getCategoryGapsPercent()
Returns the percentage of the drawing space that is allocated to providing gaps between the categories.

Returns:
The "category gaps" (percentage).

setCategoryGapsPercent

public void setCategoryGapsPercent(double percent)
Sets the gap between the last bar in one category and the first bar in the next category, and notifies registered listeners that the plot has been modified.

Parameters:
percent - The new gap value, expressed as a percentage of the width of the plot area (0.05 = 5 percent).

getItemGapsPercent

public double getItemGapsPercent()
Returns the percentage of the drawing space that is allocated to providing gaps between the items in a category.

Returns:
The "item gaps" (percentage).

setItemGapsPercent

public void setItemGapsPercent(double percent)
Sets the gap between one bar and the next within the same category, and notifies registered listeners that the plot has been modified.

Parameters:
percent - The new gap value, expressed as a percentage of the width of the plot area (0.05 = 5 percent).

getCategoryDataset

public CategoryDataset getCategoryDataset()
A convenience method that returns the dataset for the plot, cast as a CategoryDataset.

Returns:
The dataset.

getDomainAxis

public CategoryAxis getDomainAxis()
Returns the domain axis for the plot. If the domain axis for this plot is null, then the method will return the parent plot's domain axis (if there is a parent plot).

Returns:
The domain axis.

setDomainAxis

public void setDomainAxis(CategoryAxis axis)
                   throws AxisNotCompatibleException
Sets the domain axis for the plot (this must be compatible with the plot type or an exception is thrown).

Parameters:
axis - The new axis.
Throws:
AxisNotCompatibleException

getRangeAxis

public ValueAxis getRangeAxis()
Returns the range axis for the plot. If the range axis for this plot is null, then the method will return the parent plot's range axis (if there is a parent plot).

Returns:
The range axis.

setRangeAxis

public void setRangeAxis(ValueAxis axis)
                  throws AxisNotCompatibleException
Sets the range axis for the plot.

An exception is thrown if the new axis and the plot are not mutually compatible.

Parameters:
axis - The new axis (null permitted).
Throws:
AxisNotCompatibleException

isCompatibleDomainAxis

public abstract boolean isCompatibleDomainAxis(CategoryAxis axis)
Checks the compatibility of a domain axis, returning true if the axis is compatible with the plot, and false otherwise.

Parameters:
axis - The proposed axis.
Returns:
True if the axis is compatible with the plot, and false otherwise.

isCompatibleRangeAxis

public abstract boolean isCompatibleRangeAxis(ValueAxis axis)
Checks the compatibility of a range axis, returning true if the axis is compatible with the plot, and false otherwise.

Parameters:
axis - The proposed axis.
Returns:
True if the axis is compatible with the plot, and false otherwise.

getCategoryCoordinate

public abstract double getCategoryCoordinate(int category,
                                             java.awt.geom.Rectangle2D area)
Returns the x or y coordinate (depending on the orientation of the plot) in Java 2D User Space of the center of the specified category.

Parameters:
category - The category (zero-based index).
area - The region within which the plot will be drawn.

zoom

public void zoom(double percent)
Zooms (in or out) on the plot's value axis.

If the value 0.0 is passed in as the zoom percent, the auto-range calculation for the axis is restored (which sets the range to include the minimum and maximum data values, thus displaying all the data).

Specified by:
zoom in class Plot
Parameters:
percent - The zoom amount.

setLabelsVisible

public void setLabelsVisible(boolean flag)
Sets the flag that indicates whether or not the value labels are showing.

Registered listeners are notified of a general change to the axis.

Parameters:
flag - The flag.

getLabelsVisible

public boolean getLabelsVisible()
Returns a flag that indicates whether or not the value labels are showing.

Returns:
The flag.

setLabelFont

public void setLabelFont(java.awt.Font font)
Sets the value label font.

Notifies registered listeners that the plot has been changed.

Parameters:
font - The new value label font.

getLabelFont

public java.awt.Font getLabelFont()
Returns the value label font.

Returns:
The value label font

setLabelPaint

public void setLabelPaint(java.awt.Paint paint)
Sets the value label paint.

Notifies registered listeners that the plot has been changed.

Parameters:
font - The new value label paint.

getLabelPaint

public java.awt.Paint getLabelPaint()
Returns the value label paint.

Returns:
The value label paint

setLabelFormatString

public void setLabelFormatString(java.lang.String format)
Sets the format string for the value labels.

Notifies registered listeners that the plot has been changed.

Parameters:
format - The new value label format pattern. Use null if labels are not to be shown

getLabelFormatter

public java.text.NumberFormat getLabelFormatter()
Returns the value label formatter.

Returns:
The value label formatter

setVerticalLabels

public void setVerticalLabels(boolean flag)
Sets the flag that determines the orientation of the value labels. Registered listeners are notified that the plot has been changed.

Parameters:
flag - The flag.

getVerticalLabels

public boolean getVerticalLabels()
Returns true if the value labels should be rotated to vertical, and false for standard horizontal labels.

Returns:
A flag indicating the orientation of the value labels.

datasetChanged

public void datasetChanged(DatasetChangeEvent event)
Receives notification of a change to the plot's dataset.

The chart reacts by passing on a chart change event to all registered listeners.

Specified by:
datasetChanged in interface DatasetChangeListener
Overrides:
datasetChanged in class Plot
Parameters:
event - Information about the event (not used here).

addRangeMarker

public void addRangeMarker(Marker marker)
Adds a marker for the range axis.

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

Parameters:
marker - The marker.


Copyright © 2003 MBARI.

The Monterey Bay Aquarium Research Institute (MBARI) provides this documentation and code "as is", with no warranty, express or implied, of its quality or consistency. It is provided without support and without obligation on the part of MBARI to assist in its use, correction, modification, or enhancement.