Search in sources :

Example 71 with PlotOrientation

use of org.jfree.chart.plot.PlotOrientation 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 72 with PlotOrientation

use of org.jfree.chart.plot.PlotOrientation 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 73 with PlotOrientation

use of org.jfree.chart.plot.PlotOrientation 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 74 with PlotOrientation

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

the class XYShapeAnnotation 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);
    // compute transform matrix elements via sample points. Assume no
    // rotation or shear.
    Rectangle2D bounds = this.shape.getBounds2D();
    double x0 = bounds.getMinX();
    double x1 = bounds.getMaxX();
    double xx0 = domainAxis.valueToJava2D(x0, dataArea, domainEdge);
    double xx1 = domainAxis.valueToJava2D(x1, dataArea, domainEdge);
    double m00 = (xx1 - xx0) / (x1 - x0);
    double m02 = xx0 - x0 * m00;
    double y0 = bounds.getMaxY();
    double y1 = bounds.getMinY();
    double yy0 = rangeAxis.valueToJava2D(y0, dataArea, rangeEdge);
    double yy1 = rangeAxis.valueToJava2D(y1, dataArea, rangeEdge);
    double m11 = (yy1 - yy0) / (y1 - y0);
    double m12 = yy0 - m11 * y0;
    // create transform & transform shape
    Shape s = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        AffineTransform t1 = new AffineTransform(0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f);
        AffineTransform t2 = new AffineTransform(m11, 0.0f, 0.0f, m00, m12, m02);
        s = t1.createTransformedShape(this.shape);
        s = t2.createTransformedShape(s);
    } else if (orientation == PlotOrientation.VERTICAL) {
        AffineTransform t = new AffineTransform(m00, 0, 0, m11, m02, m12);
        s = t.createTransformedShape(this.shape);
    }
    if (this.fillPaint != null) {
        g2.setPaint(this.fillPaint);
        g2.fill(s);
    }
    if (this.stroke != null && this.outlinePaint != null) {
        g2.setPaint(this.outlinePaint);
        g2.setStroke(this.stroke);
        g2.draw(s);
    }
    addEntity(info, s, rendererIndex, getToolTipText(), getURL());
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Shape(java.awt.Shape) Rectangle2D(java.awt.geom.Rectangle2D) AffineTransform(java.awt.geom.AffineTransform) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 75 with PlotOrientation

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

the class AbstractCategoryItemRenderer method drawDomainGridline.

/**
 * Draws a grid line against the domain axis.
 * <P>
 * Note that this default implementation assumes that the horizontal axis
 * is the domain axis. If this is not the case, you will need to override
 * this method.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the area for plotting data (not yet adjusted for any
 *                  3D effect).
 * @param value  the Java2D value at which the grid line should be drawn.
 *
 * @see #drawRangeGridline(Graphics2D, CategoryPlot, ValueAxis,
 *     Rectangle2D, double)
 */
@Override
public void drawDomainGridline(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea, double value) {
    Line2D line = null;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(dataArea.getMinX(), value, dataArea.getMaxX(), value);
    } else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(value, dataArea.getMinY(), value, dataArea.getMaxY());
    }
    Paint paint = plot.getDomainGridlinePaint();
    if (paint == null) {
        paint = CategoryPlot.DEFAULT_GRIDLINE_PAINT;
    }
    g2.setPaint(paint);
    Stroke stroke = plot.getDomainGridlineStroke();
    if (stroke == null) {
        stroke = CategoryPlot.DEFAULT_GRIDLINE_STROKE;
    }
    g2.setStroke(stroke);
    g2.draw(line);
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Stroke(java.awt.Stroke) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Line2D(java.awt.geom.Line2D)

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