Search in sources :

Example 6 with RectangleEdge

use of org.jfree.chart.util.RectangleEdge in project graphcode2vec by graphcode2vec.

the class StatisticalLineAndShapeRenderer method drawItem.

/**
 * Draw a single data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the area in which the data is drawn.
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset (a {@link StatisticalCategoryDataset} is
 *                 required).
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 * @param pass  the pass.
 */
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, boolean selected, int pass) {
    // do nothing if item is not visible
    if (!getItemVisible(row, column)) {
        return;
    }
    // to the superclass (LineAndShapeRenderer) behaviour...
    if (!(dataset instanceof StatisticalCategoryDataset)) {
        super.drawItem(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, row, column, selected, pass);
        return;
    }
    int visibleRow = state.getVisibleSeriesIndex(row);
    if (visibleRow < 0) {
        return;
    }
    int visibleRowCount = state.getVisibleSeriesCount();
    StatisticalCategoryDataset statDataset = (StatisticalCategoryDataset) dataset;
    Number meanValue = statDataset.getMeanValue(row, column);
    if (meanValue == null) {
        return;
    }
    PlotOrientation orientation = plot.getOrientation();
    // current data point...
    double x1;
    if (getUseSeriesOffset()) {
        x1 = domainAxis.getCategorySeriesMiddle(column, dataset.getColumnCount(), visibleRow, visibleRowCount, getItemMargin(), dataArea, plot.getDomainAxisEdge());
    } else {
        x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
    }
    double y1 = rangeAxis.valueToJava2D(meanValue.doubleValue(), dataArea, plot.getRangeAxisEdge());
    // draw the standard deviation lines *before* the shapes (if they're
    // visible) - it looks better if the shape fill colour is different to
    // the line colour
    Number sdv = statDataset.getStdDevValue(row, column);
    if (pass == 1 && sdv != null) {
        // standard deviation lines
        RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
        double valueDelta = sdv.doubleValue();
        double highVal, lowVal;
        if ((meanValue.doubleValue() + valueDelta) > rangeAxis.getRange().getUpperBound()) {
            highVal = rangeAxis.valueToJava2D(rangeAxis.getRange().getUpperBound(), dataArea, yAxisLocation);
        } else {
            highVal = rangeAxis.valueToJava2D(meanValue.doubleValue() + valueDelta, dataArea, yAxisLocation);
        }
        if ((meanValue.doubleValue() + valueDelta) < rangeAxis.getRange().getLowerBound()) {
            lowVal = rangeAxis.valueToJava2D(rangeAxis.getRange().getLowerBound(), dataArea, yAxisLocation);
        } else {
            lowVal = rangeAxis.valueToJava2D(meanValue.doubleValue() - valueDelta, dataArea, yAxisLocation);
        }
        if (this.errorIndicatorPaint != null) {
            g2.setPaint(this.errorIndicatorPaint);
        } else {
            g2.setPaint(getItemPaint(row, column, selected));
        }
        if (this.errorIndicatorStroke != null) {
            g2.setStroke(this.errorIndicatorStroke);
        } else {
            g2.setStroke(getItemOutlineStroke(row, column, selected));
        }
        Line2D line = new Line2D.Double();
        if (orientation == PlotOrientation.HORIZONTAL) {
            line.setLine(lowVal, x1, highVal, x1);
            g2.draw(line);
            line.setLine(lowVal, x1 - 5.0d, lowVal, x1 + 5.0d);
            g2.draw(line);
            line.setLine(highVal, x1 - 5.0d, highVal, x1 + 5.0d);
            g2.draw(line);
        } else {
            // PlotOrientation.VERTICAL
            line.setLine(x1, lowVal, x1, highVal);
            g2.draw(line);
            line.setLine(x1 - 5.0d, highVal, x1 + 5.0d, highVal);
            g2.draw(line);
            line.setLine(x1 - 5.0d, lowVal, x1 + 5.0d, lowVal);
            g2.draw(line);
        }
    }
    Shape hotspot = null;
    if (pass == 1 && getItemShapeVisible(row, column)) {
        Shape shape = getItemShape(row, column, selected);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, y1, x1);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, x1, y1);
        }
        hotspot = shape;
        if (getItemShapeFilled(row, column)) {
            if (getUseFillPaint()) {
                g2.setPaint(getItemFillPaint(row, column, selected));
            } else {
                g2.setPaint(getItemPaint(row, column, selected));
            }
            g2.fill(shape);
        }
        if (getDrawOutlines()) {
            if (getUseOutlinePaint()) {
                g2.setPaint(getItemOutlinePaint(row, column, selected));
            } else {
                g2.setPaint(getItemPaint(row, column, selected));
            }
            g2.setStroke(getItemOutlineStroke(row, column, selected));
            g2.draw(shape);
        }
        // draw the item label if there is one...
        if (isItemLabelVisible(row, column, selected)) {
            if (orientation == PlotOrientation.HORIZONTAL) {
                drawItemLabel(g2, orientation, dataset, row, column, selected, y1, x1, (meanValue.doubleValue() < 0.0));
            } else if (orientation == PlotOrientation.VERTICAL) {
                drawItemLabel(g2, orientation, dataset, row, column, selected, x1, y1, (meanValue.doubleValue() < 0.0));
            }
        }
    }
    if (pass == 0 && getItemLineVisible(row, column)) {
        if (column != 0) {
            Number previousValue = statDataset.getValue(row, column - 1);
            if (previousValue != null) {
                // previous data point...
                double previous = previousValue.doubleValue();
                double x0;
                if (getUseSeriesOffset()) {
                    x0 = domainAxis.getCategorySeriesMiddle(column - 1, dataset.getColumnCount(), visibleRow, visibleRowCount, getItemMargin(), dataArea, plot.getDomainAxisEdge());
                } else {
                    x0 = domainAxis.getCategoryMiddle(column - 1, getColumnCount(), dataArea, plot.getDomainAxisEdge());
                }
                double y0 = rangeAxis.valueToJava2D(previous, dataArea, plot.getRangeAxisEdge());
                Line2D line = null;
                if (orientation == PlotOrientation.HORIZONTAL) {
                    line = new Line2D.Double(y0, x0, y1, x1);
                } else if (orientation == PlotOrientation.VERTICAL) {
                    line = new Line2D.Double(x0, y0, x1, y1);
                }
                g2.setPaint(getItemPaint(row, column, selected));
                g2.setStroke(getItemStroke(row, column, selected));
                g2.draw(line);
            }
        }
    }
    if (pass == 1) {
        // add an item entity, if this information is being collected
        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            addEntity(entities, hotspot, dataset, row, column, selected, x1, y1);
        }
    }
}
Also used : StatisticalCategoryDataset(org.jfree.data.statistics.StatisticalCategoryDataset) PlotOrientation(org.jfree.chart.plot.PlotOrientation) Shape(java.awt.Shape) EntityCollection(org.jfree.chart.entity.EntityCollection) Line2D(java.awt.geom.Line2D) Paint(java.awt.Paint) RectangleEdge(org.jfree.chart.util.RectangleEdge)

Example 7 with RectangleEdge

use of org.jfree.chart.util.RectangleEdge in project graphcode2vec by graphcode2vec.

the class CandlestickRenderer method initialise.

/**
 * Initialises the renderer then returns the number of 'passes' through the
 * data that the renderer will require (usually just one).  This method
 * will be called before the first item is rendered, giving the renderer
 * an opportunity to initialise any state information it wants to maintain.
 * The renderer can do nothing if it chooses.
 *
 * @param g2  the graphics device.
 * @param dataArea  the area inside the axes.
 * @param plot  the plot.
 * @param dataset  the data.
 * @param info  an optional info collection object to return data back to
 *              the caller.
 *
 * @return The number of passes the renderer requires.
 */
public XYItemRendererState initialise(Graphics2D g2, Rectangle2D dataArea, XYPlot plot, XYDataset dataset, PlotRenderingInfo info) {
    // calculate the maximum allowed candle width from the axis...
    ValueAxis axis = plot.getDomainAxis();
    double x1 = axis.getLowerBound();
    double x2 = x1 + this.maxCandleWidthInMilliseconds;
    RectangleEdge edge = plot.getDomainAxisEdge();
    double xx1 = axis.valueToJava2D(x1, dataArea, edge);
    double xx2 = axis.valueToJava2D(x2, dataArea, edge);
    this.maxCandleWidth = Math.abs(xx2 - xx1);
    // calculate the highest volume in the dataset...
    if (this.drawVolume) {
        OHLCDataset highLowDataset = (OHLCDataset) dataset;
        this.maxVolume = 0.0;
        for (int series = 0; series < highLowDataset.getSeriesCount(); series++) {
            for (int item = 0; item < highLowDataset.getItemCount(series); item++) {
                double volume = highLowDataset.getVolumeValue(series, item);
                if (volume > this.maxVolume) {
                    this.maxVolume = volume;
                }
            }
        }
    }
    return new XYItemRendererState(info);
}
Also used : OHLCDataset(org.jfree.data.xy.OHLCDataset) ValueAxis(org.jfree.chart.axis.ValueAxis) Paint(java.awt.Paint) RectangleEdge(org.jfree.chart.util.RectangleEdge)

Example 8 with RectangleEdge

use of org.jfree.chart.util.RectangleEdge in project graphcode2vec by graphcode2vec.

the class CandlestickRenderer 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 plot is being drawn.
 * @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 selected  is the item selected?
 * @param pass  the pass index.
 *
 * @since 1.2.0
 */
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, boolean selected, int pass) {
    boolean horiz;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation == PlotOrientation.HORIZONTAL) {
        horiz = true;
    } else if (orientation == PlotOrientation.VERTICAL) {
        horiz = false;
    } else {
        return;
    }
    // setup for collecting optional entity info...
    EntityCollection entities = null;
    if (state.getInfo() != null) {
        entities = state.getInfo().getOwner().getEntityCollection();
    }
    OHLCDataset highLowData = (OHLCDataset) dataset;
    double x = highLowData.getXValue(series, item);
    double yHigh = highLowData.getHighValue(series, item);
    double yLow = highLowData.getLowValue(series, item);
    double yOpen = highLowData.getOpenValue(series, item);
    double yClose = highLowData.getCloseValue(series, item);
    RectangleEdge domainEdge = plot.getDomainAxisEdge();
    double xx = domainAxis.valueToJava2D(x, dataArea, domainEdge);
    RectangleEdge edge = plot.getRangeAxisEdge();
    double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, edge);
    double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, edge);
    double yyOpen = rangeAxis.valueToJava2D(yOpen, dataArea, edge);
    double yyClose = rangeAxis.valueToJava2D(yClose, dataArea, edge);
    double volumeWidth;
    double stickWidth;
    if (this.candleWidth > 0) {
        // These are deliberately not bounded to minimums/maxCandleWidth to
        // retain old behaviour.
        volumeWidth = this.candleWidth;
        stickWidth = this.candleWidth;
    } else {
        double xxWidth = 0;
        int itemCount;
        switch(this.autoWidthMethod) {
            case WIDTHMETHOD_AVERAGE:
                itemCount = highLowData.getItemCount(series);
                if (horiz) {
                    xxWidth = dataArea.getHeight() / itemCount;
                } else {
                    xxWidth = dataArea.getWidth() / itemCount;
                }
                break;
            case WIDTHMETHOD_SMALLEST:
                // Note: It would be nice to pre-calculate this per series
                itemCount = highLowData.getItemCount(series);
                double lastPos = -1;
                xxWidth = dataArea.getWidth();
                for (int i = 0; i < itemCount; i++) {
                    double pos = domainAxis.valueToJava2D(highLowData.getXValue(series, i), dataArea, domainEdge);
                    if (lastPos != -1) {
                        xxWidth = Math.min(xxWidth, Math.abs(pos - lastPos));
                    }
                    lastPos = pos;
                }
                break;
            case WIDTHMETHOD_INTERVALDATA:
                IntervalXYDataset intervalXYData = (IntervalXYDataset) dataset;
                double startPos = domainAxis.valueToJava2D(intervalXYData.getStartXValue(series, item), dataArea, plot.getDomainAxisEdge());
                double endPos = domainAxis.valueToJava2D(intervalXYData.getEndXValue(series, item), dataArea, plot.getDomainAxisEdge());
                xxWidth = Math.abs(endPos - startPos);
                break;
        }
        xxWidth -= 2 * this.autoWidthGap;
        xxWidth *= this.autoWidthFactor;
        xxWidth = Math.min(xxWidth, this.maxCandleWidth);
        volumeWidth = Math.max(Math.min(1, this.maxCandleWidth), xxWidth);
        stickWidth = Math.max(Math.min(3, this.maxCandleWidth), xxWidth);
    }
    Paint p = getItemPaint(series, item, selected);
    Paint outlinePaint = null;
    if (this.useOutlinePaint) {
        outlinePaint = getItemOutlinePaint(series, item, selected);
    }
    Stroke s = getItemStroke(series, item, selected);
    g2.setStroke(s);
    if (this.drawVolume) {
        int volume = (int) highLowData.getVolumeValue(series, item);
        double volumeHeight = volume / this.maxVolume;
        double min, max;
        if (horiz) {
            min = dataArea.getMinX();
            max = dataArea.getMaxX();
        } else {
            min = dataArea.getMinY();
            max = dataArea.getMaxY();
        }
        double zzVolume = volumeHeight * (max - min);
        g2.setPaint(getVolumePaint());
        Composite originalComposite = g2.getComposite();
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f));
        if (horiz) {
            g2.fill(new Rectangle2D.Double(min, xx - volumeWidth / 2, zzVolume, volumeWidth));
        } else {
            g2.fill(new Rectangle2D.Double(xx - volumeWidth / 2, max - zzVolume, volumeWidth, zzVolume));
        }
        g2.setComposite(originalComposite);
    }
    if (this.useOutlinePaint) {
        g2.setPaint(outlinePaint);
    } else {
        g2.setPaint(p);
    }
    double yyMaxOpenClose = Math.max(yyOpen, yyClose);
    double yyMinOpenClose = Math.min(yyOpen, yyClose);
    double maxOpenClose = Math.max(yOpen, yClose);
    double minOpenClose = Math.min(yOpen, yClose);
    // draw the upper shadow
    if (yHigh > maxOpenClose) {
        if (horiz) {
            g2.draw(new Line2D.Double(yyHigh, xx, yyMaxOpenClose, xx));
        } else {
            g2.draw(new Line2D.Double(xx, yyHigh, xx, yyMaxOpenClose));
        }
    }
    // draw the lower shadow
    if (yLow < minOpenClose) {
        if (horiz) {
            g2.draw(new Line2D.Double(yyLow, xx, yyMinOpenClose, xx));
        } else {
            g2.draw(new Line2D.Double(xx, yyLow, xx, yyMinOpenClose));
        }
    }
    // draw the body
    Rectangle2D body = null;
    Rectangle2D hotspot = null;
    double length = Math.abs(yyHigh - yyLow);
    double base = Math.min(yyHigh, yyLow);
    if (horiz) {
        body = new Rectangle2D.Double(yyMinOpenClose, xx - stickWidth / 2, yyMaxOpenClose - yyMinOpenClose, stickWidth);
        hotspot = new Rectangle2D.Double(base, xx - stickWidth / 2, length, stickWidth);
    } else {
        body = new Rectangle2D.Double(xx - stickWidth / 2, yyMinOpenClose, stickWidth, yyMaxOpenClose - yyMinOpenClose);
        hotspot = new Rectangle2D.Double(xx - stickWidth / 2, base, stickWidth, length);
    }
    if (yClose > yOpen) {
        if (this.upPaint != null) {
            g2.setPaint(this.upPaint);
        } else {
            g2.setPaint(p);
        }
        g2.fill(body);
    } else {
        if (this.downPaint != null) {
            g2.setPaint(this.downPaint);
        } else {
            g2.setPaint(p);
        }
        g2.fill(body);
    }
    if (this.useOutlinePaint) {
        g2.setPaint(outlinePaint);
    } else {
        g2.setPaint(p);
    }
    g2.draw(body);
    // add an entity for the item...
    if (entities != null) {
        addEntity(entities, hotspot, dataset, series, item, selected, 0.0, 0.0);
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Stroke(java.awt.Stroke) AlphaComposite(java.awt.AlphaComposite) Composite(java.awt.Composite) IntervalXYDataset(org.jfree.data.xy.IntervalXYDataset) Rectangle2D(java.awt.geom.Rectangle2D) Paint(java.awt.Paint) Line2D(java.awt.geom.Line2D) Paint(java.awt.Paint) OHLCDataset(org.jfree.data.xy.OHLCDataset) EntityCollection(org.jfree.chart.entity.EntityCollection) RectangleEdge(org.jfree.chart.util.RectangleEdge)

Example 9 with RectangleEdge

use of org.jfree.chart.util.RectangleEdge in project graphcode2vec by graphcode2vec.

the class ClusteredXYBarRenderer method drawItem.

/**
 * Draws the visual representation of a single data item. This method
 * is mostly copied from the superclass, the change is that in the
 * calculated space for a singe bar we draw bars for each series next to
 * each other. The width of each bar is the available width divided by
 * the number of series. Bars for each series are drawn in order left to
 * right.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the area within which the plot is being drawn.
 * @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.
 * @param item  the item index.
 * @param pass  the pass index.
 */
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, boolean selected, int pass) {
    IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset;
    double y0;
    double y1;
    if (getUseYInterval()) {
        y0 = intervalDataset.getStartYValue(series, item);
        y1 = intervalDataset.getEndYValue(series, item);
    } else {
        y0 = getBase();
        y1 = intervalDataset.getYValue(series, item);
    }
    if (Double.isNaN(y0) || Double.isNaN(y1)) {
        return;
    }
    double yy0 = rangeAxis.valueToJava2D(y0, dataArea, plot.getRangeAxisEdge());
    double yy1 = rangeAxis.valueToJava2D(y1, dataArea, plot.getRangeAxisEdge());
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    double x0 = intervalDataset.getStartXValue(series, item);
    double xx0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
    double x1 = intervalDataset.getEndXValue(series, item);
    double xx1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    // this may be negative
    double intervalW = xx1 - xx0;
    double baseX = xx0;
    if (this.centerBarAtStartValue) {
        baseX = baseX - intervalW / 2.0;
    }
    double m = getMargin();
    if (m > 0.0) {
        double cut = intervalW * getMargin();
        intervalW = intervalW - cut;
        baseX = baseX + (cut / 2);
    }
    // we don't need the sign
    double intervalH = Math.abs(yy0 - yy1);
    PlotOrientation orientation = plot.getOrientation();
    int numSeries = dataset.getSeriesCount();
    // may be negative
    double seriesBarWidth = intervalW / numSeries;
    Rectangle2D bar = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        double barY0 = baseX + (seriesBarWidth * series);
        double barY1 = barY0 + seriesBarWidth;
        double rx = Math.min(yy0, yy1);
        double rw = intervalH;
        double ry = Math.min(barY0, barY1);
        double rh = Math.abs(barY1 - barY0);
        bar = new Rectangle2D.Double(rx, ry, rw, rh);
    } else if (orientation == PlotOrientation.VERTICAL) {
        double barX0 = baseX + (seriesBarWidth * series);
        double barX1 = barX0 + seriesBarWidth;
        double rx = Math.min(barX0, barX1);
        double rw = Math.abs(barX1 - barX0);
        double ry = Math.min(yy0, yy1);
        double rh = intervalH;
        bar = new Rectangle2D.Double(rx, ry, rw, rh);
    }
    boolean positive = (y1 > 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;
        }
    }
    if (pass == 0 && getShadowsVisible()) {
        getBarPainter().paintBarShadow(g2, this, series, item, selected, bar, barBase, !getUseYInterval());
    }
    if (pass == 1) {
        getBarPainter().paintBar(g2, this, series, item, selected, bar, barBase);
        if (isItemLabelVisible(series, item, selected)) {
            XYItemLabelGenerator generator = getItemLabelGenerator(series, item, selected);
            drawItemLabelForBar(g2, plot, dataset, series, item, selected, generator, bar, y1 < 0.0);
        }
        // add an entity for the item...
        if (state.getInfo() != null) {
            EntityCollection entities = state.getInfo().getOwner().getEntityCollection();
            if (entities != null) {
                addEntity(entities, bar, dataset, series, item, selected, bar.getCenterX(), bar.getCenterY());
            }
        }
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) EntityCollection(org.jfree.chart.entity.EntityCollection) IntervalXYDataset(org.jfree.data.xy.IntervalXYDataset) Rectangle2D(java.awt.geom.Rectangle2D) XYItemLabelGenerator(org.jfree.chart.labels.XYItemLabelGenerator) RectangleEdge(org.jfree.chart.util.RectangleEdge)

Example 10 with RectangleEdge

use of org.jfree.chart.util.RectangleEdge in project graphcode2vec by graphcode2vec.

the class IntervalBarRenderer method drawInterval.

/**
 * Draws a single interval.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the data plot area.
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the data.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 * @param selected  is the item selected?
 *
 * @since 1.2.0
 */
protected void drawInterval(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, IntervalCategoryDataset dataset, int row, int column, boolean selected) {
    int visibleRow = state.getVisibleSeriesIndex(row);
    if (visibleRow < 0) {
        return;
    }
    int seriesCount = state.getVisibleSeriesCount() >= 0 ? state.getVisibleSeriesCount() : getRowCount();
    int categoryCount = getColumnCount();
    PlotOrientation orientation = plot.getOrientation();
    double rectX = 0.0;
    double rectY = 0.0;
    RectangleEdge domainAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
    // Y0
    Number value0 = dataset.getEndValue(row, column);
    if (value0 == null) {
        return;
    }
    double java2dValue0 = rangeAxis.valueToJava2D(value0.doubleValue(), dataArea, rangeAxisLocation);
    // Y1
    Number value1 = dataset.getStartValue(row, column);
    if (value1 == null) {
        return;
    }
    double java2dValue1 = rangeAxis.valueToJava2D(value1.doubleValue(), dataArea, rangeAxisLocation);
    if (java2dValue1 < java2dValue0) {
        double temp = java2dValue1;
        java2dValue1 = java2dValue0;
        java2dValue0 = temp;
    }
    // BAR WIDTH
    double rectWidth = state.getBarWidth();
    // BAR HEIGHT
    double rectHeight = Math.abs(java2dValue1 - java2dValue0);
    RectangleEdge barBase = RectangleEdge.LEFT;
    if (orientation == PlotOrientation.HORIZONTAL) {
        // BAR Y
        rectY = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, domainAxisLocation);
        if (seriesCount > 1) {
            double seriesGap = dataArea.getHeight() * getItemMargin() / (categoryCount * (seriesCount - 1));
            rectY = rectY + visibleRow * (state.getBarWidth() + seriesGap);
        } else {
            rectY = rectY + visibleRow * state.getBarWidth();
        }
        rectX = java2dValue0;
        rectHeight = state.getBarWidth();
        rectWidth = Math.abs(java2dValue1 - java2dValue0);
        barBase = RectangleEdge.LEFT;
    } else if (orientation == PlotOrientation.VERTICAL) {
        // BAR X
        rectX = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, domainAxisLocation);
        if (seriesCount > 1) {
            double seriesGap = dataArea.getWidth() * getItemMargin() / (categoryCount * (seriesCount - 1));
            rectX = rectX + visibleRow * (state.getBarWidth() + seriesGap);
        } else {
            rectX = rectX + visibleRow * state.getBarWidth();
        }
        rectY = java2dValue0;
        barBase = RectangleEdge.BOTTOM;
    }
    Rectangle2D bar = new Rectangle2D.Double(rectX, rectY, rectWidth, rectHeight);
    BarPainter painter = getBarPainter();
    if (getShadowsVisible()) {
        painter.paintBarShadow(g2, this, row, column, selected, bar, barBase, false);
    }
    getBarPainter().paintBar(g2, this, row, column, selected, bar, barBase);
    CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column, selected);
    if (generator != null && isItemLabelVisible(row, column, selected)) {
        drawItemLabelForBar(g2, plot, dataset, row, column, selected, generator, bar, false);
    }
    // add an item entity, if this information is being collected
    EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
        addEntity(entities, bar, dataset, row, column, selected);
    }
}
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.util.RectangleEdge)

Aggregations

RectangleEdge (org.jfree.chart.util.RectangleEdge)88 Rectangle2D (java.awt.geom.Rectangle2D)48 Paint (java.awt.Paint)45 PlotOrientation (org.jfree.chart.plot.PlotOrientation)44 EntityCollection (org.jfree.chart.entity.EntityCollection)33 Stroke (java.awt.Stroke)20 Shape (java.awt.Shape)18 Line2D (java.awt.geom.Line2D)17 AxisSpace (org.jfree.chart.axis.AxisSpace)15 ValueAxis (org.jfree.chart.axis.ValueAxis)15 CategoryItemLabelGenerator (org.jfree.chart.labels.CategoryItemLabelGenerator)12 GeneralPath (java.awt.geom.GeneralPath)10 AxisLocation (org.jfree.chart.axis.AxisLocation)7 IntervalXYDataset (org.jfree.data.xy.IntervalXYDataset)7 Point2D (java.awt.geom.Point2D)6 AxisState (org.jfree.chart.axis.AxisState)6 CategoryAxis (org.jfree.chart.axis.CategoryAxis)6 XYCrosshairState (org.jfree.chart.plot.XYCrosshairState)6 RectangleInsets (org.jfree.chart.util.RectangleInsets)6 GradientPaint (java.awt.GradientPaint)5