org.jfree.chart.renderer.xy

Class XYDifferenceRenderer

Implemented Interfaces:
Cloneable, LegendItemSource, PublicCloneable, Serializable, XYItemRenderer

public class XYDifferenceRenderer
extends AbstractXYItemRenderer
implements XYItemRenderer, Cloneable, PublicCloneable, Serializable

A renderer for an XYPlot that highlights the differences between two series. The renderer expects a dataset that:

Field Summary

Fields inherited from class org.jfree.chart.renderer.AbstractRenderer

DEFAULT_OUTLINE_PAINT, DEFAULT_OUTLINE_STROKE, DEFAULT_PAINT, DEFAULT_SHAPE, DEFAULT_STROKE, DEFAULT_VALUE_LABEL_FONT, DEFAULT_VALUE_LABEL_PAINT, ZERO

Constructor Summary

XYDifferenceRenderer()
Creates a new renderer with default attributes.
XYDifferenceRenderer(Paint positivePaint, Paint negativePaint, boolean shapes)
Creates a new renderer.

Method Summary

Object
clone()
Returns a clone of the renderer.
void
drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass)
Draws the visual representation of a single data item.
protected void
drawItemPass0(Graphics2D g2, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState)
Draws the visual representation of a single data item, first pass.
protected void
drawItemPass1(Graphics2D g2, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState)
Draws the visual representation of a single data item, second pass.
boolean
equals(Object obj)
Tests this renderer for equality with an arbitrary object.
LegendItem
getLegendItem(int datasetIndex, int series)
Returns a default legend item for the specified series.
Shape
getLegendLine()
Returns the shape used to represent a line in the legend.
protected Shape
getNegativeArea(float x0, float y0A, float y0B, float x1, float y1A, float y1B, PlotOrientation orientation)
Returns the negative area for a cross-over section.
Paint
getNegativePaint()
Returns the paint used to highlight negative differences.
int
getPassCount()
Returns 2, the number of passes required by the renderer.
protected Shape
getPositiveArea(float x0, float y0A, float y0B, float x1, float y1A, float y1B, PlotOrientation orientation)
Returns the positive area for a crossover point.
Paint
getPositivePaint()
Returns the paint used to highlight positive differences.
boolean
getRoundXCoordinates()
Returns the flag that controls whether or not the x-coordinates (in Java2D space) are rounded to integer values.
boolean
getShapesVisible()
Returns a flag that controls whether or not shapes are drawn for each data value.
XYItemRendererState
initialise(Graphics2D g2, Rectangle2D dataArea, XYPlot plot, XYDataset data, PlotRenderingInfo info)
Initialises the renderer and returns a state object that should be passed to subsequent calls to the drawItem() method.
void
setLegendLine(Shape line)
Sets the shape used as a line in each legend item and sends a RendererChangeEvent to all registered listeners.
void
setNegativePaint(Paint paint)
Sets the paint used to highlight negative differences.
void
setPositivePaint(Paint paint)
Sets the paint used to highlight positive differences.
void
setRoundXCoordinates(boolean round)
Sets the flag that controls whether or not the x-coordinates (in Java2D space) are rounded to integer values, and sends a RendererChangeEvent to all registered listeners.
void
setShapesVisible(boolean flag)
Sets a flag that controls whether or not shapes are drawn for each data value.

Methods inherited from class org.jfree.chart.renderer.xy.AbstractXYItemRenderer

addAnnotation, addAnnotation, addEntity, calculateDomainMarkerTextAnchorPoint, clone, drawAnnotations, drawDomainGridLine, drawDomainLine, drawDomainMarker, drawItemLabel, drawRangeLine, drawRangeMarker, equals, fillDomainGridBand, fillRangeGridBand, findDomainBounds, findRangeBounds, getBaseItemLabelGenerator, getBaseToolTipGenerator, getDefaultEntityRadius, getDrawingSupplier, getItemLabelGenerator, getItemLabelGenerator, getLegendItem, getLegendItemLabelGenerator, getLegendItemToolTipGenerator, getLegendItemURLGenerator, getLegendItems, getPassCount, getPlot, getSeriesItemLabelGenerator, getSeriesToolTipGenerator, getToolTipGenerator, getToolTipGenerator, getURLGenerator, initialise, removeAnnotation, removeAnnotations, setBaseItemLabelGenerator, setBaseToolTipGenerator, setDefaultEntityRadius, setItemLabelGenerator, setLegendItemLabelGenerator, setLegendItemToolTipGenerator, setLegendItemURLGenerator, setPlot, setSeriesItemLabelGenerator, setSeriesToolTipGenerator, setToolTipGenerator, setURLGenerator, updateCrosshairValues, updateCrosshairValues

Methods inherited from class org.jfree.chart.renderer.AbstractRenderer

addChangeListener, calculateLabelAnchorPoint, clone, equals, fireChangeEvent, getBaseCreateEntities, getBaseFillPaint, getBaseItemLabelFont, getBaseItemLabelPaint, getBaseItemLabelsVisible, getBaseNegativeItemLabelPosition, getBaseOutlinePaint, getBaseOutlineStroke, getBasePaint, getBasePositiveItemLabelPosition, getBaseSeriesVisible, getBaseSeriesVisibleInLegend, getBaseShape, getBaseStroke, getCreateEntities, getDrawingSupplier, getItemCreateEntity, getItemFillPaint, getItemLabelAnchorOffset, getItemLabelFont, getItemLabelFont, getItemLabelPaint, getItemLabelPaint, getItemOutlinePaint, getItemOutlineStroke, getItemPaint, getItemShape, getItemStroke, getItemVisible, getNegativeItemLabelPosition, getNegativeItemLabelPosition, getPositiveItemLabelPosition, getPositiveItemLabelPosition, getSeriesCreateEntities, getSeriesFillPaint, getSeriesItemLabelFont, getSeriesItemLabelPaint, getSeriesNegativeItemLabelPosition, getSeriesOutlinePaint, getSeriesOutlineStroke, getSeriesPaint, getSeriesPositiveItemLabelPosition, getSeriesShape, getSeriesStroke, getSeriesVisible, getSeriesVisible, getSeriesVisibleInLegend, getSeriesVisibleInLegend, hasListener, hashCode, isItemLabelVisible, isSeriesItemLabelsVisible, isSeriesVisible, isSeriesVisibleInLegend, notifyListeners, removeChangeListener, setBaseCreateEntities, setBaseCreateEntities, setBaseFillPaint, setBaseFillPaint, setBaseItemLabelFont, setBaseItemLabelFont, setBaseItemLabelPaint, setBaseItemLabelPaint, setBaseItemLabelsVisible, setBaseItemLabelsVisible, setBaseItemLabelsVisible, setBaseNegativeItemLabelPosition, setBaseNegativeItemLabelPosition, setBaseOutlinePaint, setBaseOutlinePaint, setBaseOutlineStroke, setBaseOutlineStroke, setBasePaint, setBasePaint, setBasePositiveItemLabelPosition, setBasePositiveItemLabelPosition, setBaseSeriesVisible, setBaseSeriesVisible, setBaseSeriesVisibleInLegend, setBaseSeriesVisibleInLegend, setBaseShape, setBaseShape, setBaseStroke, setBaseStroke, setCreateEntities, setCreateEntities, setFillPaint, setFillPaint, setItemLabelAnchorOffset, setItemLabelFont, setItemLabelFont, setItemLabelPaint, setItemLabelPaint, setItemLabelsVisible, setItemLabelsVisible, setItemLabelsVisible, setNegativeItemLabelPosition, setNegativeItemLabelPosition, setOutlinePaint, setOutlinePaint, setOutlineStroke, setOutlineStroke, setPaint, setPaint, setPositiveItemLabelPosition, setPositiveItemLabelPosition, setSeriesCreateEntities, setSeriesCreateEntities, setSeriesFillPaint, setSeriesFillPaint, setSeriesItemLabelFont, setSeriesItemLabelFont, setSeriesItemLabelPaint, setSeriesItemLabelPaint, setSeriesItemLabelsVisible, setSeriesItemLabelsVisible, setSeriesItemLabelsVisible, setSeriesNegativeItemLabelPosition, setSeriesNegativeItemLabelPosition, setSeriesOutlinePaint, setSeriesOutlinePaint, setSeriesOutlineStroke, setSeriesOutlineStroke, setSeriesPaint, setSeriesPaint, setSeriesPositiveItemLabelPosition, setSeriesPositiveItemLabelPosition, setSeriesShape, setSeriesShape, setSeriesStroke, setSeriesStroke, setSeriesVisible, setSeriesVisible, setSeriesVisible, setSeriesVisible, setSeriesVisibleInLegend, setSeriesVisibleInLegend, setSeriesVisibleInLegend, setSeriesVisibleInLegend, setShape, setShape, setStroke, setStroke

Constructor Details

XYDifferenceRenderer

public XYDifferenceRenderer()
Creates a new renderer with default attributes.

XYDifferenceRenderer

public XYDifferenceRenderer(Paint positivePaint,
                            Paint negativePaint,
                            boolean shapes)
Creates a new renderer.
Parameters:
positivePaint - the highlight color for positive differences (null not permitted).
negativePaint - the highlight color for negative differences (null not permitted).
shapes - draw shapes?

Method Details

clone

public Object clone()
            throws CloneNotSupportedException
Returns a clone of the renderer.
Overrides:
clone in interface AbstractXYItemRenderer
Returns:
A clone.

drawItem

public void drawItem(Graphics2D g2,
                     XYItemRendererState state,
                     Rectangle2D dataArea,
                     PlotRenderingInfo info,
                     XYPlot plot,
                     ValueAxis domainAxis,
                     ValueAxis rangeAxis,
                     XYDataset dataset,
                     int series,
                     int item,
                     CrosshairState crosshairState,
                     int pass)
Draws the visual representation of a single data item.
Specified by:
drawItem in interface XYItemRenderer
Parameters:
g2 - the graphics device.
state - the renderer state.
dataArea - the area within which the data is being drawn.
info - collects information about the drawing.
plot - the plot (can be used to obtain standard color information etc).
domainAxis - the domain (horizontal) axis.
rangeAxis - the range (vertical) axis.
dataset - the dataset.
series - the series index (zero-based).
item - the item index (zero-based).
crosshairState - crosshair information for the plot (null permitted).
pass - the pass index.

drawItemPass0

protected void drawItemPass0(Graphics2D g2,
                             Rectangle2D dataArea,
                             PlotRenderingInfo info,
                             XYPlot plot,
                             ValueAxis domainAxis,
                             ValueAxis rangeAxis,
                             XYDataset dataset,
                             int series,
                             int item,
                             CrosshairState crosshairState)
Draws the visual representation of a single data item, first pass.
Parameters:
g2 - the graphics device.
dataArea - the area within which the data is being drawn.
info - collects information about the drawing.
plot - the plot (can be used to obtain standard color information etc).
domainAxis - the domain (horizontal) axis.
rangeAxis - the range (vertical) axis.
dataset - the dataset.
series - the series index (zero-based).
item - the item index (zero-based).
crosshairState - crosshair information for the plot (null permitted).

drawItemPass1

protected void drawItemPass1(Graphics2D g2,
                             Rectangle2D dataArea,
                             PlotRenderingInfo info,
                             XYPlot plot,
                             ValueAxis domainAxis,
                             ValueAxis rangeAxis,
                             XYDataset dataset,
                             int series,
                             int item,
                             CrosshairState crosshairState)
Draws the visual representation of a single data item, second pass. In the second pass, the renderer draws the lines and shapes for the individual points in the two series.
Parameters:
g2 - the graphics device.
dataArea - the area within which the data is being drawn.
info - collects information about the drawing.
plot - the plot (can be used to obtain standard color information etc).
domainAxis - the domain (horizontal) axis.
rangeAxis - the range (vertical) axis.
dataset - the dataset.
series - the series index (zero-based).
item - the item index (zero-based).
crosshairState - crosshair information for the plot (null permitted).

equals

public boolean equals(Object obj)
Tests this renderer for equality with an arbitrary object.
Overrides:
equals in interface AbstractXYItemRenderer
Parameters:
obj - the object (null permitted).
Returns:
A boolean.

getLegendItem

public LegendItem getLegendItem(int datasetIndex,
                                int series)
Returns a default legend item for the specified series. Subclasses should override this method to generate customised items.
Specified by:
getLegendItem in interface XYItemRenderer
Overrides:
getLegendItem in interface AbstractXYItemRenderer
Parameters:
datasetIndex - the dataset index (zero-based).
series - the series index (zero-based).
Returns:
A legend item for the series.

getLegendLine

public Shape getLegendLine()
Returns the shape used to represent a line in the legend.
Returns:
The legend line (never null).

getNegativeArea

protected Shape getNegativeArea(float x0,
                                float y0A,
                                float y0B,
                                float x1,
                                float y1A,
                                float y1B,
                                PlotOrientation orientation)
Returns the negative area for a cross-over section.
Parameters:
x0 - x coordinate.
y0A - y coordinate A.
y0B - y coordinate B.
x1 - x coordinate.
y1A - y coordinate A.
y1B - y coordinate B.
orientation - the plot orientation.
Returns:
The negative area.

getNegativePaint

public Paint getNegativePaint()
Returns the paint used to highlight negative differences.
Returns:
The paint (never null).

getPassCount

public int getPassCount()
Returns 2, the number of passes required by the renderer. The XYPlot will run through the dataset this number of times.
Specified by:
getPassCount in interface XYItemRenderer
Overrides:
getPassCount in interface AbstractXYItemRenderer
Returns:
The number of passes required by the renderer.

getPositiveArea

protected Shape getPositiveArea(float x0,
                                float y0A,
                                float y0B,
                                float x1,
                                float y1A,
                                float y1B,
                                PlotOrientation orientation)
Returns the positive area for a crossover point.
Parameters:
x0 - x coordinate.
y0A - y coordinate A.
y0B - y coordinate B.
x1 - x coordinate.
y1A - y coordinate A.
y1B - y coordinate B.
orientation - the plot orientation.
Returns:
The positive area.

getPositivePaint

public Paint getPositivePaint()
Returns the paint used to highlight positive differences.
Returns:
The paint (never null).

getRoundXCoordinates

public boolean getRoundXCoordinates()
Returns the flag that controls whether or not the x-coordinates (in Java2D space) are rounded to integer values.
Returns:
The flag.
Since:
1.0.4

getShapesVisible

public boolean getShapesVisible()
Returns a flag that controls whether or not shapes are drawn for each data value.
Returns:
A boolean.

initialise

public XYItemRendererState initialise(Graphics2D g2,
                                      Rectangle2D dataArea,
                                      XYPlot plot,
                                      XYDataset data,
                                      PlotRenderingInfo info)
Initialises the renderer and returns a state object that should be passed to subsequent calls to the drawItem() method. This method will be called before the first item is rendered, giving the renderer an opportunity to initialise any state information it wants to maintain. The renderer can do nothing if it chooses.
Specified by:
initialise in interface XYItemRenderer
Overrides:
initialise in interface AbstractXYItemRenderer
Parameters:
g2 - the graphics device.
dataArea - the area inside the axes.
plot - the plot.
data - the data.
info - an optional info collection object to return data back to the caller.
Returns:
A state object.

setLegendLine

public void setLegendLine(Shape line)
Sets the shape used as a line in each legend item and sends a RendererChangeEvent to all registered listeners.
Parameters:
line - the line (null not permitted).

setNegativePaint

public void setNegativePaint(Paint paint)
Sets the paint used to highlight negative differences.
Parameters:
paint - the paint (null not permitted).

setPositivePaint

public void setPositivePaint(Paint paint)
Sets the paint used to highlight positive differences.
Parameters:
paint - the paint (null not permitted).

setRoundXCoordinates

public void setRoundXCoordinates(boolean round)
Sets the flag that controls whether or not the x-coordinates (in Java2D space) are rounded to integer values, and sends a RendererChangeEvent to all registered listeners.
Parameters:
round - the new flag value.
Since:
1.0.4

setShapesVisible

public void setShapesVisible(boolean flag)
Sets a flag that controls whether or not shapes are drawn for each data value.
Parameters:
flag - the flag.