Search in sources :

Example 71 with RectangleEdge

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

the class XYStepRenderer 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 vertical axis.
 * @param dataset  the dataset.
 * @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) {
    // do nothing if item is not visible
    if (!getItemVisible(series, item)) {
        return;
    }
    PlotOrientation orientation = plot.getOrientation();
    Paint seriesPaint = getItemPaint(series, item);
    Stroke seriesStroke = getItemStroke(series, item);
    g2.setPaint(seriesPaint);
    g2.setStroke(seriesStroke);
    // get the data point...
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    double transY1 = (Double.isNaN(y1) ? Double.NaN : rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation));
    if (pass == 0 && item > 0) {
        // get the previous data point...
        double x0 = dataset.getXValue(series, item - 1);
        double y0 = dataset.getYValue(series, item - 1);
        double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
        double transY0 = (Double.isNaN(y0) ? Double.NaN : rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation));
        if (orientation == PlotOrientation.HORIZONTAL) {
            if (transY0 == transY1) {
                // this represents the situation
                // for drawing a horizontal bar.
                drawLine(g2, state.workingLine, transY0, transX0, transY1, transX1, dataArea);
            } else {
                // this handles the need to perform a 'step'.
                // calculate the step point
                double transXs = transX0 + (getStepPoint() * (transX1 - transX0));
                drawLine(g2, state.workingLine, transY0, transX0, transY0, transXs, dataArea);
                drawLine(g2, state.workingLine, transY0, transXs, transY1, transXs, dataArea);
                drawLine(g2, state.workingLine, transY1, transXs, transY1, transX1, dataArea);
            }
        } else if (orientation == PlotOrientation.VERTICAL) {
            if (transY0 == transY1) {
                // this represents the situation
                // for drawing a horizontal bar.
                drawLine(g2, state.workingLine, transX0, transY0, transX1, transY1, dataArea);
            } else {
                // this handles the need to perform a 'step'.
                // calculate the step point
                double transXs = transX0 + (getStepPoint() * (transX1 - transX0));
                drawLine(g2, state.workingLine, transX0, transY0, transXs, transY0, dataArea);
                drawLine(g2, state.workingLine, transXs, transY0, transXs, transY1, dataArea);
                drawLine(g2, state.workingLine, transXs, transY1, transX1, transY1, dataArea);
            }
        }
        // submit this data item as a candidate for the crosshair point
        int datasetIndex = plot.indexOf(dataset);
        updateCrosshairValues(crosshairState, x1, y1, datasetIndex, transX1, transY1, orientation);
        // collect entity and tool tip information...
        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            if (orientation == PlotOrientation.HORIZONTAL) {
                addEntity(entities, null, dataset, series, item, transY1, transX1);
            } else {
                addEntity(entities, null, dataset, series, item, transX1, transY1);
            }
        }
    }
    if (pass == 1) {
        // draw the item label if there is one...
        if (isItemLabelVisible(series, item)) {
            double xx = transX1;
            double yy = transY1;
            if (orientation == PlotOrientation.HORIZONTAL) {
                xx = transY1;
                yy = transX1;
            }
            drawItemLabel(g2, orientation, dataset, series, item, xx, yy, (y1 < 0.0));
        }
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Stroke(java.awt.Stroke) EntityCollection(org.jfree.chart.entity.EntityCollection) Paint(java.awt.Paint) Paint(java.awt.Paint) RectangleEdge(org.jfree.chart.api.RectangleEdge)

Example 72 with RectangleEdge

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

the class XYBoxAndWhiskerRenderer method drawVerticalItem.

/**
 * Draws the visual representation of a single data item.
 *
 * @param g2  the graphics device.
 * @param dataArea  the area within which the plot is being drawn.
 * @param info  collects info 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 (must be an instance of
 *                 {@link BoxAndWhiskerXYDataset}).
 * @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.
 */
public void drawVerticalItem(Graphics2D g2, 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();
    }
    BoxAndWhiskerXYDataset boxAndWhiskerData = (BoxAndWhiskerXYDataset) dataset;
    Number x = boxAndWhiskerData.getX(series, item);
    Number yMax = boxAndWhiskerData.getMaxRegularValue(series, item);
    Number yMin = boxAndWhiskerData.getMinRegularValue(series, item);
    Number yMedian = boxAndWhiskerData.getMedianValue(series, item);
    Number yAverage = boxAndWhiskerData.getMeanValue(series, item);
    Number yQ1Median = boxAndWhiskerData.getQ1Value(series, item);
    Number yQ3Median = boxAndWhiskerData.getQ3Value(series, item);
    List yOutliers = boxAndWhiskerData.getOutliers(series, item);
    // that case...
    if (yOutliers == null) {
        yOutliers = Collections.EMPTY_LIST;
    }
    double xx = domainAxis.valueToJava2D(x.doubleValue(), dataArea, plot.getDomainAxisEdge());
    RectangleEdge location = plot.getRangeAxisEdge();
    double yyMax = rangeAxis.valueToJava2D(yMax.doubleValue(), dataArea, location);
    double yyMin = rangeAxis.valueToJava2D(yMin.doubleValue(), dataArea, location);
    double yyMedian = rangeAxis.valueToJava2D(yMedian.doubleValue(), dataArea, location);
    double yyAverage = 0.0;
    if (yAverage != null) {
        yyAverage = rangeAxis.valueToJava2D(yAverage.doubleValue(), dataArea, location);
    }
    double yyQ1Median = rangeAxis.valueToJava2D(yQ1Median.doubleValue(), dataArea, location);
    double yyQ3Median = rangeAxis.valueToJava2D(yQ3Median.doubleValue(), dataArea, location);
    double yyOutlier;
    double exactBoxWidth = getBoxWidth();
    double width = exactBoxWidth;
    double dataAreaX = dataArea.getMaxX() - dataArea.getMinX();
    double maxBoxPercent = 0.1;
    double maxBoxWidth = dataAreaX * maxBoxPercent;
    if (exactBoxWidth <= 0.0) {
        int itemCount = boxAndWhiskerData.getItemCount(series);
        exactBoxWidth = dataAreaX / itemCount * 4.5 / 7;
        if (exactBoxWidth < 3) {
            width = 3;
        } else if (exactBoxWidth > maxBoxWidth) {
            width = maxBoxWidth;
        } else {
            width = exactBoxWidth;
        }
    }
    g2.setPaint(getItemPaint(series, item));
    Stroke s = getItemStroke(series, item);
    g2.setStroke(s);
    // draw the upper shadow
    g2.draw(new Line2D.Double(xx, yyMax, xx, yyQ3Median));
    g2.draw(new Line2D.Double(xx - width / 2, yyMax, xx + width / 2, yyMax));
    // draw the lower shadow
    g2.draw(new Line2D.Double(xx, yyMin, xx, yyQ1Median));
    g2.draw(new Line2D.Double(xx - width / 2, yyMin, xx + width / 2, yyMin));
    // draw the body
    Shape box;
    if (yyQ1Median > yyQ3Median) {
        box = new Rectangle2D.Double(xx - width / 2, yyQ3Median, width, yyQ1Median - yyQ3Median);
    } else {
        box = new Rectangle2D.Double(xx - width / 2, yyQ1Median, width, yyQ3Median - yyQ1Median);
    }
    if (this.fillBox) {
        g2.setPaint(lookupBoxPaint(series, item));
        g2.fill(box);
    }
    g2.setStroke(getItemOutlineStroke(series, item));
    g2.setPaint(getItemOutlinePaint(series, item));
    g2.draw(box);
    // draw median
    g2.setPaint(getArtifactPaint());
    g2.draw(new Line2D.Double(xx - width / 2, yyMedian, xx + width / 2, yyMedian));
    // average radius
    double aRadius = 0;
    // outlier radius
    double oRadius = width / 3;
    // draw average - SPECIAL AIMS REQUIREMENT
    if (yAverage != null) {
        aRadius = width / 4;
        // before drawing it...
        if ((yyAverage > (dataArea.getMinY() - aRadius)) && (yyAverage < (dataArea.getMaxY() + aRadius))) {
            Ellipse2D.Double avgEllipse = new Ellipse2D.Double(xx - aRadius, yyAverage - aRadius, aRadius * 2, aRadius * 2);
            g2.fill(avgEllipse);
            g2.draw(avgEllipse);
        }
    }
    List outliers = new ArrayList();
    OutlierListCollection outlierListCollection = new OutlierListCollection();
    /* From outlier array sort out which are outliers and put these into
         * an arraylist. If there are any farouts, set the flag on the
         * OutlierListCollection
         */
    for (int i = 0; i < yOutliers.size(); i++) {
        double outlier = ((Number) yOutliers.get(i)).doubleValue();
        if (outlier > boxAndWhiskerData.getMaxOutlier(series, item).doubleValue()) {
            outlierListCollection.setHighFarOut(true);
        } else if (outlier < boxAndWhiskerData.getMinOutlier(series, item).doubleValue()) {
            outlierListCollection.setLowFarOut(true);
        } else if (outlier > boxAndWhiskerData.getMaxRegularValue(series, item).doubleValue()) {
            yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea, location);
            outliers.add(new Outlier(xx, yyOutlier, oRadius));
        } else if (outlier < boxAndWhiskerData.getMinRegularValue(series, item).doubleValue()) {
            yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea, location);
            outliers.add(new Outlier(xx, yyOutlier, oRadius));
        }
        Collections.sort(outliers);
    }
    // outlier list or a new outlier list is made
    for (Iterator iterator = outliers.iterator(); iterator.hasNext(); ) {
        Outlier outlier = (Outlier) iterator.next();
        outlierListCollection.add(outlier);
    }
    // draw yOutliers
    double maxAxisValue = rangeAxis.valueToJava2D(rangeAxis.getUpperBound(), dataArea, location) + aRadius;
    double minAxisValue = rangeAxis.valueToJava2D(rangeAxis.getLowerBound(), dataArea, location) - aRadius;
    // draw outliers
    for (Iterator iterator = outlierListCollection.iterator(); iterator.hasNext(); ) {
        OutlierList list = (OutlierList) iterator.next();
        Outlier outlier = list.getAveragedOutlier();
        Point2D point = outlier.getPoint();
        if (list.isMultiple()) {
            drawMultipleEllipse(point, width, oRadius, g2);
        } else {
            drawEllipse(point, oRadius, g2);
        }
    }
    // draw farout
    if (outlierListCollection.isHighFarOut()) {
        drawHighFarOut(aRadius, g2, xx, maxAxisValue);
    }
    if (outlierListCollection.isLowFarOut()) {
        drawLowFarOut(aRadius, g2, xx, minAxisValue);
    }
    // add an entity for the item...
    if (entities != null && box.intersects(dataArea)) {
        addEntity(entities, box, dataset, series, item, xx, yyAverage);
    }
}
Also used : OutlierList(org.jfree.chart.renderer.OutlierList) Stroke(java.awt.Stroke) Shape(java.awt.Shape) Rectangle2D(java.awt.geom.Rectangle2D) ArrayList(java.util.ArrayList) Line2D(java.awt.geom.Line2D) Paint(java.awt.Paint) Ellipse2D(java.awt.geom.Ellipse2D) Outlier(org.jfree.chart.renderer.Outlier) EntityCollection(org.jfree.chart.entity.EntityCollection) Point2D(java.awt.geom.Point2D) OutlierListCollection(org.jfree.chart.renderer.OutlierListCollection) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) OutlierList(org.jfree.chart.renderer.OutlierList) List(java.util.List) BoxAndWhiskerXYDataset(org.jfree.data.statistics.BoxAndWhiskerXYDataset) RectangleEdge(org.jfree.chart.api.RectangleEdge)

Example 73 with RectangleEdge

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

the class XYDifferenceRenderer method drawItemPass1.

/**
 * Draws the visual representation of a single data item, second pass.  In
 * the second pass, the renderer draws the lines and shapes for the
 * individual points in the two series.
 *
 * @param x_graphics  the graphics device.
 * @param x_dataArea  the area within which the data is being drawn.
 * @param x_info  collects information about the drawing.
 * @param x_plot  the plot (can be used to obtain standard color
 *         information etc).
 * @param x_domainAxis  the domain (horizontal) axis.
 * @param x_rangeAxis  the range (vertical) axis.
 * @param x_dataset  the dataset.
 * @param x_series  the series index (zero-based).
 * @param x_item  the item index (zero-based).
 * @param x_crosshairState  crosshair information for the plot
 *                          ({@code null} permitted).
 */
protected void drawItemPass1(Graphics2D x_graphics, Rectangle2D x_dataArea, PlotRenderingInfo x_info, XYPlot x_plot, ValueAxis x_domainAxis, ValueAxis x_rangeAxis, XYDataset x_dataset, int x_series, int x_item, CrosshairState x_crosshairState) {
    Shape l_entityArea = null;
    EntityCollection l_entities = null;
    if (null != x_info) {
        l_entities = x_info.getOwner().getEntityCollection();
    }
    Paint l_seriesPaint = getItemPaint(x_series, x_item);
    Stroke l_seriesStroke = getItemStroke(x_series, x_item);
    x_graphics.setPaint(l_seriesPaint);
    x_graphics.setStroke(l_seriesStroke);
    PlotOrientation l_orientation = x_plot.getOrientation();
    RectangleEdge l_domainAxisLocation = x_plot.getDomainAxisEdge();
    RectangleEdge l_rangeAxisLocation = x_plot.getRangeAxisEdge();
    double l_x0 = x_dataset.getXValue(x_series, x_item);
    double l_y0 = x_dataset.getYValue(x_series, x_item);
    double l_x1 = x_domainAxis.valueToJava2D(l_x0, x_dataArea, l_domainAxisLocation);
    double l_y1 = x_rangeAxis.valueToJava2D(l_y0, x_dataArea, l_rangeAxisLocation);
    if (getShapesVisible()) {
        Shape l_shape = getItemShape(x_series, x_item);
        if (l_orientation == PlotOrientation.HORIZONTAL) {
            l_shape = ShapeUtils.createTranslatedShape(l_shape, l_y1, l_x1);
        } else {
            l_shape = ShapeUtils.createTranslatedShape(l_shape, l_x1, l_y1);
        }
        if (l_shape.intersects(x_dataArea)) {
            x_graphics.setPaint(getItemPaint(x_series, x_item));
            x_graphics.fill(l_shape);
        }
        l_entityArea = l_shape;
    }
    // add an entity for the item...
    if (null != l_entities) {
        if (null == l_entityArea) {
            l_entityArea = new Rectangle2D.Double((l_x1 - 2), (l_y1 - 2), 4, 4);
        }
        String l_tip = null;
        XYToolTipGenerator l_tipGenerator = getToolTipGenerator(x_series, x_item);
        if (null != l_tipGenerator) {
            l_tip = l_tipGenerator.generateToolTip(x_dataset, x_series, x_item);
        }
        String l_url = null;
        XYURLGenerator l_urlGenerator = getURLGenerator();
        if (null != l_urlGenerator) {
            l_url = l_urlGenerator.generateURL(x_dataset, x_series, x_item);
        }
        XYItemEntity l_entity = new XYItemEntity(l_entityArea, x_dataset, x_series, x_item, l_tip, l_url);
        l_entities.add(l_entity);
    }
    // draw the item label if there is one...
    if (isItemLabelVisible(x_series, x_item)) {
        drawItemLabel(x_graphics, l_orientation, x_dataset, x_series, x_item, l_x1, l_y1, (l_y1 < 0.0));
    }
    int datasetIndex = x_plot.indexOf(x_dataset);
    updateCrosshairValues(x_crosshairState, l_x0, l_y0, datasetIndex, l_x1, l_y1, l_orientation);
    if (0 == x_item) {
        return;
    }
    double l_x2 = x_domainAxis.valueToJava2D(x_dataset.getXValue(x_series, (x_item - 1)), x_dataArea, l_domainAxisLocation);
    double l_y2 = x_rangeAxis.valueToJava2D(x_dataset.getYValue(x_series, (x_item - 1)), x_dataArea, l_rangeAxisLocation);
    Line2D l_line = null;
    if (PlotOrientation.HORIZONTAL == l_orientation) {
        l_line = new Line2D.Double(l_y1, l_x1, l_y2, l_x2);
    } else if (PlotOrientation.VERTICAL == l_orientation) {
        l_line = new Line2D.Double(l_x1, l_y1, l_x2, l_y2);
    }
    if ((null != l_line) && l_line.intersects(x_dataArea)) {
        x_graphics.setPaint(getItemPaint(x_series, x_item));
        x_graphics.setStroke(getItemStroke(x_series, x_item));
        x_graphics.draw(l_line);
    }
}
Also used : Stroke(java.awt.Stroke) PlotOrientation(org.jfree.chart.plot.PlotOrientation) Shape(java.awt.Shape) XYURLGenerator(org.jfree.chart.urls.XYURLGenerator) Rectangle2D(java.awt.geom.Rectangle2D) Paint(java.awt.Paint) Line2D(java.awt.geom.Line2D) Paint(java.awt.Paint) XYItemEntity(org.jfree.chart.entity.XYItemEntity) EntityCollection(org.jfree.chart.entity.EntityCollection) XYToolTipGenerator(org.jfree.chart.labels.XYToolTipGenerator) RectangleEdge(org.jfree.chart.api.RectangleEdge)

Example 74 with RectangleEdge

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

the class BarRenderer 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) {
    // nothing is drawn if the row index is not included in the list with
    // the indices of the visible rows...
    int visibleRow = state.getVisibleSeriesIndex(row);
    if (visibleRow < 0) {
        return;
    }
    // nothing is drawn for null values...
    Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;
    }
    final double value = dataValue.doubleValue();
    PlotOrientation orientation = plot.getOrientation();
    double barW0 = calculateBarW0(plot, orientation, dataArea, domainAxis, state, visibleRow, column);
    double[] barL0L1 = calculateBarL0L1(value);
    if (barL0L1 == null) {
        // the bar is not visible
        return;
    }
    RectangleEdge edge = plot.getRangeAxisEdge();
    double transL0 = rangeAxis.valueToJava2D(barL0L1[0], dataArea, edge);
    double transL1 = rangeAxis.valueToJava2D(barL0L1[1], dataArea, edge);
    // in the following code, barL0 is (in Java2D coordinates) the LEFT
    // end of the bar for a horizontal bar chart, and the TOP end of the
    // bar for a vertical bar chart.  Whether this is the BASE of the bar
    // or not depends also on (a) whether the data value is 'negative'
    // relative to the base value and (b) whether or not the range axis is
    // inverted.  This only matters if/when we apply the minimumBarLength
    // attribute, because we should extend the non-base end of the bar
    boolean positive = (value >= this.base);
    boolean inverted = rangeAxis.isInverted();
    double barL0 = Math.min(transL0, transL1);
    double barLength = Math.abs(transL1 - transL0);
    double barLengthAdj = 0.0;
    if (barLength > 0.0 && barLength < getMinimumBarLength()) {
        barLengthAdj = getMinimumBarLength() - barLength;
    }
    double barL0Adj = 0.0;
    RectangleEdge barBase;
    if (orientation == PlotOrientation.HORIZONTAL) {
        if (positive && inverted || !positive && !inverted) {
            barL0Adj = barLengthAdj;
            barBase = RectangleEdge.RIGHT;
        } else {
            barBase = RectangleEdge.LEFT;
        }
    } else {
        if (positive && !inverted || !positive && inverted) {
            barL0Adj = barLengthAdj;
            barBase = RectangleEdge.BOTTOM;
        } else {
            barBase = RectangleEdge.TOP;
        }
    }
    // draw the bar...
    Rectangle2D bar;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar = new Rectangle2D.Double(barL0 - barL0Adj, barW0, barLength + barLengthAdj, state.getBarWidth());
    } else {
        bar = new Rectangle2D.Double(barW0, barL0 - barL0Adj, state.getBarWidth(), barLength + barLengthAdj);
    }
    if (state.getElementHinting()) {
        KeyedValues2DItemKey key = new KeyedValues2DItemKey(dataset.getRowKey(row), dataset.getColumnKey(column));
        beginElementGroup(g2, key);
    }
    if (getShadowsVisible()) {
        this.barPainter.paintBarShadow(g2, this, row, column, bar, barBase, true);
    }
    this.barPainter.paintBar(g2, this, row, column, bar, barBase);
    if (state.getElementHinting()) {
        endElementGroup(g2);
    }
    CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0));
    }
    // submit the current data point as a crosshair candidate
    int datasetIndex = plot.indexOf(dataset);
    updateCrosshairValues(state.getCrosshairState(), dataset.getRowKey(row), dataset.getColumnKey(column), value, datasetIndex, barW0, barL0, orientation);
    // 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) EntityCollection(org.jfree.chart.entity.EntityCollection) KeyedValues2DItemKey(org.jfree.data.KeyedValues2DItemKey) Rectangle2D(java.awt.geom.Rectangle2D) CategoryItemLabelGenerator(org.jfree.chart.labels.CategoryItemLabelGenerator) Paint(java.awt.Paint) RectangleEdge(org.jfree.chart.api.RectangleEdge)

Example 75 with RectangleEdge

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

the class GroupedStackedBarRenderer method drawItem.

/**
 * Draws a stacked bar for a specific item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the plot area.
 * @param plot  the plot.
 * @param domainAxis  the domain (category) axis.
 * @param rangeAxis  the range (value) axis.
 * @param dataset  the data.
 * @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) {
    // nothing is drawn for null values...
    Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;
    }
    double value = dataValue.doubleValue();
    Comparable group = this.seriesToGroupMap.getGroup(dataset.getRowKey(row));
    PlotOrientation orientation = plot.getOrientation();
    double barW0 = calculateBarW0(plot, orientation, dataArea, domainAxis, state, row, column);
    double positiveBase = 0.0;
    double negativeBase = 0.0;
    for (int i = 0; i < row; i++) {
        if (group.equals(this.seriesToGroupMap.getGroup(dataset.getRowKey(i)))) {
            Number v = dataset.getValue(i, column);
            if (v != null) {
                double d = v.doubleValue();
                if (d > 0) {
                    positiveBase = positiveBase + d;
                } else {
                    negativeBase = negativeBase + d;
                }
            }
        }
    }
    double translatedBase;
    double translatedValue;
    boolean positive = (value > 0.0);
    boolean inverted = rangeAxis.isInverted();
    RectangleEdge barBase;
    if (orientation == PlotOrientation.HORIZONTAL) {
        if (positive && inverted || !positive && !inverted) {
            barBase = RectangleEdge.RIGHT;
        } else {
            barBase = RectangleEdge.LEFT;
        }
    } else {
        if (positive && !inverted || !positive && inverted) {
            barBase = RectangleEdge.BOTTOM;
        } else {
            barBase = RectangleEdge.TOP;
        }
    }
    RectangleEdge location = plot.getRangeAxisEdge();
    if (value > 0.0) {
        translatedBase = rangeAxis.valueToJava2D(positiveBase, dataArea, location);
        translatedValue = rangeAxis.valueToJava2D(positiveBase + value, dataArea, location);
    } else {
        translatedBase = rangeAxis.valueToJava2D(negativeBase, dataArea, location);
        translatedValue = rangeAxis.valueToJava2D(negativeBase + value, dataArea, location);
    }
    double barL0 = Math.min(translatedBase, translatedValue);
    double barLength = Math.max(Math.abs(translatedValue - translatedBase), getMinimumBarLength());
    Rectangle2D bar;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar = new Rectangle2D.Double(barL0, barW0, barLength, state.getBarWidth());
    } else {
        bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(), barLength);
    }
    getBarPainter().paintBar(g2, this, row, column, bar, barBase);
    CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0));
    }
    // collect entity and tool tip information...
    if (state.getInfo() != null) {
        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            addItemEntity(entities, dataset, row, column, bar);
        }
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) EntityCollection(org.jfree.chart.entity.EntityCollection) Rectangle2D(java.awt.geom.Rectangle2D) CategoryItemLabelGenerator(org.jfree.chart.labels.CategoryItemLabelGenerator) 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