Search in sources :

Example 81 with RectangleEdge

use of org.jfree.chart.api.RectangleEdge in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class StatisticalBarRenderer method drawVerticalItem.

/**
 * Draws an item for a plot with a vertical 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 drawVerticalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, StatisticalCategoryDataset dataset, int visibleRow, int row, int column) {
    // BAR X
    double rectX = calculateBarW0(plot, PlotOrientation.VERTICAL, dataArea, domainAxis, state, visibleRow, column);
    // BAR Y
    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 rectY = Math.min(transY2, transY1);
    double rectWidth = state.getBarWidth();
    double rectHeight = 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(rectX + rectWidth / 2.0d, lowVal, rectX + rectWidth / 2.0d, highVal);
        g2.draw(line);
        line = new Line2D.Double(rectX + rectWidth / 2.0d - 5.0d, highVal, rectX + rectWidth / 2.0d + 5.0d, highVal);
        g2.draw(line);
        line = new Line2D.Double(rectX + rectWidth / 2.0d - 5.0d, lowVal, rectX + rectWidth / 2.0d + 5.0d, lowVal);
        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);
    }
}
Also used : Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) GradientPaintTransformer(org.jfree.chart.util.GradientPaintTransformer) Rectangle2D(java.awt.geom.Rectangle2D) GradientPaint(java.awt.GradientPaint) CategoryItemLabelGenerator(org.jfree.chart.labels.CategoryItemLabelGenerator) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Line2D(java.awt.geom.Line2D) EntityCollection(org.jfree.chart.entity.EntityCollection) RectangleEdge(org.jfree.chart.api.RectangleEdge)

Example 82 with RectangleEdge

use of org.jfree.chart.api.RectangleEdge in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class WaterfallBarRenderer method drawItem.

/**
 * 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).
 * @param pass  the pass index.
 */
@Override
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {
    double previous = state.getSeriesRunningTotal();
    if (column == dataset.getColumnCount() - 1) {
        previous = 0.0;
    }
    double current = 0.0;
    Number n = dataset.getValue(row, column);
    if (n != null) {
        current = previous + n.doubleValue();
    }
    state.setSeriesRunningTotal(current);
    int categoryCount = getColumnCount();
    PlotOrientation orientation = plot.getOrientation();
    double rectX = 0.0;
    double rectY = 0.0;
    RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
    // Y0
    double j2dy0 = rangeAxis.valueToJava2D(previous, dataArea, rangeAxisLocation);
    // Y1
    double j2dy1 = rangeAxis.valueToJava2D(current, dataArea, rangeAxisLocation);
    double valDiff = current - previous;
    if (j2dy1 < j2dy0) {
        double temp = j2dy1;
        j2dy1 = j2dy0;
        j2dy0 = temp;
    }
    // BAR WIDTH
    double rectWidth = state.getBarWidth();
    // BAR HEIGHT
    double rectHeight = Math.max(getMinimumBarLength(), Math.abs(j2dy1 - j2dy0));
    Comparable seriesKey = dataset.getRowKey(row);
    Comparable categoryKey = dataset.getColumnKey(column);
    if (orientation == PlotOrientation.HORIZONTAL) {
        rectY = domainAxis.getCategorySeriesMiddle(categoryKey, seriesKey, dataset, getItemMargin(), dataArea, RectangleEdge.LEFT);
        rectX = j2dy0;
        rectHeight = state.getBarWidth();
        rectY = rectY - rectHeight / 2.0;
        rectWidth = Math.max(getMinimumBarLength(), Math.abs(j2dy1 - j2dy0));
    } else if (orientation == PlotOrientation.VERTICAL) {
        rectX = domainAxis.getCategorySeriesMiddle(categoryKey, seriesKey, dataset, getItemMargin(), dataArea, RectangleEdge.TOP);
        rectX = rectX - rectWidth / 2.0;
        rectY = j2dy0;
    }
    Rectangle2D bar = new Rectangle2D.Double(rectX, rectY, rectWidth, rectHeight);
    Paint seriesPaint;
    if (column == 0) {
        seriesPaint = getFirstBarPaint();
    } else if (column == categoryCount - 1) {
        seriesPaint = getLastBarPaint();
    } else {
        if (valDiff >= 0.0) {
            seriesPaint = getPositiveBarPaint();
        } else {
            seriesPaint = getNegativeBarPaint();
        }
    }
    if (getGradientPaintTransformer() != null && seriesPaint instanceof GradientPaint) {
        GradientPaint gp = (GradientPaint) seriesPaint;
        seriesPaint = getGradientPaintTransformer().transform(gp, bar);
    }
    g2.setPaint(seriesPaint);
    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);
        }
    }
    CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, dataset, row, column, plot, generator, bar, (valDiff < 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);
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Stroke(java.awt.Stroke) Rectangle2D(java.awt.geom.Rectangle2D) GradientPaint(java.awt.GradientPaint) CategoryItemLabelGenerator(org.jfree.chart.labels.CategoryItemLabelGenerator) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) EntityCollection(org.jfree.chart.entity.EntityCollection) RectangleEdge(org.jfree.chart.api.RectangleEdge)

Example 83 with RectangleEdge

use of org.jfree.chart.api.RectangleEdge in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class LayeredBarRenderer method drawHorizontalItem.

/**
 * 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 drawHorizontalItem(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;
    }
    // X
    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 = lclip;
        if (value >= uclip) {
            value = uclip;
        }
    }
    RectangleEdge edge = plot.getRangeAxisEdge();
    double transX1 = rangeAxis.valueToJava2D(base, dataArea, edge);
    double transX2 = rangeAxis.valueToJava2D(value, dataArea, edge);
    double rectX = Math.min(transX1, transX2);
    double rectWidth = Math.abs(transX2 - transX1);
    // Y
    double rectY = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()) - state.getBarWidth() / 2.0;
    int seriesCount = getRowCount();
    // draw the bar...
    double shift = 0.0;
    double rectHeight;
    double widthFactor = 1.0;
    double seriesBarWidth = getSeriesBarWidth(row);
    if (!Double.isNaN(seriesBarWidth)) {
        widthFactor = seriesBarWidth;
    }
    rectHeight = widthFactor * state.getBarWidth();
    rectY = rectY + (1 - widthFactor) * state.getBarWidth() / 2.0;
    if (seriesCount > 1) {
        shift = rectHeight * 0.20 / (seriesCount - 1);
    }
    Rectangle2D bar = new Rectangle2D.Double(rectX, (rectY + ((seriesCount - 1 - row) * shift)), rectWidth, (rectHeight - (seriesCount - 1 - row) * shift * 2));
    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);
    // 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);
        }
    }
    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);
    }
}
Also used : Stroke(java.awt.Stroke) GradientPaintTransformer(org.jfree.chart.util.GradientPaintTransformer) EntityCollection(org.jfree.chart.entity.EntityCollection) Rectangle2D(java.awt.geom.Rectangle2D) GradientPaint(java.awt.GradientPaint) CategoryItemLabelGenerator(org.jfree.chart.labels.CategoryItemLabelGenerator) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) RectangleEdge(org.jfree.chart.api.RectangleEdge)

Example 84 with RectangleEdge

use of org.jfree.chart.api.RectangleEdge in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class StackedXYAreaRenderer2 method drawItem.

/**
 * Draws the visual representation of a single data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the area within which the data is being drawn.
 * @param info  collects information about the drawing.
 * @param plot  the plot (can be used to obtain standard color information
 *              etc).
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param crosshairState  information about crosshairs on a plot.
 * @param pass  the pass index.
 */
@Override
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) {
    // setup for collecting optional entity info...
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }
    TableXYDataset tdataset = (TableXYDataset) dataset;
    PlotOrientation orientation = plot.getOrientation();
    // get the data point...
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(y1)) {
        y1 = 0.0;
    }
    double[] stack1 = getStackValues(tdataset, series, item);
    // get the previous point and the next point so we can calculate a
    // "hot spot" for the area (used by the chart entity)...
    double x0 = dataset.getXValue(series, Math.max(item - 1, 0));
    double y0 = dataset.getYValue(series, Math.max(item - 1, 0));
    if (Double.isNaN(y0)) {
        y0 = 0.0;
    }
    double[] stack0 = getStackValues(tdataset, series, Math.max(item - 1, 0));
    int itemCount = dataset.getItemCount(series);
    double x2 = dataset.getXValue(series, Math.min(item + 1, itemCount - 1));
    double y2 = dataset.getYValue(series, Math.min(item + 1, itemCount - 1));
    if (Double.isNaN(y2)) {
        y2 = 0.0;
    }
    double[] stack2 = getStackValues(tdataset, series, Math.min(item + 1, itemCount - 1));
    double xleft = (x0 + x1) / 2.0;
    double xright = (x1 + x2) / 2.0;
    double[] stackLeft = averageStackValues(stack0, stack1);
    double[] stackRight = averageStackValues(stack1, stack2);
    double[] adjStackLeft = adjustedStackValues(stack0, stack1);
    double[] adjStackRight = adjustedStackValues(stack1, stack2);
    RectangleEdge edge0 = plot.getDomainAxisEdge();
    float transX1 = (float) domainAxis.valueToJava2D(x1, dataArea, edge0);
    float transXLeft = (float) domainAxis.valueToJava2D(xleft, dataArea, edge0);
    float transXRight = (float) domainAxis.valueToJava2D(xright, dataArea, edge0);
    if (this.roundXCoordinates) {
        transX1 = Math.round(transX1);
        transXLeft = Math.round(transXLeft);
        transXRight = Math.round(transXRight);
    }
    float transY1;
    RectangleEdge edge1 = plot.getRangeAxisEdge();
    GeneralPath left = new GeneralPath();
    GeneralPath right = new GeneralPath();
    if (y1 >= 0.0) {
        // handle positive value
        transY1 = (float) rangeAxis.valueToJava2D(y1 + stack1[1], dataArea, edge1);
        float transStack1 = (float) rangeAxis.valueToJava2D(stack1[1], dataArea, edge1);
        float transStackLeft = (float) rangeAxis.valueToJava2D(adjStackLeft[1], dataArea, edge1);
        // LEFT POLYGON
        if (y0 >= 0.0) {
            double yleft = (y0 + y1) / 2.0 + stackLeft[1];
            float transYLeft = (float) rangeAxis.valueToJava2D(yleft, dataArea, edge1);
            if (orientation == PlotOrientation.VERTICAL) {
                left.moveTo(transX1, transY1);
                left.lineTo(transX1, transStack1);
                left.lineTo(transXLeft, transStackLeft);
                left.lineTo(transXLeft, transYLeft);
            } else {
                left.moveTo(transY1, transX1);
                left.lineTo(transStack1, transX1);
                left.lineTo(transStackLeft, transXLeft);
                left.lineTo(transYLeft, transXLeft);
            }
            left.closePath();
        } else {
            if (orientation == PlotOrientation.VERTICAL) {
                left.moveTo(transX1, transStack1);
                left.lineTo(transX1, transY1);
                left.lineTo(transXLeft, transStackLeft);
            } else {
                left.moveTo(transStack1, transX1);
                left.lineTo(transY1, transX1);
                left.lineTo(transStackLeft, transXLeft);
            }
            left.closePath();
        }
        float transStackRight = (float) rangeAxis.valueToJava2D(adjStackRight[1], dataArea, edge1);
        // RIGHT POLYGON
        if (y2 >= 0.0) {
            double yright = (y1 + y2) / 2.0 + stackRight[1];
            float transYRight = (float) rangeAxis.valueToJava2D(yright, dataArea, edge1);
            if (orientation == PlotOrientation.VERTICAL) {
                right.moveTo(transX1, transStack1);
                right.lineTo(transX1, transY1);
                right.lineTo(transXRight, transYRight);
                right.lineTo(transXRight, transStackRight);
            } else {
                right.moveTo(transStack1, transX1);
                right.lineTo(transY1, transX1);
                right.lineTo(transYRight, transXRight);
                right.lineTo(transStackRight, transXRight);
            }
            right.closePath();
        } else {
            if (orientation == PlotOrientation.VERTICAL) {
                right.moveTo(transX1, transStack1);
                right.lineTo(transX1, transY1);
                right.lineTo(transXRight, transStackRight);
            } else {
                right.moveTo(transStack1, transX1);
                right.lineTo(transY1, transX1);
                right.lineTo(transStackRight, transXRight);
            }
            right.closePath();
        }
    } else {
        // handle negative value
        transY1 = (float) rangeAxis.valueToJava2D(y1 + stack1[0], dataArea, edge1);
        float transStack1 = (float) rangeAxis.valueToJava2D(stack1[0], dataArea, edge1);
        float transStackLeft = (float) rangeAxis.valueToJava2D(adjStackLeft[0], dataArea, edge1);
        // LEFT POLYGON
        if (y0 >= 0.0) {
            if (orientation == PlotOrientation.VERTICAL) {
                left.moveTo(transX1, transStack1);
                left.lineTo(transX1, transY1);
                left.lineTo(transXLeft, transStackLeft);
            } else {
                left.moveTo(transStack1, transX1);
                left.lineTo(transY1, transX1);
                left.lineTo(transStackLeft, transXLeft);
            }
            left.clone();
        } else {
            double yleft = (y0 + y1) / 2.0 + stackLeft[0];
            float transYLeft = (float) rangeAxis.valueToJava2D(yleft, dataArea, edge1);
            if (orientation == PlotOrientation.VERTICAL) {
                left.moveTo(transX1, transY1);
                left.lineTo(transX1, transStack1);
                left.lineTo(transXLeft, transStackLeft);
                left.lineTo(transXLeft, transYLeft);
            } else {
                left.moveTo(transY1, transX1);
                left.lineTo(transStack1, transX1);
                left.lineTo(transStackLeft, transXLeft);
                left.lineTo(transYLeft, transXLeft);
            }
            left.closePath();
        }
        float transStackRight = (float) rangeAxis.valueToJava2D(adjStackRight[0], dataArea, edge1);
        // RIGHT POLYGON
        if (y2 >= 0.0) {
            if (orientation == PlotOrientation.VERTICAL) {
                right.moveTo(transX1, transStack1);
                right.lineTo(transX1, transY1);
                right.lineTo(transXRight, transStackRight);
            } else {
                right.moveTo(transStack1, transX1);
                right.lineTo(transY1, transX1);
                right.lineTo(transStackRight, transXRight);
            }
            right.closePath();
        } else {
            double yright = (y1 + y2) / 2.0 + stackRight[0];
            float transYRight = (float) rangeAxis.valueToJava2D(yright, dataArea, edge1);
            if (orientation == PlotOrientation.VERTICAL) {
                right.moveTo(transX1, transStack1);
                right.lineTo(transX1, transY1);
                right.lineTo(transXRight, transYRight);
                right.lineTo(transXRight, transStackRight);
            } else {
                right.moveTo(transStack1, transX1);
                right.lineTo(transY1, transX1);
                right.lineTo(transYRight, transXRight);
                right.lineTo(transStackRight, transXRight);
            }
            right.closePath();
        }
    }
    // Get series Paint and Stroke
    Paint itemPaint = getItemPaint(series, item);
    if (pass == 0) {
        g2.setPaint(itemPaint);
        g2.fill(left);
        g2.fill(right);
    }
    // add an entity for the item...
    if (entities != null) {
        // Create the entity area and limit it to the data area
        Area dataAreaHotspot = new Area(left);
        dataAreaHotspot.add(new Area(right));
        dataAreaHotspot.intersect(new Area(dataArea));
        if (!dataAreaHotspot.isEmpty()) {
            addEntity(entities, dataAreaHotspot, dataset, series, item, 0.0, 0.0);
        }
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Area(java.awt.geom.Area) GeneralPath(java.awt.geom.GeneralPath) EntityCollection(org.jfree.chart.entity.EntityCollection) TableXYDataset(org.jfree.data.xy.TableXYDataset) Paint(java.awt.Paint) Paint(java.awt.Paint) RectangleEdge(org.jfree.chart.api.RectangleEdge)

Example 85 with RectangleEdge

use of org.jfree.chart.api.RectangleEdge in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class XYBubbleRenderer method drawItem.

/**
 * Draws the visual representation of a single data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the area within which the data is being drawn.
 * @param info  collects information about the drawing.
 * @param plot  the plot (can be used to obtain standard color
 *              information etc).
 * @param domainAxis  the domain (horizontal) axis.
 * @param rangeAxis  the range (vertical) axis.
 * @param dataset  the dataset (an {@link XYZDataset} is expected).
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param crosshairState  crosshair information for the plot
 *                        ({@code null} permitted).
 * @param pass  the pass index.
 */
@Override
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) {
    // return straight away if the item is not visible
    if (!getItemVisible(series, item)) {
        return;
    }
    PlotOrientation orientation = plot.getOrientation();
    // get the data point...
    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    double z = Double.NaN;
    if (dataset instanceof XYZDataset) {
        XYZDataset xyzData = (XYZDataset) dataset;
        z = xyzData.getZValue(series, item);
    }
    if (!Double.isNaN(z)) {
        RectangleEdge domainAxisLocation = plot.getDomainAxisEdge();
        RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
        double transX = domainAxis.valueToJava2D(x, dataArea, domainAxisLocation);
        double transY = rangeAxis.valueToJava2D(y, dataArea, rangeAxisLocation);
        double transDomain;
        double transRange;
        double zero;
        switch(getScaleType()) {
            case SCALE_ON_DOMAIN_AXIS:
                zero = domainAxis.valueToJava2D(0.0, dataArea, domainAxisLocation);
                transDomain = domainAxis.valueToJava2D(z, dataArea, domainAxisLocation) - zero;
                transRange = transDomain;
                break;
            case SCALE_ON_RANGE_AXIS:
                zero = rangeAxis.valueToJava2D(0.0, dataArea, rangeAxisLocation);
                transRange = zero - rangeAxis.valueToJava2D(z, dataArea, rangeAxisLocation);
                transDomain = transRange;
                break;
            default:
                double zero1 = domainAxis.valueToJava2D(0.0, dataArea, domainAxisLocation);
                double zero2 = rangeAxis.valueToJava2D(0.0, dataArea, rangeAxisLocation);
                transDomain = domainAxis.valueToJava2D(z, dataArea, domainAxisLocation) - zero1;
                transRange = zero2 - rangeAxis.valueToJava2D(z, dataArea, rangeAxisLocation);
        }
        transDomain = Math.abs(transDomain);
        transRange = Math.abs(transRange);
        Ellipse2D circle = null;
        if (orientation == PlotOrientation.VERTICAL) {
            circle = new Ellipse2D.Double(transX - transDomain / 2.0, transY - transRange / 2.0, transDomain, transRange);
        } else if (orientation == PlotOrientation.HORIZONTAL) {
            circle = new Ellipse2D.Double(transY - transRange / 2.0, transX - transDomain / 2.0, transRange, transDomain);
        } else {
            throw new IllegalStateException();
        }
        g2.setPaint(getItemPaint(series, item));
        g2.fill(circle);
        g2.setStroke(getItemOutlineStroke(series, item));
        g2.setPaint(getItemOutlinePaint(series, item));
        g2.draw(circle);
        if (isItemLabelVisible(series, item)) {
            if (orientation == PlotOrientation.VERTICAL) {
                drawItemLabel(g2, orientation, dataset, series, item, transX, transY, false);
            } else if (orientation == PlotOrientation.HORIZONTAL) {
                drawItemLabel(g2, orientation, dataset, series, item, transY, transX, false);
            }
        }
        // add an entity if this info is being collected
        if (info != null) {
            EntityCollection entities = info.getOwner().getEntityCollection();
            if (entities != null && circle.intersects(dataArea)) {
                addEntity(entities, circle, dataset, series, item, circle.getCenterX(), circle.getCenterY());
            }
        }
        int datasetIndex = plot.indexOf(dataset);
        updateCrosshairValues(crosshairState, x, y, datasetIndex, transX, transY, orientation);
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) EntityCollection(org.jfree.chart.entity.EntityCollection) XYZDataset(org.jfree.data.xy.XYZDataset) Ellipse2D(java.awt.geom.Ellipse2D) Paint(java.awt.Paint) RectangleEdge(org.jfree.chart.api.RectangleEdge)

Aggregations

RectangleEdge (org.jfree.chart.api.RectangleEdge)87 Rectangle2D (java.awt.geom.Rectangle2D)47 PlotOrientation (org.jfree.chart.plot.PlotOrientation)44 Paint (java.awt.Paint)40 EntityCollection (org.jfree.chart.entity.EntityCollection)33 Stroke (java.awt.Stroke)18 Line2D (java.awt.geom.Line2D)17 Shape (java.awt.Shape)16 AxisSpace (org.jfree.chart.axis.AxisSpace)12 CategoryItemLabelGenerator (org.jfree.chart.labels.CategoryItemLabelGenerator)11 ValueAxis (org.jfree.chart.axis.ValueAxis)10 GeneralPath (java.awt.geom.GeneralPath)9 IntervalXYDataset (org.jfree.data.xy.IntervalXYDataset)8 Point2D (java.awt.geom.Point2D)7 GradientPaint (java.awt.GradientPaint)6 RectangleInsets (org.jfree.chart.api.RectangleInsets)6 CrosshairState (org.jfree.chart.plot.CrosshairState)6 Ellipse2D (java.awt.geom.Ellipse2D)5 AxisState (org.jfree.chart.axis.AxisState)5 AxisLocation (org.jfree.chart.axis.AxisLocation)4