Search in sources :

Example 36 with RectangleEdge

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

the class CombinedRangeXYPlot method draw.

/**
 * Draws the plot within the specified area on a graphics device.
 *
 * @param g2  the graphics device.
 * @param area  the plot area (in Java2D space).
 * @param anchor  an anchor point in Java2D space ({@code null} permitted).
 * @param parentState  the state from the parent plot, if there is one
 *                     ({@code null} permitted).
 * @param info  collects chart drawing information ({@code null}
 *              permitted).
 */
@Override
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) {
    // set up info collection...
    if (info != null) {
        info.setPlotArea(area);
    }
    // adjust the drawing area for plot insets (if any)...
    RectangleInsets insets = getInsets();
    insets.trim(area);
    AxisSpace space = calculateAxisSpace(g2, area);
    Rectangle2D dataArea = space.shrink(area, null);
    // this.axisOffset.trim(dataArea);
    // set the width and height of non-shared axis of all sub-plots
    setFixedDomainAxisSpaceForSubplots(space);
    // draw the shared axis
    ValueAxis axis = getRangeAxis();
    RectangleEdge edge = getRangeAxisEdge();
    double cursor = RectangleEdge.coordinate(dataArea, edge);
    AxisState axisState = axis.draw(g2, cursor, area, dataArea, edge, info);
    if (parentState == null) {
        parentState = new PlotState();
    }
    parentState.getSharedAxisStates().put(axis, axisState);
    // draw all the charts
    for (int i = 0; i < this.subplots.size(); i++) {
        XYPlot plot = (XYPlot) this.subplots.get(i);
        PlotRenderingInfo subplotInfo = null;
        if (info != null) {
            subplotInfo = new PlotRenderingInfo(info.getOwner());
            info.addSubplotInfo(subplotInfo);
        }
        plot.draw(g2, this.subplotAreas[i], anchor, parentState, subplotInfo);
    }
    if (info != null) {
        info.setDataArea(dataArea);
    }
}
Also used : AxisState(org.jfree.chart.axis.AxisState) ValueAxis(org.jfree.chart.axis.ValueAxis) Rectangle2D(java.awt.geom.Rectangle2D) RectangleInsets(org.jfree.chart.api.RectangleInsets) AxisSpace(org.jfree.chart.axis.AxisSpace) RectangleEdge(org.jfree.chart.api.RectangleEdge)

Example 37 with RectangleEdge

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

the class PaintScaleLegend method draw.

/**
 * Draws the legend within the specified area.
 *
 * @param g2  the graphics target ({@code null} not permitted).
 * @param area  the drawing area ({@code null} not permitted).
 * @param params  drawing parameters (ignored here).
 *
 * @return {@code null}.
 */
@Override
public Object draw(Graphics2D g2, Rectangle2D area, Object params) {
    Rectangle2D target = (Rectangle2D) area.clone();
    target = trimMargin(target);
    if (this.backgroundPaint != null) {
        g2.setPaint(this.backgroundPaint);
        g2.fill(target);
    }
    getFrame().draw(g2, target);
    getFrame().getInsets().trim(target);
    target = trimPadding(target);
    double base = this.axis.getLowerBound();
    double increment = this.axis.getRange().getLength() / this.subdivisions;
    Rectangle2D r = new Rectangle2D.Double();
    if (RectangleEdge.isTopOrBottom(getPosition())) {
        RectangleEdge axisEdge = Plot.resolveRangeAxisLocation(this.axisLocation, PlotOrientation.HORIZONTAL);
        if (axisEdge == RectangleEdge.TOP) {
            for (int i = 0; i < this.subdivisions; i++) {
                double v = base + (i * increment);
                Paint p = this.scale.getPaint(v);
                double vv0 = this.axis.valueToJava2D(v, target, RectangleEdge.TOP);
                double vv1 = this.axis.valueToJava2D(v + increment, target, RectangleEdge.TOP);
                double ww = Math.abs(vv1 - vv0) + 1.0;
                r.setRect(Math.min(vv0, vv1), target.getMaxY() - this.stripWidth, ww, this.stripWidth);
                g2.setPaint(p);
                g2.fill(r);
            }
            if (isStripOutlineVisible()) {
                g2.setPaint(this.stripOutlinePaint);
                g2.setStroke(this.stripOutlineStroke);
                g2.draw(new Rectangle2D.Double(target.getMinX(), target.getMaxY() - this.stripWidth, target.getWidth(), this.stripWidth));
            }
            this.axis.draw(g2, target.getMaxY() - this.stripWidth - this.axisOffset, target, target, RectangleEdge.TOP, null);
        } else if (axisEdge == RectangleEdge.BOTTOM) {
            for (int i = 0; i < this.subdivisions; i++) {
                double v = base + (i * increment);
                Paint p = this.scale.getPaint(v);
                double vv0 = this.axis.valueToJava2D(v, target, RectangleEdge.BOTTOM);
                double vv1 = this.axis.valueToJava2D(v + increment, target, RectangleEdge.BOTTOM);
                double ww = Math.abs(vv1 - vv0) + 1.0;
                r.setRect(Math.min(vv0, vv1), target.getMinY(), ww, this.stripWidth);
                g2.setPaint(p);
                g2.fill(r);
            }
            if (isStripOutlineVisible()) {
                g2.setPaint(this.stripOutlinePaint);
                g2.setStroke(this.stripOutlineStroke);
                g2.draw(new Rectangle2D.Double(target.getMinX(), target.getMinY(), target.getWidth(), this.stripWidth));
            }
            this.axis.draw(g2, target.getMinY() + this.stripWidth + this.axisOffset, target, target, RectangleEdge.BOTTOM, null);
        }
    } else {
        RectangleEdge axisEdge = Plot.resolveRangeAxisLocation(this.axisLocation, PlotOrientation.VERTICAL);
        if (axisEdge == RectangleEdge.LEFT) {
            for (int i = 0; i < this.subdivisions; i++) {
                double v = base + (i * increment);
                Paint p = this.scale.getPaint(v);
                double vv0 = this.axis.valueToJava2D(v, target, RectangleEdge.LEFT);
                double vv1 = this.axis.valueToJava2D(v + increment, target, RectangleEdge.LEFT);
                double hh = Math.abs(vv1 - vv0) + 1.0;
                r.setRect(target.getMaxX() - this.stripWidth, Math.min(vv0, vv1), this.stripWidth, hh);
                g2.setPaint(p);
                g2.fill(r);
            }
            if (isStripOutlineVisible()) {
                g2.setPaint(this.stripOutlinePaint);
                g2.setStroke(this.stripOutlineStroke);
                g2.draw(new Rectangle2D.Double(target.getMaxX() - this.stripWidth, target.getMinY(), this.stripWidth, target.getHeight()));
            }
            this.axis.draw(g2, target.getMaxX() - this.stripWidth - this.axisOffset, target, target, RectangleEdge.LEFT, null);
        } else if (axisEdge == RectangleEdge.RIGHT) {
            for (int i = 0; i < this.subdivisions; i++) {
                double v = base + (i * increment);
                Paint p = this.scale.getPaint(v);
                double vv0 = this.axis.valueToJava2D(v, target, RectangleEdge.LEFT);
                double vv1 = this.axis.valueToJava2D(v + increment, target, RectangleEdge.LEFT);
                double hh = Math.abs(vv1 - vv0) + 1.0;
                r.setRect(target.getMinX(), Math.min(vv0, vv1), this.stripWidth, hh);
                g2.setPaint(p);
                g2.fill(r);
            }
            if (isStripOutlineVisible()) {
                g2.setPaint(this.stripOutlinePaint);
                g2.setStroke(this.stripOutlineStroke);
                g2.draw(new Rectangle2D.Double(target.getMinX(), target.getMinY(), this.stripWidth, target.getHeight()));
            }
            this.axis.draw(g2, target.getMinX() + this.stripWidth + this.axisOffset, target, target, RectangleEdge.RIGHT, null);
        }
    }
    return null;
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) Paint(java.awt.Paint) RectangleConstraint(org.jfree.chart.block.RectangleConstraint) Paint(java.awt.Paint) RectangleEdge(org.jfree.chart.api.RectangleEdge)

Example 38 with RectangleEdge

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

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

Example 39 with RectangleEdge

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

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

Example 40 with RectangleEdge

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

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