public void drawItem(Graphics2D g2,
CategoryItemRendererState state,
Rectangle2D dataArea,
CategoryPlot plot,
CategoryAxis domainAxis,
ValueAxis rangeAxis,
CategoryDataset dataset,
int row,
int column,
int pass) {
// do nothing if item is not visible
if (!getItemVisible(row, column)) {
return;
}
Number value = dataset.getValue(row, column);
if (value == null) {
return;
}
PlotOrientation orientation = plot.getOrientation();
// current data point...
double x1s = domainAxis.getCategoryStart(column, getColumnCount(),
dataArea, plot.getDomainAxisEdge());
double x1 = domainAxis.getCategoryMiddle(column, getColumnCount(),
dataArea, plot.getDomainAxisEdge());
double x1e = 2 * x1 - x1s; // or: x1s + 2*(x1-x1s)
double y1 = rangeAxis.valueToJava2D(value.doubleValue(), dataArea,
plot.getRangeAxisEdge());
g2.setPaint(getItemPaint(row, column));
g2.setStroke(getItemStroke(row, column));
if (column != 0) {
Number previousValue = dataset.getValue(row, column - 1);
if (previousValue != null) {
// previous data point...
double previous = previousValue.doubleValue();
double x0s = domainAxis.getCategoryStart(column - 1,
getColumnCount(), dataArea, plot.getDomainAxisEdge());
double x0 = domainAxis.getCategoryMiddle(column - 1,
getColumnCount(), dataArea, plot.getDomainAxisEdge());
double x0e = 2 * x0 - x0s; // or: x0s + 2*(x0-x0s)
double y0 = rangeAxis.valueToJava2D(previous, dataArea,
plot.getRangeAxisEdge());
if (getStagger()) {
int xStagger = row * STAGGER_WIDTH;
if (xStagger > (x1s - x0e)) {
xStagger = (int) (x1s - x0e);
}
x1s = x0e + xStagger;
}
drawLine(g2, (State) state, orientation, x0e, y0, x1s, y0);
// extend x0's flat bar
drawLine(g2, (State) state, orientation, x1s, y0, x1s, y1);
// upright bar
}
}
drawLine(g2, (State) state, orientation, x1s, y1, x1e, y1);
// x1's flat bar
// draw the item labels if there are any...
if (isItemLabelVisible(row, column)) {
drawItemLabel(g2, orientation, dataset, row, column, x1, y1,
(value.doubleValue() < 0.0));
}
// add an item entity, if this information is being collected
EntityCollection entities = state.getEntityCollection();
if (entities != null) {
Rectangle2D hotspot = new Rectangle2D.Double();
if (orientation == PlotOrientation.VERTICAL) {
hotspot.setRect(x1s, y1, x1e - x1s, 4.0);
}
else {
hotspot.setRect(y1 - 2.0, x1s, 4.0, x1e - x1s);
}
addItemEntity(entities, dataset, row, column, hotspot);
}
}
|
protected void drawLine(Graphics2D g2,
CategoryStepRenderer.State state,
PlotOrientation orientation,
double x0,
double y0,
double x1,
double y1) {
if (orientation == PlotOrientation.VERTICAL) {
state.line.setLine(x0, y0, x1, y1);
g2.draw(state.line);
}
else if (orientation == PlotOrientation.HORIZONTAL) {
state.line.setLine(y0, x0, y1, x1); // switch x and y
g2.draw(state.line);
}
}
Draws a line taking into account the specified orientation.
In version 1.0.5, the signature of this method was changed by the
addition of the 'state' parameter. This is an incompatible change, but
is considered a low risk because it is unlikely that anyone has
subclassed this renderer. If this *does* cause trouble for you, please
report it as a bug. |
public LegendItem getLegendItem(int datasetIndex,
int series) {
CategoryPlot p = getPlot();
if (p == null) {
return null;
}
// check that a legend item needs to be displayed...
if (!isSeriesVisible(series) || !isSeriesVisibleInLegend(series)) {
return null;
}
CategoryDataset dataset = p.getDataset(datasetIndex);
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);
}
Shape shape = new Rectangle2D.Double(-4.0, -3.0, 8.0, 6.0);
Paint paint = lookupSeriesPaint(series);
LegendItem item = new LegendItem(label, description, toolTipText,
urlText, shape, paint);
item.setSeriesKey(dataset.getRowKey(series));
item.setSeriesIndex(series);
item.setDataset(dataset);
item.setDatasetIndex(datasetIndex);
return item;
}
Returns a legend item for a series. |