Search in sources :

Example 31 with RectangleEdge

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

the class CombinedDomainCategoryPlot method draw.

/**
 * Draws the plot on a Java 2D graphics device (such as the screen or a
 * printer).  Will perform all the placement calculations for each of the
 * sub-plots and then tell these to draw themselves.
 *
 * @param g2  the graphics device.
 * @param area  the area within which the plot (including axis labels)
 *              should be drawn.
 * @param anchor  the anchor point ({@code null} permitted).
 * @param parentState  the state from the parent plot, if there is one.
 * @param info  collects information about the drawing ({@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();
    area.setRect(area.getX() + insets.getLeft(), area.getY() + insets.getTop(), area.getWidth() - insets.getLeft() - insets.getRight(), area.getHeight() - insets.getTop() - insets.getBottom());
    // calculate the data area...
    setFixedRangeAxisSpaceForSubplots(null);
    AxisSpace space = calculateAxisSpace(g2, area);
    Rectangle2D dataArea = space.shrink(area, null);
    // set the width and height of non-shared axis of all sub-plots
    setFixedRangeAxisSpaceForSubplots(space);
    // draw the shared axis
    CategoryAxis axis = getDomainAxis();
    RectangleEdge domainEdge = getDomainAxisEdge();
    double cursor = RectangleEdge.coordinate(dataArea, domainEdge);
    AxisState axisState = axis.draw(g2, cursor, area, dataArea, domainEdge, info);
    if (parentState == null) {
        parentState = new PlotState();
    }
    parentState.getSharedAxisStates().put(axis, axisState);
    // draw all the subplots
    for (int i = 0; i < this.subplots.size(); i++) {
        CategoryPlot plot = (CategoryPlot) this.subplots.get(i);
        PlotRenderingInfo subplotInfo = null;
        if (info != null) {
            subplotInfo = new PlotRenderingInfo(info.getOwner());
            info.addSubplotInfo(subplotInfo);
        }
        Point2D subAnchor = null;
        if (anchor != null && this.subplotAreas[i].contains(anchor)) {
            subAnchor = anchor;
        }
        plot.draw(g2, this.subplotAreas[i], subAnchor, parentState, subplotInfo);
    }
    if (info != null) {
        info.setDataArea(dataArea);
    }
}
Also used : AxisState(org.jfree.chart.axis.AxisState) CategoryAxis(org.jfree.chart.axis.CategoryAxis) Point2D(java.awt.geom.Point2D) Rectangle2D(java.awt.geom.Rectangle2D) RectangleInsets(org.jfree.chart.api.RectangleInsets) AxisSpace(org.jfree.chart.axis.AxisSpace) RectangleEdge(org.jfree.chart.api.RectangleEdge)

Example 32 with RectangleEdge

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

the class CombinedDomainCategoryPlot method calculateAxisSpace.

/**
 * Calculates the space required for the axes.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 *
 * @return The space required for the axes.
 */
@Override
protected AxisSpace calculateAxisSpace(Graphics2D g2, Rectangle2D plotArea) {
    AxisSpace space = new AxisSpace();
    PlotOrientation orientation = getOrientation();
    // work out the space required by the domain axis...
    AxisSpace fixed = getFixedDomainAxisSpace();
    if (fixed != null) {
        if (orientation == PlotOrientation.HORIZONTAL) {
            space.setLeft(fixed.getLeft());
            space.setRight(fixed.getRight());
        } else if (orientation == PlotOrientation.VERTICAL) {
            space.setTop(fixed.getTop());
            space.setBottom(fixed.getBottom());
        }
    } else {
        CategoryAxis categoryAxis = getDomainAxis();
        RectangleEdge categoryEdge = Plot.resolveDomainAxisLocation(getDomainAxisLocation(), orientation);
        if (categoryAxis != null) {
            space = categoryAxis.reserveSpace(g2, this, plotArea, categoryEdge, space);
        } else {
            if (getDrawSharedDomainAxis()) {
                space = getDomainAxis().reserveSpace(g2, this, plotArea, categoryEdge, space);
            }
        }
    }
    Rectangle2D adjustedPlotArea = space.shrink(plotArea, null);
    // work out the maximum height or width of the non-shared axes...
    int n = this.subplots.size();
    int totalWeight = 0;
    for (int i = 0; i < n; i++) {
        CategoryPlot sub = (CategoryPlot) this.subplots.get(i);
        totalWeight += sub.getWeight();
    }
    this.subplotAreas = new Rectangle2D[n];
    double x = adjustedPlotArea.getX();
    double y = adjustedPlotArea.getY();
    double usableSize = 0.0;
    if (orientation == PlotOrientation.HORIZONTAL) {
        usableSize = adjustedPlotArea.getWidth() - this.gap * (n - 1);
    } else if (orientation == PlotOrientation.VERTICAL) {
        usableSize = adjustedPlotArea.getHeight() - this.gap * (n - 1);
    }
    for (int i = 0; i < n; i++) {
        CategoryPlot plot = (CategoryPlot) this.subplots.get(i);
        // calculate sub-plot area
        if (orientation == PlotOrientation.HORIZONTAL) {
            double w = usableSize * plot.getWeight() / totalWeight;
            this.subplotAreas[i] = new Rectangle2D.Double(x, y, w, adjustedPlotArea.getHeight());
            x = x + w + this.gap;
        } else if (orientation == PlotOrientation.VERTICAL) {
            double h = usableSize * plot.getWeight() / totalWeight;
            this.subplotAreas[i] = new Rectangle2D.Double(x, y, adjustedPlotArea.getWidth(), h);
            y = y + h + this.gap;
        }
        AxisSpace subSpace = plot.calculateRangeAxisSpace(g2, this.subplotAreas[i], null);
        space.ensureAtLeast(subSpace);
    }
    return space;
}
Also used : CategoryAxis(org.jfree.chart.axis.CategoryAxis) Rectangle2D(java.awt.geom.Rectangle2D) AxisSpace(org.jfree.chart.axis.AxisSpace) RectangleEdge(org.jfree.chart.api.RectangleEdge)

Example 33 with RectangleEdge

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

the class CategoryPlot method handleClick.

/**
 * Handles a 'click' on the plot by updating the anchor value.
 *
 * @param x  x-coordinate of the click (in Java2D space).
 * @param y  y-coordinate of the click (in Java2D space).
 * @param info  information about the plot's dimensions.
 */
@Override
public void handleClick(int x, int y, PlotRenderingInfo info) {
    Rectangle2D dataArea = info.getDataArea();
    if (dataArea.contains(x, y)) {
        // set the anchor value for the range axis...
        double java2D = 0.0;
        if (this.orientation == PlotOrientation.HORIZONTAL) {
            java2D = x;
        } else if (this.orientation == PlotOrientation.VERTICAL) {
            java2D = y;
        }
        RectangleEdge edge = Plot.resolveRangeAxisLocation(getRangeAxisLocation(), this.orientation);
        double value = getRangeAxis().java2DToValue(java2D, info.getDataArea(), edge);
        setAnchorValue(value);
        setRangeCrosshairValue(value);
    }
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) RectangleEdge(org.jfree.chart.api.RectangleEdge)

Example 34 with RectangleEdge

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

the class PaintScaleLegend method arrangeRR.

/**
 * Returns the content size for the title.  This will reflect the fact that
 * a text title positioned on the left or right of a chart will be rotated
 * 90 degrees.
 *
 * @param g2  the graphics device.
 * @param widthRange  the width range.
 * @param heightRange  the height range.
 *
 * @return The content size.
 */
protected Size2D arrangeRR(Graphics2D g2, Range widthRange, Range heightRange) {
    RectangleEdge position = getPosition();
    if (position == RectangleEdge.TOP || position == RectangleEdge.BOTTOM) {
        float maxWidth = (float) widthRange.getUpperBound();
        // determine the space required for the axis
        AxisSpace space = this.axis.reserveSpace(g2, null, new Rectangle2D.Double(0, 0, maxWidth, 100), RectangleEdge.BOTTOM, null);
        return new Size2D(maxWidth, this.stripWidth + this.axisOffset + space.getTop() + space.getBottom());
    } else if (position == RectangleEdge.LEFT || position == RectangleEdge.RIGHT) {
        float maxHeight = (float) heightRange.getUpperBound();
        AxisSpace space = this.axis.reserveSpace(g2, null, new Rectangle2D.Double(0, 0, 100, maxHeight), RectangleEdge.RIGHT, null);
        return new Size2D(this.stripWidth + this.axisOffset + space.getLeft() + space.getRight(), maxHeight);
    } else {
        throw new RuntimeException("Unrecognised position.");
    }
}
Also used : Size2D(org.jfree.chart.block.Size2D) Rectangle2D(java.awt.geom.Rectangle2D) AxisSpace(org.jfree.chart.axis.AxisSpace) RectangleEdge(org.jfree.chart.api.RectangleEdge)

Example 35 with RectangleEdge

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

the class CombinedDomainXYPlot 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);
    setFixedRangeAxisSpaceForSubplots(null);
    AxisSpace space = calculateAxisSpace(g2, area);
    Rectangle2D dataArea = space.shrink(area, null);
    // set the width and height of non-shared axis of all sub-plots
    setFixedRangeAxisSpaceForSubplots(space);
    // draw the shared axis
    ValueAxis axis = getDomainAxis();
    RectangleEdge edge = getDomainAxisEdge();
    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 subplots
    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)

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