A renderer that connects data points with lines and/or draws shapes at each
data point. This renderer is designed for use with the
| Method from org.jfree.chart.renderer.xy.XYLineAndShapeRenderer Detail: |
public Object clone() throws CloneNotSupportedException {
XYLineAndShapeRenderer clone = (XYLineAndShapeRenderer) super.clone();
clone.seriesLinesVisible
= (BooleanList) this.seriesLinesVisible.clone();
if (this.legendLine != null) {
clone.legendLine = ShapeUtilities.clone(this.legendLine);
}
clone.seriesShapesVisible
= (BooleanList) this.seriesShapesVisible.clone();
clone.seriesShapesFilled
= (BooleanList) this.seriesShapesFilled.clone();
return clone;
}
Returns a clone of the renderer. |
protected void drawFirstPassShape(Graphics2D g2,
int pass,
int series,
int item,
Shape shape) {
g2.setStroke(getItemStroke(series, item));
g2.setPaint(getItemPaint(series, item));
g2.draw(shape);
}
Draws the first pass shape. |
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) {
// do nothing if item is not visible
if (!getItemVisible(series, item)) {
return;
}
// first pass draws the background (lines, for instance)
if (isLinePass(pass)) {
if (item == 0) {
if (this.drawSeriesLineAsPath) {
State s = (State) state;
s.seriesPath.reset();
s.lastPointGood = false;
}
}
if (getItemLineVisible(series, item)) {
if (this.drawSeriesLineAsPath) {
drawPrimaryLineAsPath(state, g2, plot, dataset, pass,
series, item, domainAxis, rangeAxis, dataArea);
}
else {
drawPrimaryLine(state, g2, plot, dataset, pass, series,
item, domainAxis, rangeAxis, dataArea);
}
}
}
// second pass adds shapes where the items are ..
else if (isItemPass(pass)) {
// setup for collecting optional entity info...
EntityCollection entities = null;
if (info != null) {
entities = info.getOwner().getEntityCollection();
}
drawSecondaryPass(g2, plot, dataset, pass, series, item,
domainAxis, dataArea, rangeAxis, crosshairState, entities);
}
}
Draws the visual representation of a single data item. |
protected void drawPrimaryLine(XYItemRendererState state,
Graphics2D g2,
XYPlot plot,
XYDataset dataset,
int pass,
int series,
int item,
ValueAxis domainAxis,
ValueAxis rangeAxis,
Rectangle2D dataArea) {
if (item == 0) {
return;
}
// get the data point...
double x1 = dataset.getXValue(series, item);
double y1 = dataset.getYValue(series, item);
if (Double.isNaN(y1) || Double.isNaN(x1)) {
return;
}
double x0 = dataset.getXValue(series, item - 1);
double y0 = dataset.getYValue(series, item - 1);
if (Double.isNaN(y0) || Double.isNaN(x0)) {
return;
}
RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);
double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);
// only draw if we have good values
if (Double.isNaN(transX0) || Double.isNaN(transY0)
|| Double.isNaN(transX1) || Double.isNaN(transY1)) {
return;
}
PlotOrientation orientation = plot.getOrientation();
if (orientation == PlotOrientation.HORIZONTAL) {
state.workingLine.setLine(transY0, transX0, transY1, transX1);
}
else if (orientation == PlotOrientation.VERTICAL) {
state.workingLine.setLine(transX0, transY0, transX1, transY1);
}
if (state.workingLine.intersects(dataArea)) {
drawFirstPassShape(g2, pass, series, item, state.workingLine);
}
}
Draws the item (first pass). This method draws the lines
connecting the items. |
protected void drawPrimaryLineAsPath(XYItemRendererState state,
Graphics2D g2,
XYPlot plot,
XYDataset dataset,
int pass,
int series,
int item,
ValueAxis domainAxis,
ValueAxis rangeAxis,
Rectangle2D dataArea) {
RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
// get the data point...
double x1 = dataset.getXValue(series, item);
double y1 = dataset.getYValue(series, item);
double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);
State s = (State) state;
// update path to reflect latest point
if (!Double.isNaN(transX1) && !Double.isNaN(transY1)) {
float x = (float) transX1;
float y = (float) transY1;
PlotOrientation orientation = plot.getOrientation();
if (orientation == PlotOrientation.HORIZONTAL) {
x = (float) transY1;
y = (float) transX1;
}
if (s.isLastPointGood()) {
s.seriesPath.lineTo(x, y);
}
else {
s.seriesPath.moveTo(x, y);
}
s.setLastPointGood(true);
}
else {
s.setLastPointGood(false);
}
// if this is the last item, draw the path ...
if (item == dataset.getItemCount(series) - 1) {
// draw path
drawFirstPassShape(g2, pass, series, item, s.seriesPath);
}
}
Draws the item (first pass). This method draws the lines
connecting the items. Instead of drawing separate lines,
a GeneralPath is constructed and drawn at the end of
the series painting. |
protected void drawSecondaryPass(Graphics2D g2,
XYPlot plot,
XYDataset dataset,
int pass,
int series,
int item,
ValueAxis domainAxis,
Rectangle2D dataArea,
ValueAxis rangeAxis,
CrosshairState crosshairState,
EntityCollection entities) {
Shape entityArea = null;
// get the data point...
double x1 = dataset.getXValue(series, item);
double y1 = dataset.getYValue(series, item);
if (Double.isNaN(y1) || Double.isNaN(x1)) {
return;
}
PlotOrientation orientation = plot.getOrientation();
RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);
if (getItemShapeVisible(series, item)) {
Shape shape = getItemShape(series, item);
if (orientation == PlotOrientation.HORIZONTAL) {
shape = ShapeUtilities.createTranslatedShape(shape, transY1,
transX1);
}
else if (orientation == PlotOrientation.VERTICAL) {
shape = ShapeUtilities.createTranslatedShape(shape, transX1,
transY1);
}
entityArea = shape;
if (shape.intersects(dataArea)) {
if (getItemShapeFilled(series, item)) {
if (this.useFillPaint) {
g2.setPaint(getItemFillPaint(series, item));
}
else {
g2.setPaint(getItemPaint(series, item));
}
g2.fill(shape);
}
if (this.drawOutlines) {
if (getUseOutlinePaint()) {
g2.setPaint(getItemOutlinePaint(series, item));
}
else {
g2.setPaint(getItemPaint(series, item));
}
g2.setStroke(getItemOutlineStroke(series, item));
g2.draw(shape);
}
}
}
double xx = transX1;
double yy = transY1;
if (orientation == PlotOrientation.HORIZONTAL) {
xx = transY1;
yy = transX1;
}
// draw the item label if there is one...
if (isItemLabelVisible(series, item)) {
drawItemLabel(g2, orientation, dataset, series, item, xx, yy,
(y1 < 0.0));
}
int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex,
rangeAxisIndex, transX1, transY1, orientation);
// add an entity for the item, but only if it falls within the data
// area...
if (entities != null && isPointInRect(dataArea, xx, yy)) {
addEntity(entities, entityArea, dataset, series, item, xx, yy);
}
}
Draws the item shapes and adds chart entities (second pass). This method
draws the shapes which mark the item positions. If entities
is not null it will be populated with entity information
for points that fall within the data area. |
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof XYLineAndShapeRenderer)) {
return false;
}
if (!super.equals(obj)) {
return false;
}
XYLineAndShapeRenderer that = (XYLineAndShapeRenderer) obj;
if (!ObjectUtilities.equal(this.linesVisible, that.linesVisible)) {
return false;
}
if (!ObjectUtilities.equal(
this.seriesLinesVisible, that.seriesLinesVisible)
) {
return false;
}
if (this.baseLinesVisible != that.baseLinesVisible) {
return false;
}
if (!ShapeUtilities.equal(this.legendLine, that.legendLine)) {
return false;
}
if (!ObjectUtilities.equal(this.shapesVisible, that.shapesVisible)) {
return false;
}
if (!ObjectUtilities.equal(
this.seriesShapesVisible, that.seriesShapesVisible)
) {
return false;
}
if (this.baseShapesVisible != that.baseShapesVisible) {
return false;
}
if (!ObjectUtilities.equal(this.shapesFilled, that.shapesFilled)) {
return false;
}
if (!ObjectUtilities.equal(
this.seriesShapesFilled, that.seriesShapesFilled)
) {
return false;
}
if (this.baseShapesFilled != that.baseShapesFilled) {
return false;
}
if (this.drawOutlines != that.drawOutlines) {
return false;
}
if (this.useOutlinePaint != that.useOutlinePaint) {
return false;
}
if (this.useFillPaint != that.useFillPaint) {
return false;
}
if (this.drawSeriesLineAsPath != that.drawSeriesLineAsPath) {
return false;
}
return true;
}
Tests this renderer for equality with an arbitrary object. |
public boolean getBaseLinesVisible() {
return this.baseLinesVisible;
}
Returns the base 'lines visible' attribute. |
public boolean getBaseShapesFilled() {
return this.baseShapesFilled;
}
Returns the base 'shape filled' attribute. |
public boolean getBaseShapesVisible() {
return this.baseShapesVisible;
}
Returns the base 'shape visible' attribute. |
public boolean getDrawOutlines() {
return this.drawOutlines;
}
Returns true if outlines should be drawn for shapes, and
false otherwise. |
public boolean getDrawSeriesLineAsPath() {
return this.drawSeriesLineAsPath;
}
Returns a flag that controls whether or not each series is drawn as a
single path. |
public boolean getItemLineVisible(int series,
int item) {
Boolean flag = this.linesVisible;
if (flag == null) {
flag = getSeriesLinesVisible(series);
}
if (flag != null) {
return flag.booleanValue();
}
else {
return this.baseLinesVisible;
}
}
Returns the flag used to control whether or not the shape for an item is
visible. |
public boolean getItemShapeFilled(int series,
int item) {
Boolean flag = this.shapesFilled;
if (flag == null) {
flag = getSeriesShapesFilled(series);
}
if (flag != null) {
return flag.booleanValue();
}
else {
return this.baseShapesFilled;
}
}
Returns the flag used to control whether or not the shape for an item
is filled.
The default implementation passes control to the
getSeriesShapesFilled method. You can override this method
if you require different behaviour. |
public boolean getItemShapeVisible(int series,
int item) {
Boolean flag = this.shapesVisible;
if (flag == null) {
flag = getSeriesShapesVisible(series);
}
if (flag != null) {
return flag.booleanValue();
}
else {
return this.baseShapesVisible;
}
}
Returns the flag used to control whether or not the shape for an item is
visible.
The default implementation passes control to the
getSeriesShapesVisible method. You can override this method
if you require different behaviour. |
public LegendItem getLegendItem(int datasetIndex,
int series) {
XYPlot plot = getPlot();
if (plot == null) {
return null;
}
LegendItem result = null;
XYDataset dataset = plot.getDataset(datasetIndex);
if (dataset != null) {
if (getItemVisible(series, 0)) {
String label = getLegendItemLabelGenerator().generateLabel(
dataset, series);
String description = label;
String toolTipText = null;
if (getLegendItemToolTipGenerator() != null) {
toolTipText = getLegendItemToolTipGenerator().generateLabel(
dataset, series);
}
String urlText = null;
if (getLegendItemURLGenerator() != null) {
urlText = getLegendItemURLGenerator().generateLabel(
dataset, series);
}
boolean shapeIsVisible = getItemShapeVisible(series, 0);
Shape shape = lookupSeriesShape(series);
boolean shapeIsFilled = getItemShapeFilled(series, 0);
Paint fillPaint = (this.useFillPaint
? lookupSeriesFillPaint(series)
: lookupSeriesPaint(series));
boolean shapeOutlineVisible = this.drawOutlines;
Paint outlinePaint = (this.useOutlinePaint
? lookupSeriesOutlinePaint(series)
: lookupSeriesPaint(series));
Stroke outlineStroke = lookupSeriesOutlineStroke(series);
boolean lineVisible = getItemLineVisible(series, 0);
Stroke lineStroke = lookupSeriesStroke(series);
Paint linePaint = lookupSeriesPaint(series);
result = new LegendItem(label, description, toolTipText,
urlText, shapeIsVisible, shape, shapeIsFilled,
fillPaint, shapeOutlineVisible, outlinePaint,
outlineStroke, lineVisible, this.legendLine,
lineStroke, linePaint);
result.setSeriesKey(dataset.getSeriesKey(series));
result.setSeriesIndex(series);
result.setDataset(dataset);
result.setDatasetIndex(datasetIndex);
}
}
return result;
}
Returns a legend item for the specified series. |
public Shape getLegendLine() {
return this.legendLine;
}
Returns the shape used to represent a line in the legend. |
public Boolean getLinesVisible() {
return this.linesVisible;
} Deprecated! As - of 1.0.7, use the per-series and base level settings.
Returns a flag that controls whether or not lines are drawn for ALL
series. If this flag is null, then the "per series"
settings will apply. |
public int getPassCount() {
return 2;
}
Returns the number of passes through the data that the renderer requires
in order to draw the chart. Most charts will require a single pass, but
some require two passes. |
public Boolean getSeriesLinesVisible(int series) {
return this.seriesLinesVisible.getBoolean(series);
}
Returns the flag used to control whether or not the lines for a series
are visible. |
public Boolean getSeriesShapesFilled(int series) {
return this.seriesShapesFilled.getBoolean(series);
}
Returns the flag used to control whether or not the shapes for a series
are filled. |
public Boolean getSeriesShapesVisible(int series) {
return this.seriesShapesVisible.getBoolean(series);
}
Returns the flag used to control whether or not the shapes for a series
are visible. |
public Boolean getShapesVisible() {
return this.shapesVisible;
} Deprecated! As - of 1.0.7, use the per-series and base level settings.
Returns the flag that controls whether the shapes are visible for the
items in ALL series. |
public boolean getUseFillPaint() {
return this.useFillPaint;
}
|
public boolean getUseOutlinePaint() {
return this.useOutlinePaint;
}
Returns true if the renderer should use the outline paint
setting to draw shape outlines, and false if it should just
use the regular paint. |
public XYItemRendererState initialise(Graphics2D g2,
Rectangle2D dataArea,
XYPlot plot,
XYDataset data,
PlotRenderingInfo info) {
State state = new State(info);
state.seriesPath = new GeneralPath();
return state;
}
Initialises the renderer.
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. |
protected boolean isItemPass(int pass) {
return pass == 1;
}
Returns true if the specified pass is the one for drawing
items. |
protected boolean isLinePass(int pass) {
return pass == 0;
}
Returns true if the specified pass is the one for drawing
lines. |
public void setBaseLinesVisible(boolean flag) {
this.baseLinesVisible = flag;
fireChangeEvent();
}
Sets the base 'lines visible' flag and sends a
RendererChangeEvent to all registered listeners. |
public void setBaseShapesFilled(boolean flag) {
this.baseShapesFilled = flag;
fireChangeEvent();
}
Sets the base 'shapes filled' flag and sends a
RendererChangeEvent to all registered listeners. |
public void setBaseShapesVisible(boolean flag) {
this.baseShapesVisible = flag;
fireChangeEvent();
}
Sets the base 'shapes visible' flag and sends a
RendererChangeEvent to all registered listeners. |
public void setDrawOutlines(boolean flag) {
this.drawOutlines = flag;
fireChangeEvent();
}
Sets the flag that controls whether outlines are drawn for
shapes, and sends a RendererChangeEvent to all registered
listeners.
In some cases, shapes look better if they do NOT have an outline, but
this flag allows you to set your own preference. |
public void setDrawSeriesLineAsPath(boolean flag) {
if (this.drawSeriesLineAsPath != flag) {
this.drawSeriesLineAsPath = flag;
fireChangeEvent();
}
}
Sets the flag that controls whether or not each series is drawn as a
single path and sends a RendererChangeEvent to all registered
listeners. |
public void setLegendLine(Shape line) {
if (line == null) {
throw new IllegalArgumentException("Null 'line' argument.");
}
this.legendLine = line;
fireChangeEvent();
}
Sets the shape used as a line in each legend item and sends a
RendererChangeEvent to all registered listeners. |
public void setLinesVisible(Boolean visible) {
this.linesVisible = visible;
fireChangeEvent();
} Deprecated! As - of 1.0.7, use the per-series and base level settings.
Sets a flag that controls whether or not lines are drawn between the
items in ALL series, and sends a RendererChangeEvent to all
registered listeners. You need to set this to null if you
want the "per series" settings to apply. |
public void setLinesVisible(boolean visible) {
// we use BooleanUtilities here to preserve JRE 1.3.1 compatibility
setLinesVisible(BooleanUtilities.valueOf(visible));
} Deprecated! As - of 1.0.7, use the per-series and base level settings.
Sets a flag that controls whether or not lines are drawn between the
items in ALL series, and sends a RendererChangeEvent to all
registered listeners. |
public void setSeriesLinesVisible(int series,
Boolean flag) {
this.seriesLinesVisible.setBoolean(series, flag);
fireChangeEvent();
}
Sets the 'lines visible' flag for a series and sends a
RendererChangeEvent to all registered listeners. |
public void setSeriesLinesVisible(int series,
boolean visible) {
setSeriesLinesVisible(series, BooleanUtilities.valueOf(visible));
}
Sets the 'lines visible' flag for a series and sends a
RendererChangeEvent to all registered listeners. |
public void setSeriesShapesFilled(int series,
boolean flag) {
setSeriesShapesFilled(series, BooleanUtilities.valueOf(flag));
}
Sets the 'shapes filled' flag for a series and sends a
RendererChangeEvent to all registered listeners. |
public void setSeriesShapesFilled(int series,
Boolean flag) {
this.seriesShapesFilled.setBoolean(series, flag);
fireChangeEvent();
}
Sets the 'shapes filled' flag for a series and sends a
RendererChangeEvent to all registered listeners. |
public void setSeriesShapesVisible(int series,
boolean visible) {
setSeriesShapesVisible(series, BooleanUtilities.valueOf(visible));
}
Sets the 'shapes visible' flag for a series and sends a
RendererChangeEvent to all registered listeners. |
public void setSeriesShapesVisible(int series,
Boolean flag) {
this.seriesShapesVisible.setBoolean(series, flag);
fireChangeEvent();
}
Sets the 'shapes visible' flag for a series and sends a
RendererChangeEvent to all registered listeners. |
public void setShapesFilled(boolean filled) {
setShapesFilled(BooleanUtilities.valueOf(filled));
} Deprecated! As - of 1.0.7, use the per-series and base level settings.
Sets the 'shapes filled' for ALL series and sends a
RendererChangeEvent to all registered listeners. |
public void setShapesFilled(Boolean filled) {
this.shapesFilled = filled;
fireChangeEvent();
} Deprecated! As - of 1.0.7, use the per-series and base level settings.
Sets the 'shapes filled' for ALL series and sends a
RendererChangeEvent to all registered listeners. |
public void setShapesVisible(Boolean visible) {
this.shapesVisible = visible;
fireChangeEvent();
} Deprecated! As - of 1.0.7, use the per-series and base level settings.
Sets the 'shapes visible' for ALL series and sends a
RendererChangeEvent to all registered listeners. |
public void setShapesVisible(boolean visible) {
setShapesVisible(BooleanUtilities.valueOf(visible));
} Deprecated! As - of 1.0.7, use the per-series and base level settings.
Sets the 'shapes visible' for ALL series and sends a
RendererChangeEvent to all registered listeners. |
public void setUseFillPaint(boolean flag) {
this.useFillPaint = flag;
fireChangeEvent();
}
Sets the flag that controls whether the fill paint is used to fill
shapes, and sends a RendererChangeEvent to all
registered listeners. |
public void setUseOutlinePaint(boolean flag) {
this.useOutlinePaint = flag;
fireChangeEvent();
}
|