Search in sources :

Example 66 with RectangleEdge

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

the class CategoryTextAnnotation 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 catIndex = dataset.getColumnIndex(this.category);
    int catCount = dataset.getColumnCount();
    float anchorX = 0.0f;
    float anchorY = 0.0f;
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation);
    if (orientation == PlotOrientation.HORIZONTAL) {
        anchorY = (float) domainAxis.getCategoryJava2DCoordinate(this.categoryAnchor, catIndex, catCount, dataArea, domainEdge);
        anchorX = (float) rangeAxis.valueToJava2D(this.value, dataArea, rangeEdge);
    } else if (orientation == PlotOrientation.VERTICAL) {
        anchorX = (float) domainAxis.getCategoryJava2DCoordinate(this.categoryAnchor, catIndex, catCount, dataArea, domainEdge);
        anchorY = (float) rangeAxis.valueToJava2D(this.value, dataArea, rangeEdge);
    }
    g2.setFont(getFont());
    g2.setPaint(getPaint());
    TextUtilities.drawRotatedString(getText(), g2, anchorX, anchorY, getTextAnchor(), getRotationAngle(), getRotationAnchor());
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) CategoryDataset(org.jfree.data.category.CategoryDataset) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 67 with RectangleEdge

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

the class XYDataImageAnnotation method draw.

/**
 * Draws the annotation.  This method is called by the drawing code in the
 * {@link XYPlot} class, you don't normally need to call this method
 * 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  if supplied, this info object will be populated with
 *              entity information.
 */
@Override
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) {
    PlotOrientation orientation = plot.getOrientation();
    AxisLocation xAxisLocation = plot.getDomainAxisLocation();
    AxisLocation yAxisLocation = plot.getRangeAxisLocation();
    RectangleEdge xEdge = Plot.resolveDomainAxisLocation(xAxisLocation, orientation);
    RectangleEdge yEdge = Plot.resolveRangeAxisLocation(yAxisLocation, orientation);
    float j2DX0 = (float) domainAxis.valueToJava2D(this.x, dataArea, xEdge);
    float j2DY0 = (float) rangeAxis.valueToJava2D(this.y, dataArea, yEdge);
    float j2DX1 = (float) domainAxis.valueToJava2D(this.x + this.w, dataArea, xEdge);
    float j2DY1 = (float) rangeAxis.valueToJava2D(this.y + this.h, dataArea, yEdge);
    float xx0 = 0.0f;
    float yy0 = 0.0f;
    float xx1 = 0.0f;
    float yy1 = 0.0f;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx0 = j2DY0;
        xx1 = j2DY1;
        yy0 = j2DX0;
        yy1 = j2DX1;
    } else if (orientation == PlotOrientation.VERTICAL) {
        xx0 = j2DX0;
        xx1 = j2DX1;
        yy0 = j2DY0;
        yy1 = j2DY1;
    }
    // TODO: rotate the image when drawn with horizontal orientation?
    g2.drawImage(this.image, (int) xx0, (int) Math.min(yy0, yy1), (int) (xx1 - xx0), (int) Math.abs(yy1 - yy0), null);
    String toolTip = getToolTipText();
    String url = getURL();
    if (toolTip != null || url != null) {
        addEntity(info, new Rectangle2D.Float(xx0, yy0, (xx1 - xx0), (yy1 - yy0)), rendererIndex, toolTip, url);
    }
}
Also used : AxisLocation(org.jfree.chart.axis.AxisLocation) PlotOrientation(org.jfree.chart.plot.PlotOrientation) Rectangle2D(java.awt.geom.Rectangle2D) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 68 with RectangleEdge

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

the class XYDrawableAnnotation 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.
 * @param rendererIndex  the renderer index.
 * @param info  if supplied, this info object will be populated with
 *              entity information.
 */
@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);
    float j2DX = (float) domainAxis.valueToJava2D(this.x, dataArea, domainEdge);
    float j2DY = (float) rangeAxis.valueToJava2D(this.y, dataArea, rangeEdge);
    Rectangle2D displayArea = new Rectangle2D.Double(j2DX - this.displayWidth / 2.0, j2DY - this.displayHeight / 2.0, this.displayWidth, this.displayHeight);
    // here we change the AffineTransform so we can draw the annotation
    // to a larger area and scale it down into the display area
    // afterwards, the original transform is restored
    AffineTransform savedTransform = g2.getTransform();
    Rectangle2D drawArea = new Rectangle2D.Double(0.0, 0.0, this.displayWidth * this.drawScaleFactor, this.displayHeight * this.drawScaleFactor);
    g2.scale(1 / this.drawScaleFactor, 1 / this.drawScaleFactor);
    g2.translate((j2DX - this.displayWidth / 2.0) * this.drawScaleFactor, (j2DY - this.displayHeight / 2.0) * this.drawScaleFactor);
    this.drawable.draw(g2, drawArea);
    g2.setTransform(savedTransform);
    String toolTip = getToolTipText();
    String url = getURL();
    if (toolTip != null || url != null) {
        addEntity(info, displayArea, rendererIndex, toolTip, url);
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Rectangle2D(java.awt.geom.Rectangle2D) AffineTransform(java.awt.geom.AffineTransform) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 69 with RectangleEdge

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

the class XYLineAnnotation method draw.

/**
 * Draws the annotation.  This method is called by the {@link XYPlot}
 * class, you won't normally need to call it yourself.
 *
 * @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  if supplied, this info object will be populated with
 *              entity information.
 */
@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);
    float j2DX1 = 0.0f;
    float j2DX2 = 0.0f;
    float j2DY1 = 0.0f;
    float j2DY2 = 0.0f;
    if (orientation == PlotOrientation.VERTICAL) {
        j2DX1 = (float) domainAxis.valueToJava2D(this.x1, dataArea, domainEdge);
        j2DY1 = (float) rangeAxis.valueToJava2D(this.y1, dataArea, rangeEdge);
        j2DX2 = (float) domainAxis.valueToJava2D(this.x2, dataArea, domainEdge);
        j2DY2 = (float) rangeAxis.valueToJava2D(this.y2, dataArea, rangeEdge);
    } else if (orientation == PlotOrientation.HORIZONTAL) {
        j2DY1 = (float) domainAxis.valueToJava2D(this.x1, dataArea, domainEdge);
        j2DX1 = (float) rangeAxis.valueToJava2D(this.y1, dataArea, rangeEdge);
        j2DY2 = (float) domainAxis.valueToJava2D(this.x2, dataArea, domainEdge);
        j2DX2 = (float) rangeAxis.valueToJava2D(this.y2, dataArea, rangeEdge);
    }
    g2.setPaint(this.paint);
    g2.setStroke(this.stroke);
    Line2D line = new Line2D.Float(j2DX1, j2DY1, j2DX2, j2DY2);
    // line is clipped to avoid JRE bug 6574155, for more info
    // see JFreeChart bug 2221495
    boolean visible = LineUtilities.clipLine(line, dataArea);
    if (visible) {
        g2.draw(line);
    }
    String toolTip = getToolTipText();
    String url = getURL();
    if (toolTip != null || url != null) {
        addEntity(info, ShapeUtilities.createLineRegion(line, 1.0f), rendererIndex, toolTip, url);
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Line2D(java.awt.geom.Line2D) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 70 with RectangleEdge

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

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</code> 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.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