Search in sources :

Example 36 with PlotOrientation

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

the class CategoryPointerAnnotation method draw.

/**
 * Draws the annotation.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 */
@Override
public void draw(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea, CategoryAxis domainAxis, ValueAxis rangeAxis) {
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation);
    CategoryDataset dataset = plot.getDataset();
    int catIndex = dataset.getColumnIndex(getCategory());
    int catCount = dataset.getColumnCount();
    double j2DX = domainAxis.getCategoryMiddle(catIndex, catCount, dataArea, domainEdge);
    double j2DY = rangeAxis.valueToJava2D(getValue(), dataArea, rangeEdge);
    if (orientation == PlotOrientation.HORIZONTAL) {
        double temp = j2DX;
        j2DX = j2DY;
        j2DY = temp;
    }
    double startX = j2DX + Math.cos(this.angle) * this.baseRadius;
    double startY = j2DY + Math.sin(this.angle) * this.baseRadius;
    double endX = j2DX + Math.cos(this.angle) * this.tipRadius;
    double endY = j2DY + Math.sin(this.angle) * this.tipRadius;
    double arrowBaseX = endX + Math.cos(this.angle) * this.arrowLength;
    double arrowBaseY = endY + Math.sin(this.angle) * this.arrowLength;
    double arrowLeftX = arrowBaseX + Math.cos(this.angle + Math.PI / 2.0) * this.arrowWidth;
    double arrowLeftY = arrowBaseY + Math.sin(this.angle + Math.PI / 2.0) * this.arrowWidth;
    double arrowRightX = arrowBaseX - Math.cos(this.angle + Math.PI / 2.0) * this.arrowWidth;
    double arrowRightY = arrowBaseY - Math.sin(this.angle + Math.PI / 2.0) * this.arrowWidth;
    GeneralPath arrow = new GeneralPath();
    arrow.moveTo((float) endX, (float) endY);
    arrow.lineTo((float) arrowLeftX, (float) arrowLeftY);
    arrow.lineTo((float) arrowRightX, (float) arrowRightY);
    arrow.closePath();
    g2.setStroke(this.arrowStroke);
    g2.setPaint(this.arrowPaint);
    Line2D line = new Line2D.Double(startX, startY, arrowBaseX, arrowBaseY);
    g2.draw(line);
    g2.fill(arrow);
    // draw the label
    g2.setFont(getFont());
    g2.setPaint(getPaint());
    double labelX = j2DX + Math.cos(this.angle) * (this.baseRadius + this.labelOffset);
    double labelY = j2DY + Math.sin(this.angle) * (this.baseRadius + this.labelOffset);
    /* Rectangle2D hotspot = */
    TextUtilities.drawAlignedString(getText(), g2, (float) labelX, (float) labelY, getTextAnchor());
// TODO: implement the entity for the annotation
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) GeneralPath(java.awt.geom.GeneralPath) CategoryDataset(org.jfree.data.category.CategoryDataset) Line2D(java.awt.geom.Line2D) Paint(java.awt.Paint) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 37 with PlotOrientation

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

the class XYBoxAnnotation method draw.

/**
 * Draws the annotation.  This method is usually called by the
 * {@link XYPlot} class, you shouldn't need to call it directly.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param rendererIndex  the renderer index.
 * @param info  the plot rendering info.
 */
@Override
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) {
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation);
    double transX0 = domainAxis.valueToJava2D(this.x0, dataArea, domainEdge);
    double transY0 = rangeAxis.valueToJava2D(this.y0, dataArea, rangeEdge);
    double transX1 = domainAxis.valueToJava2D(this.x1, dataArea, domainEdge);
    double transY1 = rangeAxis.valueToJava2D(this.y1, dataArea, rangeEdge);
    Rectangle2D box = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        box = new Rectangle2D.Double(transY0, transX1, transY1 - transY0, transX0 - transX1);
    } else if (orientation == PlotOrientation.VERTICAL) {
        box = new Rectangle2D.Double(transX0, transY1, transX1 - transX0, transY0 - transY1);
    }
    if (this.fillPaint != null) {
        g2.setPaint(this.fillPaint);
        g2.fill(box);
    }
    if (this.stroke != null && this.outlinePaint != null) {
        g2.setPaint(this.outlinePaint);
        g2.setStroke(this.stroke);
        g2.draw(box);
    }
    addEntity(info, box, rendererIndex, getToolTipText(), getURL());
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Rectangle2D(java.awt.geom.Rectangle2D) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 38 with PlotOrientation

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

the class CategoryLineAnnotation method draw.

/**
 * Draws the annotation.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 */
@Override
public void draw(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea, CategoryAxis domainAxis, ValueAxis rangeAxis) {
    CategoryDataset dataset = plot.getDataset();
    int catIndex1 = dataset.getColumnIndex(this.category1);
    int catIndex2 = dataset.getColumnIndex(this.category2);
    int catCount = dataset.getColumnCount();
    double lineX1 = 0.0f;
    double lineY1 = 0.0f;
    double lineX2 = 0.0f;
    double lineY2 = 0.0f;
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation);
    if (orientation == PlotOrientation.HORIZONTAL) {
        lineY1 = domainAxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, catIndex1, catCount, dataArea, domainEdge);
        lineX1 = rangeAxis.valueToJava2D(this.value1, dataArea, rangeEdge);
        lineY2 = domainAxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, catIndex2, catCount, dataArea, domainEdge);
        lineX2 = rangeAxis.valueToJava2D(this.value2, dataArea, rangeEdge);
    } else if (orientation == PlotOrientation.VERTICAL) {
        lineX1 = domainAxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, catIndex1, catCount, dataArea, domainEdge);
        lineY1 = rangeAxis.valueToJava2D(this.value1, dataArea, rangeEdge);
        lineX2 = domainAxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, catIndex2, catCount, dataArea, domainEdge);
        lineY2 = rangeAxis.valueToJava2D(this.value2, dataArea, rangeEdge);
    }
    g2.setPaint(this.paint);
    g2.setStroke(this.stroke);
    g2.drawLine((int) lineX1, (int) lineY1, (int) lineX2, (int) lineY2);
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) CategoryDataset(org.jfree.data.category.CategoryDataset) Paint(java.awt.Paint) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 39 with PlotOrientation

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

the class XYSmoothLineAndShapeRenderer method drawPrimaryLine.

/**
 * Draws the item (first pass). This method draws the lines
 * connecting the items.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the area within which the data 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 pass  the pass.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 */
protected void drawPrimaryLine(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) {
    if (item == 0) {
        return;
    }
    // get the data point...
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(y1) || Double.isNaN(x1)) {
        return;
    }
    double x0 = dataset.getXValue(series, item - 1);
    double y0 = dataset.getYValue(series, item - 1);
    if (Double.isNaN(y0) || Double.isNaN(x0)) {
        return;
    }
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
    double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);
    // only draw if we have good values
    if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1) || Double.isNaN(transY1)) {
        return;
    }
    Point2D.Double point0 = new Point2D.Double();
    Point2D.Double point1 = new Point2D.Double();
    Point2D.Double point2 = new Point2D.Double();
    Point2D.Double point3 = new Point2D.Double();
    if (item == 1) {
        point0 = null;
    } else {
        point0.x = domainAxis.valueToJava2D(dataset.getXValue(series, item - 2), dataArea, xAxisLocation);
        point0.y = rangeAxis.valueToJava2D(dataset.getYValue(series, item - 2), dataArea, yAxisLocation);
    }
    point1.x = transX0;
    point1.y = transY0;
    point2.x = transX1;
    point2.y = transY1;
    if ((item + 1) == dataset.getItemCount(series)) {
        point3 = null;
    } else {
        point3.x = domainAxis.valueToJava2D(dataset.getXValue(series, item + 1), dataArea, xAxisLocation);
        point3.y = rangeAxis.valueToJava2D(dataset.getYValue(series, item + 1), dataArea, yAxisLocation);
    }
    int steps = ((int) ((point2.x - point1.x) / 0.2) < 30) ? (int) ((point2.x - point1.x) / 0.2) : 30;
    Point2D.Double[] points = getBezierCurve(point0, point1, point2, point3, 1, steps);
    for (int i = 1; i < points.length; i++) {
        transX0 = points[i - 1].x;
        transY0 = points[i - 1].y;
        transX1 = points[i].x;
        transY1 = points[i].y;
        PlotOrientation orientation = plot.getOrientation();
        if (orientation == PlotOrientation.HORIZONTAL) {
            state.workingLine.setLine(transY0, transX0, transY1, transX1);
        } else if (orientation == PlotOrientation.VERTICAL) {
            state.workingLine.setLine(transX0, transY0, transX1, transY1);
        }
        if (state.workingLine.intersects(dataArea)) {
            drawFirstPassShape(g2, pass, series, item, state.workingLine);
        }
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Point2D(java.awt.geom.Point2D) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 40 with PlotOrientation

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

the class AbstractCategoryItemRenderer method drawRangeMarker.

/**
 * Draws a marker for the range axis.
 *
 * @param g2  the graphics device (not <code>null</code>).
 * @param plot  the plot (not <code>null</code>).
 * @param axis  the range axis (not <code>null</code>).
 * @param marker  the marker to be drawn (not <code>null</code>).
 * @param dataArea  the area inside the axes (not <code>null</code>).
 *
 * @see #drawDomainMarker(Graphics2D, CategoryPlot, CategoryAxis,
 *     CategoryMarker, Rectangle2D)
 */
@Override
public void drawRangeMarker(Graphics2D g2, CategoryPlot plot, ValueAxis axis, Marker marker, Rectangle2D dataArea) {
    if (marker instanceof ValueMarker) {
        ValueMarker vm = (ValueMarker) marker;
        double value = vm.getValue();
        Range range = axis.getRange();
        if (!range.contains(value)) {
            return;
        }
        final Composite savedComposite = g2.getComposite();
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, marker.getAlpha()));
        PlotOrientation orientation = plot.getOrientation();
        double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());
        Line2D line = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY());
        } else if (orientation == PlotOrientation.VERTICAL) {
            line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v);
        } else {
            throw new IllegalStateException();
        }
        g2.setPaint(marker.getPaint());
        g2.setStroke(marker.getStroke());
        g2.draw(line);
        String label = marker.getLabel();
        RectangleAnchor anchor = marker.getLabelAnchor();
        if (label != null) {
            Font labelFont = marker.getLabelFont();
            g2.setFont(labelFont);
            Point2D coordinates = calculateRangeMarkerTextAnchorPoint(g2, orientation, dataArea, line.getBounds2D(), marker.getLabelOffset(), LengthAdjustmentType.EXPAND, anchor);
            Rectangle2D rect = TextUtils.calcAlignedStringBounds(label, g2, (float) coordinates.getX(), (float) coordinates.getY(), marker.getLabelTextAnchor());
            g2.setPaint(marker.getLabelBackgroundColor());
            g2.fill(rect);
            g2.setPaint(marker.getLabelPaint());
            TextUtils.drawAlignedString(label, g2, (float) coordinates.getX(), (float) coordinates.getY(), marker.getLabelTextAnchor());
        }
        g2.setComposite(savedComposite);
    } else if (marker instanceof IntervalMarker) {
        IntervalMarker im = (IntervalMarker) marker;
        double start = im.getStartValue();
        double end = im.getEndValue();
        Range range = axis.getRange();
        if (!(range.intersects(start, end))) {
            return;
        }
        final Composite savedComposite = g2.getComposite();
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, marker.getAlpha()));
        double start2d = axis.valueToJava2D(start, dataArea, plot.getRangeAxisEdge());
        double end2d = axis.valueToJava2D(end, dataArea, plot.getRangeAxisEdge());
        double low = Math.min(start2d, end2d);
        double high = Math.max(start2d, end2d);
        PlotOrientation orientation = plot.getOrientation();
        Rectangle2D rect = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            // clip left and right bounds to data area
            low = Math.max(low, dataArea.getMinX());
            high = Math.min(high, dataArea.getMaxX());
            rect = new Rectangle2D.Double(low, dataArea.getMinY(), high - low, dataArea.getHeight());
        } else if (orientation == PlotOrientation.VERTICAL) {
            // clip top and bottom bounds to data area
            low = Math.max(low, dataArea.getMinY());
            high = Math.min(high, dataArea.getMaxY());
            rect = new Rectangle2D.Double(dataArea.getMinX(), low, dataArea.getWidth(), high - low);
        }
        Paint p = marker.getPaint();
        if (p instanceof GradientPaint) {
            GradientPaint gp = (GradientPaint) p;
            GradientPaintTransformer t = im.getGradientPaintTransformer();
            if (t != null) {
                gp = t.transform(gp, rect);
            }
            g2.setPaint(gp);
        } else {
            g2.setPaint(p);
        }
        g2.fill(rect);
        // now draw the outlines, if visible...
        if (im.getOutlinePaint() != null && im.getOutlineStroke() != null) {
            if (orientation == PlotOrientation.VERTICAL) {
                Line2D line = new Line2D.Double();
                double x0 = dataArea.getMinX();
                double x1 = dataArea.getMaxX();
                g2.setPaint(im.getOutlinePaint());
                g2.setStroke(im.getOutlineStroke());
                if (range.contains(start)) {
                    line.setLine(x0, start2d, x1, start2d);
                    g2.draw(line);
                }
                if (range.contains(end)) {
                    line.setLine(x0, end2d, x1, end2d);
                    g2.draw(line);
                }
            } else {
                // PlotOrientation.HORIZONTAL
                Line2D line = new Line2D.Double();
                double y0 = dataArea.getMinY();
                double y1 = dataArea.getMaxY();
                g2.setPaint(im.getOutlinePaint());
                g2.setStroke(im.getOutlineStroke());
                if (range.contains(start)) {
                    line.setLine(start2d, y0, start2d, y1);
                    g2.draw(line);
                }
                if (range.contains(end)) {
                    line.setLine(end2d, y0, end2d, y1);
                    g2.draw(line);
                }
            }
        }
        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, rect, marker.getLabelOffset(), marker.getLabelOffsetType(), anchor);
            TextUtilities.drawAlignedString(label, g2, (float) coordinates.getX(), (float) coordinates.getY(), marker.getLabelTextAnchor());
        }
        g2.setComposite(savedComposite);
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) GradientPaintTransformer(org.jfree.ui.GradientPaintTransformer) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) Rectangle2D(java.awt.geom.Rectangle2D) GradientPaint(java.awt.GradientPaint) RectangleAnchor(org.jfree.ui.RectangleAnchor) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Range(org.jfree.data.Range) Line2D(java.awt.geom.Line2D) Font(java.awt.Font) Point2D(java.awt.geom.Point2D) IntervalMarker(org.jfree.chart.plot.IntervalMarker) ValueMarker(org.jfree.chart.plot.ValueMarker)

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