use of org.jfree.chart.util.GradientPaintTransformer in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class IntervalMarkerTest method testEquals.
/**
* Confirm that the equals method can distinguish all the required fields.
*/
@Test
public void testEquals() {
IntervalMarker m1 = new IntervalMarker(45.0, 50.0);
IntervalMarker m2 = new IntervalMarker(45.0, 50.0);
assertEquals(m1, m2);
assertEquals(m2, m1);
m1 = new IntervalMarker(44.0, 50.0);
assertNotEquals(m1, m2);
m2 = new IntervalMarker(44.0, 50.0);
assertEquals(m1, m2);
m1 = new IntervalMarker(44.0, 55.0);
assertNotEquals(m1, m2);
m2 = new IntervalMarker(44.0, 55.0);
assertEquals(m1, m2);
GradientPaintTransformer t = new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL);
m1.setGradientPaintTransformer(t);
assertNotEquals(m1, m2);
m2.setGradientPaintTransformer(t);
assertEquals(m1, m2);
}
use of org.jfree.chart.util.GradientPaintTransformer in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class AbstractXYItemRenderer method drawDomainMarker.
/**
* Draws a line on the chart perpendicular to the x-axis to mark
* a value or range of values.
*
* @param g2 the graphics device.
* @param plot the plot.
* @param domainAxis the domain axis.
* @param marker the marker line.
* @param dataArea the axis data area.
*/
@Override
public void drawDomainMarker(Graphics2D g2, XYPlot plot, ValueAxis domainAxis, Marker marker, Rectangle2D dataArea) {
if (marker instanceof ValueMarker) {
ValueMarker vm = (ValueMarker) marker;
double value = vm.getValue();
Range range = domainAxis.getRange();
if (!range.contains(value)) {
return;
}
double v = domainAxis.valueToJava2D(value, dataArea, plot.getDomainAxisEdge());
PlotOrientation orientation = plot.getOrientation();
Line2D line = null;
switch(orientation) {
case HORIZONTAL:
line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v);
break;
case VERTICAL:
line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY());
break;
default:
throw new IllegalStateException("Unrecognised orientation.");
}
final Composite originalComposite = g2.getComposite();
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, marker.getAlpha()));
g2.setPaint(marker.getPaint());
g2.setStroke(marker.getStroke());
g2.draw(line);
String label = marker.getLabel();
RectangleAnchor anchor = marker.getLabelAnchor();
if (label != null) {
Font labelFont = marker.getLabelFont();
g2.setFont(labelFont);
Point2D coords = calculateDomainMarkerTextAnchorPoint(g2, orientation, dataArea, line.getBounds2D(), marker.getLabelOffset(), LengthAdjustmentType.EXPAND, anchor);
Rectangle2D r = TextUtils.calcAlignedStringBounds(label, g2, (float) coords.getX(), (float) coords.getY(), marker.getLabelTextAnchor());
g2.setPaint(marker.getLabelBackgroundColor());
g2.fill(r);
g2.setPaint(marker.getLabelPaint());
TextUtils.drawAlignedString(label, g2, (float) coords.getX(), (float) coords.getY(), marker.getLabelTextAnchor());
}
g2.setComposite(originalComposite);
} else if (marker instanceof IntervalMarker) {
IntervalMarker im = (IntervalMarker) marker;
double start = im.getStartValue();
double end = im.getEndValue();
Range range = domainAxis.getRange();
if (!(range.intersects(start, end))) {
return;
}
double start2d = domainAxis.valueToJava2D(start, dataArea, plot.getDomainAxisEdge());
double end2d = domainAxis.valueToJava2D(end, dataArea, plot.getDomainAxisEdge());
double low = Math.min(start2d, end2d);
double high = Math.max(start2d, end2d);
PlotOrientation orientation = plot.getOrientation();
Rectangle2D rect = null;
if (orientation == PlotOrientation.HORIZONTAL) {
// clip top and bottom bounds to data area
low = Math.max(low, dataArea.getMinY());
high = Math.min(high, dataArea.getMaxY());
rect = new Rectangle2D.Double(dataArea.getMinX(), low, dataArea.getWidth(), high - low);
} else if (orientation == PlotOrientation.VERTICAL) {
// clip left and right bounds to data area
low = Math.max(low, dataArea.getMinX());
high = Math.min(high, dataArea.getMaxX());
rect = new Rectangle2D.Double(low, dataArea.getMinY(), high - low, dataArea.getHeight());
}
final Composite originalComposite = g2.getComposite();
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, marker.getAlpha()));
Paint p = marker.getPaint();
if (p instanceof GradientPaint) {
GradientPaint gp = (GradientPaint) p;
GradientPaintTransformer t = im.getGradientPaintTransformer();
if (t != null) {
gp = t.transform(gp, rect);
}
g2.setPaint(gp);
} else {
g2.setPaint(p);
}
g2.fill(rect);
// now draw the outlines, if visible...
if (im.getOutlinePaint() != null && im.getOutlineStroke() != null) {
if (orientation == PlotOrientation.VERTICAL) {
Line2D line = new Line2D.Double();
double y0 = dataArea.getMinY();
double y1 = dataArea.getMaxY();
g2.setPaint(im.getOutlinePaint());
g2.setStroke(im.getOutlineStroke());
if (range.contains(start)) {
line.setLine(start2d, y0, start2d, y1);
g2.draw(line);
}
if (range.contains(end)) {
line.setLine(end2d, y0, end2d, y1);
g2.draw(line);
}
} else {
// PlotOrientation.HORIZONTAL
Line2D line = new Line2D.Double();
double x0 = dataArea.getMinX();
double x1 = dataArea.getMaxX();
g2.setPaint(im.getOutlinePaint());
g2.setStroke(im.getOutlineStroke());
if (range.contains(start)) {
line.setLine(x0, start2d, x1, start2d);
g2.draw(line);
}
if (range.contains(end)) {
line.setLine(x0, end2d, x1, end2d);
g2.draw(line);
}
}
}
String label = marker.getLabel();
RectangleAnchor anchor = marker.getLabelAnchor();
if (label != null) {
Font labelFont = marker.getLabelFont();
g2.setFont(labelFont);
Point2D coords = calculateDomainMarkerTextAnchorPoint(g2, orientation, dataArea, rect, marker.getLabelOffset(), marker.getLabelOffsetType(), anchor);
Rectangle2D r = TextUtils.calcAlignedStringBounds(label, g2, (float) coords.getX(), (float) coords.getY(), marker.getLabelTextAnchor());
g2.setPaint(marker.getLabelBackgroundColor());
g2.fill(r);
g2.setPaint(marker.getLabelPaint());
TextUtils.drawAlignedString(label, g2, (float) coords.getX(), (float) coords.getY(), marker.getLabelTextAnchor());
}
g2.setComposite(originalComposite);
}
}
use of org.jfree.chart.util.GradientPaintTransformer in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class LayeredBarRenderer method drawVerticalItem.
/**
* Draws the bar for a single (series, category) data item.
*
* @param g2 the graphics device.
* @param state the renderer state.
* @param dataArea the data area.
* @param plot the plot.
* @param domainAxis the domain axis.
* @param rangeAxis the range axis.
* @param dataset the dataset.
* @param row the row index (zero-based).
* @param column the column index (zero-based).
*/
protected void drawVerticalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column) {
// nothing is drawn for null values...
Number dataValue = dataset.getValue(row, column);
if (dataValue == null) {
return;
}
// BAR X
double rectX = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()) - state.getBarWidth() / 2.0;
int seriesCount = getRowCount();
// BAR Y
double value = dataValue.doubleValue();
double base = getBase();
double lclip = getLowerClip();
double uclip = getUpperClip();
if (uclip <= 0.0) {
// cases 1, 2, 3 and 4
if (value >= uclip) {
// bar is not visible
return;
}
base = uclip;
if (value <= lclip) {
value = lclip;
}
} else if (lclip <= 0.0) {
// cases 5, 6, 7 and 8
if (value >= uclip) {
value = uclip;
} else {
if (value <= lclip) {
value = lclip;
}
}
} else {
// cases 9, 10, 11 and 12
if (value <= lclip) {
// bar is not visible
return;
}
base = getLowerClip();
if (value >= uclip) {
value = uclip;
}
}
RectangleEdge edge = plot.getRangeAxisEdge();
double transY1 = rangeAxis.valueToJava2D(base, dataArea, edge);
double transY2 = rangeAxis.valueToJava2D(value, dataArea, edge);
double rectY = Math.min(transY2, transY1);
double rectWidth;
double rectHeight = Math.abs(transY2 - transY1);
// draw the bar...
double shift = 0.0;
double widthFactor = 1.0;
double seriesBarWidth = getSeriesBarWidth(row);
if (!Double.isNaN(seriesBarWidth)) {
widthFactor = seriesBarWidth;
}
rectWidth = widthFactor * state.getBarWidth();
rectX = rectX + (1 - widthFactor) * state.getBarWidth() / 2.0;
if (seriesCount > 1) {
// needs to be improved !!!
shift = rectWidth * 0.20 / (seriesCount - 1);
}
Rectangle2D bar = new Rectangle2D.Double((rectX + ((seriesCount - 1 - row) * shift)), rectY, (rectWidth - (seriesCount - 1 - row) * shift * 2), rectHeight);
if (state.getElementHinting()) {
beginElementGroup(g2, dataset.getRowKey(row), dataset.getColumnKey(column));
}
Paint itemPaint = getItemPaint(row, column);
GradientPaintTransformer t = getGradientPaintTransformer();
if (t != null && itemPaint instanceof GradientPaint) {
itemPaint = t.transform((GradientPaint) itemPaint, bar);
}
g2.setPaint(itemPaint);
g2.fill(bar);
if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
g2.setStroke(getItemOutlineStroke(row, column));
g2.setPaint(getItemOutlinePaint(row, column));
g2.draw(bar);
}
if (state.getElementHinting()) {
endElementGroup(g2);
}
// draw the item labels if there are any...
CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
if (generator != null && isItemLabelVisible(row, column)) {
drawItemLabel(g2, dataset, row, column, plot, generator, bar, value < base);
}
// collect entity and tool tip information...
EntityCollection entities = state.getEntityCollection();
if (entities != null) {
addItemEntity(entities, dataset, row, column, bar);
}
}
use of org.jfree.chart.util.GradientPaintTransformer in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class StandardBarPainter method paintBar.
/**
* Paints a single bar instance.
*
* @param g2 the graphics target.
* @param renderer the renderer.
* @param row the row index.
* @param column the column index.
* @param bar the bar
* @param base indicates which side of the rectangle is the base of the
* bar.
*/
@Override
public void paintBar(Graphics2D g2, BarRenderer renderer, int row, int column, RectangularShape bar, RectangleEdge base) {
Paint itemPaint = renderer.getItemPaint(row, column);
GradientPaintTransformer t = renderer.getGradientPaintTransformer();
if (t != null && itemPaint instanceof GradientPaint) {
itemPaint = t.transform((GradientPaint) itemPaint, bar);
}
g2.setPaint(itemPaint);
g2.fill(bar);
// draw the outline...
if (renderer.isDrawBarOutline()) {
// && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
Stroke stroke = renderer.getItemOutlineStroke(row, column);
Paint paint = renderer.getItemOutlinePaint(row, column);
if (stroke != null && paint != null) {
g2.setStroke(stroke);
g2.setPaint(paint);
g2.draw(bar);
}
}
}
use of org.jfree.chart.util.GradientPaintTransformer in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class StatisticalBarRenderer method drawHorizontalItem.
/**
* Draws an item for a plot with a horizontal orientation.
*
* @param g2 the graphics device.
* @param state the renderer state.
* @param dataArea the data area.
* @param plot the plot.
* @param domainAxis the domain axis.
* @param rangeAxis the range axis.
* @param dataset the data.
* @param visibleRow the visible row index.
* @param row the row index (zero-based).
* @param column the column index (zero-based).
*/
protected void drawHorizontalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, StatisticalCategoryDataset dataset, int visibleRow, int row, int column) {
// BAR Y
double rectY = calculateBarW0(plot, PlotOrientation.HORIZONTAL, dataArea, domainAxis, state, visibleRow, column);
// BAR X
Number meanValue = dataset.getMeanValue(row, column);
if (meanValue == null) {
return;
}
double value = meanValue.doubleValue();
double base = 0.0;
double lclip = getLowerClip();
double uclip = getUpperClip();
if (uclip <= 0.0) {
// cases 1, 2, 3 and 4
if (value >= uclip) {
// bar is not visible
return;
}
base = uclip;
if (value <= lclip) {
value = lclip;
}
} else if (lclip <= 0.0) {
// cases 5, 6, 7 and 8
if (value >= uclip) {
value = uclip;
} else {
if (value <= lclip) {
value = lclip;
}
}
} else {
// cases 9, 10, 11 and 12
if (value <= lclip) {
// bar is not visible
return;
}
base = getLowerClip();
if (value >= uclip) {
value = uclip;
}
}
RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
double transY1 = rangeAxis.valueToJava2D(base, dataArea, yAxisLocation);
double transY2 = rangeAxis.valueToJava2D(value, dataArea, yAxisLocation);
double rectX = Math.min(transY2, transY1);
double rectHeight = state.getBarWidth();
double rectWidth = Math.abs(transY2 - transY1);
Rectangle2D bar = new Rectangle2D.Double(rectX, rectY, rectWidth, rectHeight);
Paint itemPaint = getItemPaint(row, column);
GradientPaintTransformer t = getGradientPaintTransformer();
if (t != null && itemPaint instanceof GradientPaint) {
itemPaint = t.transform((GradientPaint) itemPaint, bar);
}
g2.setPaint(itemPaint);
g2.fill(bar);
// draw the outline...
if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
Stroke stroke = getItemOutlineStroke(row, column);
Paint paint = getItemOutlinePaint(row, column);
if (stroke != null && paint != null) {
g2.setStroke(stroke);
g2.setPaint(paint);
g2.draw(bar);
}
}
// standard deviation lines
Number n = dataset.getStdDevValue(row, column);
if (n != null) {
double valueDelta = n.doubleValue();
double highVal = rangeAxis.valueToJava2D(meanValue.doubleValue() + valueDelta, dataArea, yAxisLocation);
double lowVal = rangeAxis.valueToJava2D(meanValue.doubleValue() - valueDelta, dataArea, yAxisLocation);
if (this.errorIndicatorPaint != null) {
g2.setPaint(this.errorIndicatorPaint);
} else {
g2.setPaint(getItemOutlinePaint(row, column));
}
if (this.errorIndicatorStroke != null) {
g2.setStroke(this.errorIndicatorStroke);
} else {
g2.setStroke(getItemOutlineStroke(row, column));
}
Line2D line;
line = new Line2D.Double(lowVal, rectY + rectHeight / 2.0d, highVal, rectY + rectHeight / 2.0d);
g2.draw(line);
line = new Line2D.Double(highVal, rectY + rectHeight * 0.25, highVal, rectY + rectHeight * 0.75);
g2.draw(line);
line = new Line2D.Double(lowVal, rectY + rectHeight * 0.25, lowVal, rectY + rectHeight * 0.75);
g2.draw(line);
}
CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
if (generator != null && isItemLabelVisible(row, column)) {
drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0));
}
// add an item entity, if this information is being collected
EntityCollection entities = state.getEntityCollection();
if (entities != null) {
addItemEntity(entities, dataset, row, column, bar);
}
}
Aggregations