Search in sources :

Example 36 with RectangleEdge

use of org.jfree.ui.RectangleEdge in project SIMVA-SoS by SESoS.

the class AreaRenderer method drawItem.

/**
 * Draw a single data item.
 *
 * @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 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) {
    // do nothing if item is not visible or null
    if (!getItemVisible(row, column)) {
        return;
    }
    Number value = dataset.getValue(row, column);
    if (value == null) {
        return;
    }
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge axisEdge = plot.getDomainAxisEdge();
    int count = dataset.getColumnCount();
    float x0 = (float) domainAxis.getCategoryStart(column, count, dataArea, axisEdge);
    float x1 = (float) domainAxis.getCategoryMiddle(column, count, dataArea, axisEdge);
    float x2 = (float) domainAxis.getCategoryEnd(column, count, dataArea, axisEdge);
    x0 = Math.round(x0);
    x1 = Math.round(x1);
    x2 = Math.round(x2);
    if (this.endType == AreaRendererEndType.TRUNCATE) {
        if (column == 0) {
            x0 = x1;
        } else if (column == getColumnCount() - 1) {
            x2 = x1;
        }
    }
    double yy1 = value.doubleValue();
    double yy0 = 0.0;
    if (this.endType == AreaRendererEndType.LEVEL) {
        yy0 = yy1;
    }
    if (column > 0) {
        Number n0 = dataset.getValue(row, column - 1);
        if (n0 != null) {
            yy0 = (n0.doubleValue() + yy1) / 2.0;
        }
    }
    double yy2 = 0.0;
    if (column < dataset.getColumnCount() - 1) {
        Number n2 = dataset.getValue(row, column + 1);
        if (n2 != null) {
            yy2 = (n2.doubleValue() + yy1) / 2.0;
        }
    } else if (this.endType == AreaRendererEndType.LEVEL) {
        yy2 = yy1;
    }
    RectangleEdge edge = plot.getRangeAxisEdge();
    float y0 = (float) rangeAxis.valueToJava2D(yy0, dataArea, edge);
    float y1 = (float) rangeAxis.valueToJava2D(yy1, dataArea, edge);
    float y2 = (float) rangeAxis.valueToJava2D(yy2, dataArea, edge);
    float yz = (float) rangeAxis.valueToJava2D(0.0, dataArea, edge);
    double labelXX = x1;
    double labelYY = y1;
    g2.setPaint(getItemPaint(row, column));
    g2.setStroke(getItemStroke(row, column));
    GeneralPath area = new GeneralPath();
    if (orientation == PlotOrientation.VERTICAL) {
        area.moveTo(x0, yz);
        area.lineTo(x0, y0);
        area.lineTo(x1, y1);
        area.lineTo(x2, y2);
        area.lineTo(x2, yz);
    } else if (orientation == PlotOrientation.HORIZONTAL) {
        area.moveTo(yz, x0);
        area.lineTo(y0, x0);
        area.lineTo(y1, x1);
        area.lineTo(y2, x2);
        area.lineTo(yz, x2);
        double temp = labelXX;
        labelXX = labelYY;
        labelYY = temp;
    }
    area.closePath();
    g2.setPaint(getItemPaint(row, column));
    g2.fill(area);
    // draw the item labels if there are any...
    if (isItemLabelVisible(row, column)) {
        drawItemLabel(g2, orientation, dataset, row, column, labelXX, labelYY, (value.doubleValue() < 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), yy1, datasetIndex, x1, y1, orientation);
    // add an item entity, if this information is being collected
    EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
        addItemEntity(entities, dataset, row, column, area);
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) GeneralPath(java.awt.geom.GeneralPath) EntityCollection(org.jfree.chart.entity.EntityCollection) Paint(java.awt.Paint) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 37 with RectangleEdge

use of org.jfree.ui.RectangleEdge in project SIMVA-SoS by SESoS.

the class XYPlot method calculateRangeAxisSpace.

/**
 * Calculates the space required for the range axis/axes.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 * @param space  a carrier for the result (<code>null</code> permitted).
 *
 * @return The required space.
 */
protected AxisSpace calculateRangeAxisSpace(Graphics2D g2, Rectangle2D plotArea, AxisSpace space) {
    if (space == null) {
        space = new AxisSpace();
    }
    // reserve some space for the range axis...
    if (this.fixedRangeAxisSpace != null) {
        if (this.orientation == PlotOrientation.HORIZONTAL) {
            space.ensureAtLeast(this.fixedRangeAxisSpace.getTop(), RectangleEdge.TOP);
            space.ensureAtLeast(this.fixedRangeAxisSpace.getBottom(), RectangleEdge.BOTTOM);
        } else if (this.orientation == PlotOrientation.VERTICAL) {
            space.ensureAtLeast(this.fixedRangeAxisSpace.getLeft(), RectangleEdge.LEFT);
            space.ensureAtLeast(this.fixedRangeAxisSpace.getRight(), RectangleEdge.RIGHT);
        }
    } else {
        // reserve space for the range axes...
        for (ValueAxis axis : this.rangeAxes.values()) {
            if (axis != null) {
                RectangleEdge edge = getRangeAxisEdge(findRangeAxisIndex(axis));
                space = axis.reserveSpace(g2, this, plotArea, edge, space);
            }
        }
    }
    return space;
}
Also used : ValueAxis(org.jfree.chart.axis.ValueAxis) AxisSpace(org.jfree.chart.axis.AxisSpace) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 38 with RectangleEdge

use of org.jfree.ui.RectangleEdge in project SIMVA-SoS by SESoS.

the class XYBarRenderer 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 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  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) {
    if (!getItemVisible(series, item)) {
        return;
    }
    IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset;
    double value0;
    double value1;
    if (this.useYInterval) {
        value0 = intervalDataset.getStartYValue(series, item);
        value1 = intervalDataset.getEndYValue(series, item);
    } else {
        value0 = this.base;
        value1 = intervalDataset.getYValue(series, item);
    }
    if (Double.isNaN(value0) || Double.isNaN(value1)) {
        return;
    }
    if (value0 <= value1) {
        if (!rangeAxis.getRange().intersects(value0, value1)) {
            return;
        }
    } else {
        if (!rangeAxis.getRange().intersects(value1, value0)) {
            return;
        }
    }
    double translatedValue0 = rangeAxis.valueToJava2D(value0, dataArea, plot.getRangeAxisEdge());
    double translatedValue1 = rangeAxis.valueToJava2D(value1, dataArea, plot.getRangeAxisEdge());
    double bottom = Math.min(translatedValue0, translatedValue1);
    double top = Math.max(translatedValue0, translatedValue1);
    double startX = intervalDataset.getStartXValue(series, item);
    if (Double.isNaN(startX)) {
        return;
    }
    double endX = intervalDataset.getEndXValue(series, item);
    if (Double.isNaN(endX)) {
        return;
    }
    if (startX <= endX) {
        if (!domainAxis.getRange().intersects(startX, endX)) {
            return;
        }
    } else {
        if (!domainAxis.getRange().intersects(endX, startX)) {
            return;
        }
    }
    // is there an alignment adjustment to be made?
    if (this.barAlignmentFactor >= 0.0 && this.barAlignmentFactor <= 1.0) {
        double x = intervalDataset.getXValue(series, item);
        double interval = endX - startX;
        startX = x - interval * this.barAlignmentFactor;
        endX = startX + interval;
    }
    RectangleEdge location = plot.getDomainAxisEdge();
    double translatedStartX = domainAxis.valueToJava2D(startX, dataArea, location);
    double translatedEndX = domainAxis.valueToJava2D(endX, dataArea, location);
    double translatedWidth = Math.max(1, Math.abs(translatedEndX - translatedStartX));
    double left = Math.min(translatedStartX, translatedEndX);
    if (getMargin() > 0.0) {
        double cut = translatedWidth * getMargin();
        translatedWidth = translatedWidth - cut;
        left = left + cut / 2;
    }
    Rectangle2D bar = null;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation == PlotOrientation.HORIZONTAL) {
        // clip left and right bounds to data area
        bottom = Math.max(bottom, dataArea.getMinX());
        top = Math.min(top, dataArea.getMaxX());
        bar = new Rectangle2D.Double(bottom, left, top - bottom, translatedWidth);
    } else if (orientation == PlotOrientation.VERTICAL) {
        // clip top and bottom bounds to data area
        bottom = Math.max(bottom, dataArea.getMinY());
        top = Math.min(top, dataArea.getMaxY());
        bar = new Rectangle2D.Double(left, bottom, translatedWidth, top - bottom);
    }
    boolean positive = (value1 > 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 (getShadowsVisible()) {
        this.barPainter.paintBarShadow(g2, this, series, item, bar, barBase, !this.useYInterval);
    }
    this.barPainter.paintBar(g2, this, series, item, bar, barBase);
    if (isItemLabelVisible(series, item)) {
        XYItemLabelGenerator generator = getItemLabelGenerator(series, item);
        drawItemLabel(g2, dataset, series, item, plot, generator, bar, value1 < 0.0);
    }
    // update the crosshair point
    double x1 = (startX + endX) / 2.0;
    double y1 = dataset.getYValue(series, item);
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, location);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, plot.getRangeAxisEdge());
    int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
    updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1, plot.getOrientation());
    EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
        addEntity(entities, bar, dataset, series, item, 0.0, 0.0);
    }
}
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) Paint(java.awt.Paint) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 39 with RectangleEdge

use of org.jfree.ui.RectangleEdge in project SIMVA-SoS by SESoS.

the class XYBoxAndWhiskerRenderer method drawHorizontalItem.

/**
 * 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</code> permitted).
 * @param pass  the pass index.
 */
public void drawHorizontalItem(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);
    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 exactBoxWidth = getBoxWidth();
    double width = exactBoxWidth;
    double dataAreaX = dataArea.getHeight();
    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(yyMax, xx, yyQ3Median, xx));
    g2.draw(new Line2D.Double(yyMax, xx - width / 2, yyMax, xx + width / 2));
    // draw the lower shadow
    g2.draw(new Line2D.Double(yyMin, xx, yyQ1Median, xx));
    g2.draw(new Line2D.Double(yyMin, xx - width / 2, yyMin, xx + width / 2));
    // draw the body
    Shape box;
    if (yyQ1Median < yyQ3Median) {
        box = new Rectangle2D.Double(yyQ1Median, xx - width / 2, yyQ3Median - yyQ1Median, width);
    } else {
        box = new Rectangle2D.Double(yyQ3Median, xx - width / 2, yyQ1Median - yyQ3Median, width);
    }
    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(yyMedian, xx - width / 2, yyMedian, xx + width / 2));
    // draw average - SPECIAL AIMS REQUIREMENT
    if (yAverage != null) {
        double aRadius = width / 4;
        // before drawing it...
        if ((yyAverage > (dataArea.getMinX() - aRadius)) && (yyAverage < (dataArea.getMaxX() + aRadius))) {
            Ellipse2D.Double avgEllipse = new Ellipse2D.Double(yyAverage - aRadius, xx - aRadius, aRadius * 2, aRadius * 2);
            g2.fill(avgEllipse);
            g2.draw(avgEllipse);
        }
    }
    // add an entity for the item...
    if (entities != null && box.intersects(dataArea)) {
        addEntity(entities, box, dataset, series, item, yyAverage, xx);
    }
}
Also used : Stroke(java.awt.Stroke) Shape(java.awt.Shape) Rectangle2D(java.awt.geom.Rectangle2D) Line2D(java.awt.geom.Line2D) Paint(java.awt.Paint) Ellipse2D(java.awt.geom.Ellipse2D) EntityCollection(org.jfree.chart.entity.EntityCollection) BoxAndWhiskerXYDataset(org.jfree.data.statistics.BoxAndWhiskerXYDataset) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 40 with RectangleEdge

use of org.jfree.ui.RectangleEdge in project SIMVA-SoS by SESoS.

the class YIntervalRenderer 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 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  crosshair information for the plot
 *                        (<code>null</code> permitted).
 * @param pass  the pass index (ignored here).
 */
@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();
    }
    IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset;
    double x = intervalDataset.getXValue(series, item);
    double yLow = intervalDataset.getStartYValue(series, item);
    double yHigh = intervalDataset.getEndYValue(series, item);
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double xx = domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
    double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, yAxisLocation);
    double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, yAxisLocation);
    Paint p = getItemPaint(series, item);
    Stroke s = getItemStroke(series, item);
    Line2D line = null;
    Shape shape = getItemShape(series, item);
    Shape top = null;
    Shape bottom = null;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(yyLow, xx, yyHigh, xx);
        top = ShapeUtilities.createTranslatedShape(shape, yyHigh, xx);
        bottom = ShapeUtilities.createTranslatedShape(shape, yyLow, xx);
    } else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(xx, yyLow, xx, yyHigh);
        top = ShapeUtilities.createTranslatedShape(shape, xx, yyHigh);
        bottom = ShapeUtilities.createTranslatedShape(shape, xx, yyLow);
    } else {
        throw new IllegalStateException();
    }
    g2.setPaint(p);
    g2.setStroke(s);
    g2.draw(line);
    g2.fill(top);
    g2.fill(bottom);
    // PLUS an additional item label near the lower y-value.
    if (isItemLabelVisible(series, item)) {
        drawItemLabel(g2, orientation, dataset, series, item, xx, yyHigh, false);
        drawAdditionalItemLabel(g2, orientation, dataset, series, item, xx, yyLow);
    }
    // add an entity for the item...
    if (entities != null) {
        addEntity(entities, line.getBounds(), dataset, series, item, 0.0, 0.0);
    }
}
Also used : Stroke(java.awt.Stroke) PlotOrientation(org.jfree.chart.plot.PlotOrientation) Shape(java.awt.Shape) EntityCollection(org.jfree.chart.entity.EntityCollection) IntervalXYDataset(org.jfree.data.xy.IntervalXYDataset) Paint(java.awt.Paint) Line2D(java.awt.geom.Line2D) RectangleEdge(org.jfree.ui.RectangleEdge)

Aggregations

RectangleEdge (org.jfree.ui.RectangleEdge)98 Rectangle2D (java.awt.geom.Rectangle2D)52 PlotOrientation (org.jfree.chart.plot.PlotOrientation)49 Paint (java.awt.Paint)48 EntityCollection (org.jfree.chart.entity.EntityCollection)40 Stroke (java.awt.Stroke)23 Shape (java.awt.Shape)19 Line2D (java.awt.geom.Line2D)18 ValueAxis (org.jfree.chart.axis.ValueAxis)16 AxisSpace (org.jfree.chart.axis.AxisSpace)15 CategoryItemLabelGenerator (org.jfree.chart.labels.CategoryItemLabelGenerator)13 Point2D (java.awt.geom.Point2D)11 GeneralPath (java.awt.geom.GeneralPath)9 GradientPaint (java.awt.GradientPaint)8 Ellipse2D (java.awt.geom.Ellipse2D)7 IntervalXYDataset (org.jfree.data.xy.IntervalXYDataset)7 RectangleInsets (org.jfree.ui.RectangleInsets)7 BasicStroke (java.awt.BasicStroke)6 AxisState (org.jfree.chart.axis.AxisState)6 CrosshairState (org.jfree.chart.plot.CrosshairState)5