use of org.jfree.chart.entity.EntityCollection in project hudson-2.x by hudson.
the class StackedAreaRenderer2 method drawItem.
// Mostly copied from the base class.
@Override
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {
// plot non-null values...
Number dataValue = dataset.getValue(row, column);
if (dataValue == null) {
return;
}
double value = dataValue.doubleValue();
// leave the y values (y1, y0) untranslated as it is going to be be
// stacked up later by previous series values, after this it will be
// translated.
double xx1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
double previousHeightx1 = getPreviousHeight(dataset, row, column);
double y1 = value + previousHeightx1;
RectangleEdge location = plot.getRangeAxisEdge();
double yy1 = rangeAxis.valueToJava2D(y1, dataArea, location);
g2.setPaint(getItemPaint(row, column));
g2.setStroke(getItemStroke(row, column));
// add an item entity, if this information is being collected
EntityCollection entities = state.getEntityCollection();
// and this is done in the second pass...
if (column == 0) {
if (pass == 1) {
// draw item labels, if visible
if (isItemLabelVisible(row, column)) {
drawItemLabel(g2, plot.getOrientation(), dataset, row, column, xx1, yy1, (y1 < 0.0));
}
}
} else {
Number previousValue = dataset.getValue(row, column - 1);
if (previousValue != null) {
double xx0 = domainAxis.getCategoryMiddle(column - 1, getColumnCount(), dataArea, plot.getDomainAxisEdge());
double y0 = previousValue.doubleValue();
// Get the previous height, but this will be different for both
// y0 and y1 as the previous series values could differ.
double previousHeightx0 = getPreviousHeight(dataset, row, column - 1);
// Now stack the current y values on top of the previous values.
y0 += previousHeightx0;
// Now translate the previous heights
double previousHeightxx0 = rangeAxis.valueToJava2D(previousHeightx0, dataArea, location);
double previousHeightxx1 = rangeAxis.valueToJava2D(previousHeightx1, dataArea, location);
// Now translate the current y values.
double yy0 = rangeAxis.valueToJava2D(y0, dataArea, location);
if (pass == 0) {
// left half
Polygon p = new Polygon();
p.addPoint((int) xx0, (int) yy0);
p.addPoint((int) (xx0 + xx1) / 2, (int) (yy0 + yy1) / 2);
p.addPoint((int) (xx0 + xx1) / 2, (int) (previousHeightxx0 + previousHeightxx1) / 2);
p.addPoint((int) xx0, (int) previousHeightxx0);
g2.setPaint(getItemPaint(row, column - 1));
g2.setStroke(getItemStroke(row, column - 1));
g2.fill(p);
if (entities != null)
addItemEntity(entities, dataset, row, column - 1, p);
// right half
p = new Polygon();
p.addPoint((int) xx1, (int) yy1);
p.addPoint((int) (xx0 + xx1) / 2, (int) (yy0 + yy1) / 2);
p.addPoint((int) (xx0 + xx1) / 2, (int) (previousHeightxx0 + previousHeightxx1) / 2);
p.addPoint((int) xx1, (int) previousHeightxx1);
g2.setPaint(getItemPaint(row, column));
g2.setStroke(getItemStroke(row, column));
g2.fill(p);
if (entities != null)
addItemEntity(entities, dataset, row, column, p);
} else {
if (isItemLabelVisible(row, column)) {
drawItemLabel(g2, plot.getOrientation(), dataset, row, column, xx1, yy1, (y1 < 0.0));
}
}
}
}
}
use of org.jfree.chart.entity.EntityCollection in project hudson-2.x by hudson.
the class NoOverlapCategoryAxis method drawCategoryLabels.
@Override
protected AxisState drawCategoryLabels(Graphics2D g2, Rectangle2D plotArea, Rectangle2D dataArea, RectangleEdge edge, AxisState state, PlotRenderingInfo plotState) {
if (state == null) {
throw new IllegalArgumentException("Null 'state' argument.");
}
if (isTickLabelsVisible()) {
java.util.List ticks = refreshTicks(g2, state, plotArea, edge);
state.setTicks(ticks);
// remember the last drawn label so that we can avoid drawing overlapping labels.
Rectangle2D r = null;
int categoryIndex = 0;
Iterator iterator = ticks.iterator();
while (iterator.hasNext()) {
CategoryTick tick = (CategoryTick) iterator.next();
g2.setFont(getTickLabelFont(tick.getCategory()));
g2.setPaint(getTickLabelPaint(tick.getCategory()));
CategoryLabelPosition position = this.getCategoryLabelPositions().getLabelPosition(edge);
double x0 = 0.0;
double x1 = 0.0;
double y0 = 0.0;
double y1 = 0.0;
if (edge == RectangleEdge.TOP) {
x0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge);
x1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge);
y1 = state.getCursor() - this.getCategoryLabelPositionOffset();
y0 = y1 - state.getMax();
} else if (edge == RectangleEdge.BOTTOM) {
x0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge);
x1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge);
y0 = state.getCursor() + this.getCategoryLabelPositionOffset();
y1 = y0 + state.getMax();
} else if (edge == RectangleEdge.LEFT) {
y0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge);
y1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge);
x1 = state.getCursor() - this.getCategoryLabelPositionOffset();
x0 = x1 - state.getMax();
} else if (edge == RectangleEdge.RIGHT) {
y0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge);
y1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge);
x0 = state.getCursor() + this.getCategoryLabelPositionOffset();
x1 = x0 - state.getMax();
}
Rectangle2D area = new Rectangle2D.Double(x0, y0, (x1 - x0), (y1 - y0));
if (r == null || !r.intersects(area)) {
Point2D anchorPoint = RectangleAnchor.coordinates(area, position.getCategoryAnchor());
TextBlock block = tick.getLabel();
block.draw(g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getLabelAnchor(), (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getAngle());
Shape bounds = block.calculateBounds(g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getLabelAnchor(), (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getAngle());
if (plotState != null && plotState.getOwner() != null) {
EntityCollection entities = plotState.getOwner().getEntityCollection();
if (entities != null) {
String tooltip = getCategoryLabelToolTip(tick.getCategory());
entities.add(new CategoryLabelEntity(tick.getCategory(), bounds, tooltip, null));
}
}
r = bounds.getBounds2D();
}
categoryIndex++;
}
if (edge.equals(RectangleEdge.TOP)) {
double h = state.getMax();
state.cursorUp(h);
} else if (edge.equals(RectangleEdge.BOTTOM)) {
double h = state.getMax();
state.cursorDown(h);
} else if (edge == RectangleEdge.LEFT) {
double w = state.getMax();
state.cursorLeft(w);
} else if (edge == RectangleEdge.RIGHT) {
double w = state.getMax();
state.cursorRight(w);
}
}
return state;
}
Aggregations