Search in sources :

Example 81 with PlotOrientation

use of org.jfree.chart.plot.PlotOrientation in project SIMVA-SoS by SESoS.

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 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.
 * @param item  the item index.
 * @param crosshairState  crosshair information for the plot
 *                        (<code>null</code> 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) {
    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);
    } else {
        throw new IllegalStateException();
    }
    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, bar, barBase, !getUseYInterval());
    }
    if (pass == 1) {
        getBarPainter().paintBar(g2, this, series, item, bar, barBase);
        if (isItemLabelVisible(series, item)) {
            XYItemLabelGenerator generator = getItemLabelGenerator(series, item);
            drawItemLabel(g2, dataset, series, item, plot, generator, bar, y1 < 0.0);
        }
        // add an entity for the item...
        if (info != null) {
            EntityCollection entities = info.getOwner().getEntityCollection();
            if (entities != null) {
                addEntity(entities, bar, dataset, series, item, 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.ui.RectangleEdge)

Example 82 with PlotOrientation

use of org.jfree.chart.plot.PlotOrientation in project SIMVA-SoS by SESoS.

the class BarRenderer method calculateBarWidth.

/**
 * Calculates the bar width and stores it in the renderer state.
 *
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param rendererIndex  the renderer index.
 * @param state  the renderer state.
 */
protected void calculateBarWidth(CategoryPlot plot, Rectangle2D dataArea, int rendererIndex, CategoryItemRendererState state) {
    CategoryAxis domainAxis = getDomainAxis(plot, rendererIndex);
    CategoryDataset dataset = plot.getDataset(rendererIndex);
    if (dataset != null) {
        int columns = dataset.getColumnCount();
        int rows = state.getVisibleSeriesCount() >= 0 ? state.getVisibleSeriesCount() : dataset.getRowCount();
        double space = 0.0;
        PlotOrientation orientation = plot.getOrientation();
        if (orientation == PlotOrientation.HORIZONTAL) {
            space = dataArea.getHeight();
        } else if (orientation == PlotOrientation.VERTICAL) {
            space = dataArea.getWidth();
        }
        double maxWidth = space * getMaximumBarWidth();
        double categoryMargin = 0.0;
        double currentItemMargin = 0.0;
        if (columns > 1) {
            categoryMargin = domainAxis.getCategoryMargin();
        }
        if (rows > 1) {
            currentItemMargin = getItemMargin();
        }
        double used = space * (1 - domainAxis.getLowerMargin() - domainAxis.getUpperMargin() - categoryMargin - currentItemMargin);
        if ((rows * columns) > 0) {
            state.setBarWidth(Math.min(used / (rows * columns), maxWidth));
        } else {
            state.setBarWidth(Math.min(used, maxWidth));
        }
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) CategoryAxis(org.jfree.chart.axis.CategoryAxis) CategoryDataset(org.jfree.data.category.CategoryDataset) Paint(java.awt.Paint)

Example 83 with PlotOrientation

use of org.jfree.chart.plot.PlotOrientation in project SIMVA-SoS by SESoS.

the class BarRenderer3D method drawRangeLine.

/**
 * Draws a line perpendicular to the range axis.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param axis  the value axis.
 * @param dataArea  the area for plotting data (not yet adjusted for any 3D
 *                  effect).
 * @param value  the value at which the grid line should be drawn.
 * @param paint  the paint.
 * @param stroke  the stroke.
 *
 * @see #drawRangeGridline
 *
 * @since 1.0.13
 */
@Override
public void drawRangeLine(Graphics2D g2, CategoryPlot plot, ValueAxis axis, Rectangle2D dataArea, double value, Paint paint, Stroke stroke) {
    Range range = axis.getRange();
    if (!range.contains(value)) {
        return;
    }
    Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(), dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset());
    Line2D line1 = null;
    Line2D line2 = null;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation == PlotOrientation.HORIZONTAL) {
        double x0 = axis.valueToJava2D(value, adjusted, plot.getRangeAxisEdge());
        double x1 = x0 + getXOffset();
        double y0 = dataArea.getMaxY();
        double y1 = y0 - getYOffset();
        double y2 = dataArea.getMinY();
        line1 = new Line2D.Double(x0, y0, x1, y1);
        line2 = new Line2D.Double(x1, y1, x1, y2);
    } else if (orientation == PlotOrientation.VERTICAL) {
        double y0 = axis.valueToJava2D(value, adjusted, plot.getRangeAxisEdge());
        double y1 = y0 - getYOffset();
        double x0 = dataArea.getMinX();
        double x1 = x0 + getXOffset();
        double x2 = dataArea.getMaxX();
        line1 = new Line2D.Double(x0, y0, x1, y1);
        line2 = new Line2D.Double(x1, y1, x2, y1);
    }
    g2.setPaint(paint);
    g2.setStroke(stroke);
    g2.draw(line1);
    g2.draw(line2);
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Rectangle2D(java.awt.geom.Rectangle2D) Range(org.jfree.data.Range) Line2D(java.awt.geom.Line2D)

Example 84 with PlotOrientation

use of org.jfree.chart.plot.PlotOrientation in project SIMVA-SoS by SESoS.

the class BarRenderer3D method drawRangeMarker.

/**
 * Draws a range marker.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param axis  the value axis.
 * @param marker  the marker.
 * @param dataArea  the area for plotting data (not including 3D effect).
 */
@Override
public void drawRangeMarker(Graphics2D g2, CategoryPlot plot, ValueAxis axis, Marker marker, Rectangle2D dataArea) {
    Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(), dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset());
    if (marker instanceof ValueMarker) {
        ValueMarker vm = (ValueMarker) marker;
        double value = vm.getValue();
        Range range = axis.getRange();
        if (!range.contains(value)) {
            return;
        }
        GeneralPath path = null;
        PlotOrientation orientation = plot.getOrientation();
        if (orientation == PlotOrientation.HORIZONTAL) {
            float x = (float) axis.valueToJava2D(value, adjusted, plot.getRangeAxisEdge());
            float y = (float) adjusted.getMaxY();
            path = new GeneralPath();
            path.moveTo(x, y);
            path.lineTo((float) (x + getXOffset()), y - (float) getYOffset());
            path.lineTo((float) (x + getXOffset()), (float) (adjusted.getMinY() - getYOffset()));
            path.lineTo(x, (float) adjusted.getMinY());
            path.closePath();
        } else if (orientation == PlotOrientation.VERTICAL) {
            float y = (float) axis.valueToJava2D(value, adjusted, plot.getRangeAxisEdge());
            float x = (float) dataArea.getX();
            path = new GeneralPath();
            path.moveTo(x, y);
            path.lineTo(x + (float) this.xOffset, y - (float) this.yOffset);
            path.lineTo((float) (adjusted.getMaxX() + this.xOffset), y - (float) this.yOffset);
            path.lineTo((float) (adjusted.getMaxX()), y);
            path.closePath();
        } else {
            throw new IllegalStateException();
        }
        g2.setPaint(marker.getPaint());
        g2.fill(path);
        g2.setPaint(marker.getOutlinePaint());
        g2.draw(path);
        String label = marker.getLabel();
        RectangleAnchor anchor = marker.getLabelAnchor();
        if (label != null) {
            Font labelFont = marker.getLabelFont();
            g2.setFont(labelFont);
            g2.setPaint(marker.getLabelPaint());
            Point2D coordinates = calculateRangeMarkerTextAnchorPoint(g2, orientation, dataArea, path.getBounds2D(), marker.getLabelOffset(), LengthAdjustmentType.EXPAND, anchor);
            TextUtilities.drawAlignedString(label, g2, (float) coordinates.getX(), (float) coordinates.getY(), marker.getLabelTextAnchor());
        }
    } else {
        super.drawRangeMarker(g2, plot, axis, marker, adjusted);
    // TODO: draw the interval marker with a 3D effect
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) GeneralPath(java.awt.geom.GeneralPath) Rectangle2D(java.awt.geom.Rectangle2D) RectangleAnchor(org.jfree.ui.RectangleAnchor) Range(org.jfree.data.Range) Font(java.awt.Font) Point2D(java.awt.geom.Point2D) ValueMarker(org.jfree.chart.plot.ValueMarker)

Example 85 with PlotOrientation

use of org.jfree.chart.plot.PlotOrientation in project SIMVA-SoS by SESoS.

the class BarRenderer3D method drawItem.

/**
 * Draws a 3D bar to represent one data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the area for plotting the data.
 * @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;
    }
    // check the value we are plotting...
    Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;
    }
    double value = dataValue.doubleValue();
    Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(), dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset());
    PlotOrientation orientation = plot.getOrientation();
    double barW0 = calculateBarW0(plot, orientation, adjusted, 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], adjusted, edge);
    double transL1 = rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge);
    double barL0 = Math.min(transL0, transL1);
    double barLength = Math.abs(transL1 - transL0);
    // draw the bar...
    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);
    }
    Paint itemPaint = getItemPaint(row, column);
    g2.setPaint(itemPaint);
    g2.fill(bar);
    double x0 = bar.getMinX();
    double x1 = x0 + getXOffset();
    double x2 = bar.getMaxX();
    double x3 = x2 + getXOffset();
    double y0 = bar.getMinY() - getYOffset();
    double y1 = bar.getMinY();
    double y2 = bar.getMaxY() - getYOffset();
    double y3 = bar.getMaxY();
    GeneralPath bar3dRight = null;
    GeneralPath bar3dTop;
    if (barLength > 0.0) {
        bar3dRight = new GeneralPath();
        bar3dRight.moveTo((float) x2, (float) y3);
        bar3dRight.lineTo((float) x2, (float) y1);
        bar3dRight.lineTo((float) x3, (float) y0);
        bar3dRight.lineTo((float) x3, (float) y2);
        bar3dRight.closePath();
        g2.setPaint(PaintAlpha.darker(itemPaint));
        g2.fill(bar3dRight);
    }
    bar3dTop = new GeneralPath();
    bar3dTop.moveTo((float) x0, (float) y1);
    bar3dTop.lineTo((float) x1, (float) y0);
    bar3dTop.lineTo((float) x3, (float) y0);
    bar3dTop.lineTo((float) x2, (float) y1);
    bar3dTop.closePath();
    g2.fill(bar3dTop);
    if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
        g2.setStroke(getItemOutlineStroke(row, column));
        g2.setPaint(getItemOutlinePaint(row, column));
        g2.draw(bar);
        if (bar3dRight != null) {
            g2.draw(bar3dRight);
        }
        g2.draw(bar3dTop);
    }
    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) {
        GeneralPath barOutline = new GeneralPath();
        barOutline.moveTo((float) x0, (float) y3);
        barOutline.lineTo((float) x0, (float) y1);
        barOutline.lineTo((float) x1, (float) y0);
        barOutline.lineTo((float) x3, (float) y0);
        barOutline.lineTo((float) x3, (float) y2);
        barOutline.lineTo((float) x2, (float) y3);
        barOutline.closePath();
        addItemEntity(entities, dataset, row, column, barOutline);
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) GeneralPath(java.awt.geom.GeneralPath) Rectangle2D(java.awt.geom.Rectangle2D) CategoryItemLabelGenerator(org.jfree.chart.labels.CategoryItemLabelGenerator) Paint(java.awt.Paint) Paint(java.awt.Paint) EntityCollection(org.jfree.chart.entity.EntityCollection) RectangleEdge(org.jfree.ui.RectangleEdge)

Aggregations

PlotOrientation (org.jfree.chart.plot.PlotOrientation)100 Paint (java.awt.Paint)52 RectangleEdge (org.jfree.ui.RectangleEdge)49 Rectangle2D (java.awt.geom.Rectangle2D)40 EntityCollection (org.jfree.chart.entity.EntityCollection)39 Line2D (java.awt.geom.Line2D)29 Stroke (java.awt.Stroke)20 Shape (java.awt.Shape)19 GeneralPath (java.awt.geom.GeneralPath)14 Range (org.jfree.data.Range)14 GradientPaint (java.awt.GradientPaint)13 JFreeChart (org.jfree.chart.JFreeChart)11 CategoryAxis (org.jfree.chart.axis.CategoryAxis)11 CategoryDataset (org.jfree.data.category.CategoryDataset)11 Point2D (java.awt.geom.Point2D)9 CategoryItemLabelGenerator (org.jfree.chart.labels.CategoryItemLabelGenerator)9 IntervalXYDataset (org.jfree.data.xy.IntervalXYDataset)7 AlphaComposite (java.awt.AlphaComposite)6 BasicStroke (java.awt.BasicStroke)6 Composite (java.awt.Composite)6