Search in sources :

Example 41 with RectangleEdge

use of org.jfree.chart.api.RectangleEdge in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class XYImageAnnotation 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 domainAxisLocation = plot.getDomainAxisLocation();
    AxisLocation rangeAxisLocation = plot.getRangeAxisLocation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(domainAxisLocation, orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(rangeAxisLocation, orientation);
    float j2DX = (float) domainAxis.valueToJava2D(this.x, dataArea, domainEdge);
    float j2DY = (float) rangeAxis.valueToJava2D(this.y, dataArea, rangeEdge);
    float xx = 0.0f;
    float yy = 0.0f;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = j2DY;
        yy = j2DX;
    } else if (orientation == PlotOrientation.VERTICAL) {
        xx = j2DX;
        yy = j2DY;
    }
    int w = this.image.getWidth(null);
    int h = this.image.getHeight(null);
    Rectangle2D imageRect = new Rectangle2D.Double(0, 0, w, h);
    Point2D anchorPoint = this.anchor.getAnchorPoint(imageRect);
    xx = xx - (float) anchorPoint.getX();
    yy = yy - (float) anchorPoint.getY();
    g2.drawImage(this.image, (int) xx, (int) yy, null);
    String toolTip = getToolTipText();
    String url = getURL();
    if (toolTip != null || url != null) {
        addEntity(info, new Rectangle2D.Float(xx, yy, w, h), rendererIndex, toolTip, url);
    }
}
Also used : AxisLocation(org.jfree.chart.axis.AxisLocation) PlotOrientation(org.jfree.chart.plot.PlotOrientation) Point2D(java.awt.geom.Point2D) Rectangle2D(java.awt.geom.Rectangle2D) RectangleEdge(org.jfree.chart.api.RectangleEdge)

Example 42 with RectangleEdge

use of org.jfree.chart.api.RectangleEdge in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

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 = LineUtils.clipLine(line, dataArea);
    if (visible) {
        g2.draw(line);
    }
    String toolTip = getToolTipText();
    String url = getURL();
    if (toolTip != null || url != null) {
        addEntity(info, ShapeUtils.createLineRegion(line, 1.0f), rendererIndex, toolTip, url);
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Line2D(java.awt.geom.Line2D) RectangleEdge(org.jfree.chart.api.RectangleEdge)

Example 43 with RectangleEdge

use of org.jfree.chart.api.RectangleEdge in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

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.chart.api.RectangleEdge)

Example 44 with RectangleEdge

use of org.jfree.chart.api.RectangleEdge in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class JFreeChart method drawTitle.

/**
 * Draws a title.  The title should be drawn at the top, bottom, left or
 * right of the specified area, and the area should be updated to reflect
 * the amount of space used by the title.
 *
 * @param t  the title ({@code null} not permitted).
 * @param g2  the graphics device ({@code null} not permitted).
 * @param area  the chart area, excluding any existing titles
 *              ({@code null} not permitted).
 * @param entities  a flag that controls whether or not an entity
 *                  collection is returned for the title.
 *
 * @return An entity collection for the title (possibly {@code null}).
 */
protected EntityCollection drawTitle(Title t, Graphics2D g2, Rectangle2D area, boolean entities) {
    Args.nullNotPermitted(t, "t");
    Args.nullNotPermitted(area, "area");
    Rectangle2D titleArea;
    RectangleEdge position = t.getPosition();
    double ww = area.getWidth();
    if (ww <= 0.0) {
        return null;
    }
    double hh = area.getHeight();
    if (hh <= 0.0) {
        return null;
    }
    RectangleConstraint constraint = new RectangleConstraint(ww, new Range(0.0, ww), LengthConstraintType.RANGE, hh, new Range(0.0, hh), LengthConstraintType.RANGE);
    Object retValue = null;
    BlockParams p = new BlockParams();
    p.setGenerateEntities(entities);
    switch(position) {
        case TOP:
            {
                Size2D size = t.arrange(g2, constraint);
                titleArea = createAlignedRectangle2D(size, area, t.getHorizontalAlignment(), VerticalAlignment.TOP);
                retValue = t.draw(g2, titleArea, p);
                area.setRect(area.getX(), Math.min(area.getY() + size.height, area.getMaxY()), area.getWidth(), Math.max(area.getHeight() - size.height, 0));
                break;
            }
        case BOTTOM:
            {
                Size2D size = t.arrange(g2, constraint);
                titleArea = createAlignedRectangle2D(size, area, t.getHorizontalAlignment(), VerticalAlignment.BOTTOM);
                retValue = t.draw(g2, titleArea, p);
                area.setRect(area.getX(), area.getY(), area.getWidth(), area.getHeight() - size.height);
                break;
            }
        case RIGHT:
            {
                Size2D size = t.arrange(g2, constraint);
                titleArea = createAlignedRectangle2D(size, area, HorizontalAlignment.RIGHT, t.getVerticalAlignment());
                retValue = t.draw(g2, titleArea, p);
                area.setRect(area.getX(), area.getY(), area.getWidth() - size.width, area.getHeight());
                break;
            }
        case LEFT:
            {
                Size2D size = t.arrange(g2, constraint);
                titleArea = createAlignedRectangle2D(size, area, HorizontalAlignment.LEFT, t.getVerticalAlignment());
                retValue = t.draw(g2, titleArea, p);
                area.setRect(area.getX() + size.width, area.getY(), area.getWidth() - size.width, area.getHeight());
                break;
            }
        default:
            {
                throw new RuntimeException("Unrecognised title position.");
            }
    }
    EntityCollection result = null;
    if (retValue instanceof EntityBlockResult) {
        EntityBlockResult ebr = (EntityBlockResult) retValue;
        result = ebr.getEntityCollection();
    }
    return result;
}
Also used : Size2D(org.jfree.chart.block.Size2D) EntityCollection(org.jfree.chart.entity.EntityCollection) Rectangle2D(java.awt.geom.Rectangle2D) EntityBlockResult(org.jfree.chart.block.EntityBlockResult) RectangleConstraint(org.jfree.chart.block.RectangleConstraint) Range(org.jfree.data.Range) RectangleEdge(org.jfree.chart.api.RectangleEdge) BlockParams(org.jfree.chart.block.BlockParams)

Example 45 with RectangleEdge

use of org.jfree.chart.api.RectangleEdge in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class TextTitle method arrangeFN.

/**
 * Arranges the content for this title assuming a fixed width and no bounds
 * on the height, and returns the required size.  This will reflect the
 * fact that a text title positioned on the left or right of a chart will
 * be rotated by 90 degrees.
 *
 * @param g2  the graphics target.
 * @param w  the width.
 *
 * @return The content size.
 */
protected Size2D arrangeFN(Graphics2D g2, double w) {
    RectangleEdge position = getPosition();
    if (position == RectangleEdge.TOP || position == RectangleEdge.BOTTOM) {
        float maxWidth = (float) w;
        g2.setFont(this.font);
        this.content = TextUtils.createTextBlock(this.text, this.font, this.paint, maxWidth, this.maximumLinesToDisplay, new G2TextMeasurer(g2));
        this.content.setLineAlignment(this.textAlignment);
        Size2D contentSize = this.content.calculateDimensions(g2);
        if (this.expandToFitSpace) {
            return new Size2D(maxWidth, contentSize.getHeight());
        } else {
            return contentSize;
        }
    } else if (position == RectangleEdge.LEFT || position == RectangleEdge.RIGHT) {
        float maxWidth = Float.MAX_VALUE;
        g2.setFont(this.font);
        this.content = TextUtils.createTextBlock(this.text, this.font, this.paint, maxWidth, this.maximumLinesToDisplay, new G2TextMeasurer(g2));
        this.content.setLineAlignment(this.textAlignment);
        Size2D contentSize = this.content.calculateDimensions(g2);
        // transpose the dimensions, because the title is rotated
        if (this.expandToFitSpace) {
            return new Size2D(contentSize.getHeight(), maxWidth);
        } else {
            return new Size2D(contentSize.height, contentSize.width);
        }
    } else {
        throw new RuntimeException("Unrecognised exception.");
    }
}
Also used : Size2D(org.jfree.chart.block.Size2D) G2TextMeasurer(org.jfree.chart.text.G2TextMeasurer) RectangleEdge(org.jfree.chart.api.RectangleEdge)

Aggregations

RectangleEdge (org.jfree.chart.api.RectangleEdge)87 Rectangle2D (java.awt.geom.Rectangle2D)47 PlotOrientation (org.jfree.chart.plot.PlotOrientation)44 Paint (java.awt.Paint)40 EntityCollection (org.jfree.chart.entity.EntityCollection)33 Stroke (java.awt.Stroke)18 Line2D (java.awt.geom.Line2D)17 Shape (java.awt.Shape)16 AxisSpace (org.jfree.chart.axis.AxisSpace)12 CategoryItemLabelGenerator (org.jfree.chart.labels.CategoryItemLabelGenerator)11 ValueAxis (org.jfree.chart.axis.ValueAxis)10 GeneralPath (java.awt.geom.GeneralPath)9 IntervalXYDataset (org.jfree.data.xy.IntervalXYDataset)8 Point2D (java.awt.geom.Point2D)7 GradientPaint (java.awt.GradientPaint)6 RectangleInsets (org.jfree.chart.api.RectangleInsets)6 CrosshairState (org.jfree.chart.plot.CrosshairState)6 Ellipse2D (java.awt.geom.Ellipse2D)5 AxisState (org.jfree.chart.axis.AxisState)5 AxisLocation (org.jfree.chart.axis.AxisLocation)4