Search in sources :

Example 26 with RectangleEdge

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

the class LogarithmicAxisTest method testValueToJava2D.

/**
 * Test of valueToJava2D method.
 */
@Test
public void testValueToJava2D() {
    Rectangle2D plotArea = new Rectangle2D.Double(22, 33, 500, 500);
    RectangleEdge edge = RectangleEdge.BOTTOM;
    // set axis bounds to be both greater than 1
    this.axis.setRange(10, 20);
    checkPointsToJava2D(edge, plotArea);
    // check for bounds interval that includes 1
    this.axis.setRange(0.5, 10);
    checkPointsToJava2D(edge, plotArea);
    // check for bounds interval that includes 1
    this.axis.setRange(0.2, 20);
    checkPointsToJava2D(edge, plotArea);
    // check for both bounds smaller than 1
    this.axis.setRange(0.2, 0.7);
    checkPointsToJava2D(edge, plotArea);
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) RectangleEdge(org.jfree.chart.api.RectangleEdge) Test(org.junit.jupiter.api.Test)

Example 27 with RectangleEdge

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

the class LogarithmicAxisTest method testJava2DToValue.

/**
 * Test of java2DToValue method.
 */
@Test
public void testJava2DToValue() {
    Rectangle2D plotArea = new Rectangle2D.Double(22, 33, 500, 500);
    RectangleEdge edge = RectangleEdge.BOTTOM;
    // set axis bounds to be both greater than 1
    this.axis.setRange(10, 20);
    checkPointsToValue(edge, plotArea);
    // check for bounds interval that includes 1
    this.axis.setRange(0.5, 10);
    checkPointsToValue(edge, plotArea);
    // check for bounds interval that includes 1
    this.axis.setRange(0.2, 20);
    checkPointsToValue(edge, plotArea);
    // check for both bounds smaller than 1
    this.axis.setRange(0.2, 0.7);
    checkPointsToValue(edge, plotArea);
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) RectangleEdge(org.jfree.chart.api.RectangleEdge) Test(org.junit.jupiter.api.Test)

Example 28 with RectangleEdge

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

the class CategoryPlot method draw.

/**
 * Draws the plot on a Java 2D graphics device (such as the screen or a
 * printer).
 * <P>
 * At your option, you may supply an instance of {@link PlotRenderingInfo}.
 * If you do, it will be populated with information about the drawing,
 * including various plot dimensions and tooltip info.
 *
 * @param g2  the graphics device.
 * @param area  the area within which the plot (including axes) should
 *              be drawn.
 * @param anchor  the anchor point ({@code null} permitted).
 * @param parentState  the state from the parent plot, if there is one.
 * @param state  collects info as the chart is drawn (possibly
 *               {@code null}).
 */
@Override
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo state) {
    // if the plot area is too small, just return...
    boolean b1 = (area.getWidth() <= MINIMUM_WIDTH_TO_DRAW);
    boolean b2 = (area.getHeight() <= MINIMUM_HEIGHT_TO_DRAW);
    if (b1 || b2) {
        return;
    }
    // record the plot area...
    if (state == null) {
        // if the incoming state is null, no information will be passed
        // back to the caller - but we create a temporary state to record
        // the plot area, since that is used later by the axes
        state = new PlotRenderingInfo(null);
    }
    state.setPlotArea(area);
    // adjust the drawing area for the plot insets (if any)...
    RectangleInsets insets = getInsets();
    insets.trim(area);
    // calculate the data area...
    AxisSpace space = calculateAxisSpace(g2, area);
    Rectangle2D dataArea = space.shrink(area, null);
    this.axisOffset.trim(dataArea);
    dataArea = integerise(dataArea);
    if (dataArea.isEmpty()) {
        return;
    }
    state.setDataArea(dataArea);
    createAndAddEntity((Rectangle2D) dataArea.clone(), state, null, null);
    // default background...
    if (getRenderer() != null) {
        getRenderer().drawBackground(g2, this, dataArea);
    } else {
        drawBackground(g2, dataArea);
    }
    Map<Axis, AxisState> axisStateMap = drawAxes(g2, area, dataArea, state);
    // clicked - the crosshairs will be driven off this point...
    if (anchor != null && !dataArea.contains(anchor)) {
        anchor = ShapeUtils.getPointInRectangle(anchor.getX(), anchor.getY(), dataArea);
    }
    CategoryCrosshairState<R, C> crosshairState = new CategoryCrosshairState<>();
    crosshairState.setCrosshairDistance(Double.POSITIVE_INFINITY);
    crosshairState.setAnchor(anchor);
    // specify the anchor X and Y coordinates in Java2D space, for the
    // cases where these are not updated during rendering (i.e. no lock
    // on data)
    crosshairState.setAnchorX(Double.NaN);
    crosshairState.setAnchorY(Double.NaN);
    if (anchor != null) {
        ValueAxis rangeAxis = getRangeAxis();
        if (rangeAxis != null) {
            double y;
            if (getOrientation() == PlotOrientation.VERTICAL) {
                y = rangeAxis.java2DToValue(anchor.getY(), dataArea, getRangeAxisEdge());
            } else {
                y = rangeAxis.java2DToValue(anchor.getX(), dataArea, getRangeAxisEdge());
            }
            crosshairState.setAnchorY(y);
        }
    }
    crosshairState.setRowKey(getDomainCrosshairRowKey());
    crosshairState.setColumnKey(getDomainCrosshairColumnKey());
    crosshairState.setCrosshairY(getRangeCrosshairValue());
    // don't let anyone draw outside the data area
    Shape savedClip = g2.getClip();
    g2.clip(dataArea);
    drawDomainGridlines(g2, dataArea);
    AxisState rangeAxisState = axisStateMap.get(getRangeAxis());
    if (rangeAxisState == null) {
        if (parentState != null) {
            rangeAxisState = parentState.getSharedAxisStates().get(getRangeAxis());
        }
    }
    if (rangeAxisState != null) {
        drawRangeGridlines(g2, dataArea, rangeAxisState.getTicks());
        drawZeroRangeBaseline(g2, dataArea);
    }
    Graphics2D savedG2 = g2;
    BufferedImage dataImage = null;
    boolean suppressShadow = Boolean.TRUE.equals(g2.getRenderingHint(JFreeChart.KEY_SUPPRESS_SHADOW_GENERATION));
    if (this.shadowGenerator != null && !suppressShadow) {
        dataImage = new BufferedImage((int) dataArea.getWidth(), (int) dataArea.getHeight(), BufferedImage.TYPE_INT_ARGB);
        g2 = dataImage.createGraphics();
        g2.translate(-dataArea.getX(), -dataArea.getY());
        g2.setRenderingHints(savedG2.getRenderingHints());
    }
    // draw the markers...
    for (CategoryItemRenderer renderer : this.renderers.values()) {
        int i = getIndexOf(renderer);
        drawDomainMarkers(g2, dataArea, i, Layer.BACKGROUND);
    }
    for (CategoryItemRenderer renderer : this.renderers.values()) {
        int i = getIndexOf(renderer);
        drawRangeMarkers(g2, dataArea, i, Layer.BACKGROUND);
    }
    // now render data items...
    boolean foundData = false;
    // set up the alpha-transparency...
    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));
    DatasetRenderingOrder order = getDatasetRenderingOrder();
    List<Integer> datasetIndices = getDatasetIndices(order);
    for (int i : datasetIndices) {
        foundData = render(g2, dataArea, i, state, crosshairState) || foundData;
    }
    // draw the foreground markers...
    List<Integer> rendererIndices = getRendererIndices(order);
    for (int i : rendererIndices) {
        drawDomainMarkers(g2, dataArea, i, Layer.FOREGROUND);
    }
    for (int i : rendererIndices) {
        drawRangeMarkers(g2, dataArea, i, Layer.FOREGROUND);
    }
    // draw the annotations (if any)...
    drawAnnotations(g2, dataArea);
    if (this.shadowGenerator != null && !suppressShadow) {
        BufferedImage shadowImage = this.shadowGenerator.createDropShadow(dataImage);
        g2 = savedG2;
        g2.drawImage(shadowImage, (int) dataArea.getX() + this.shadowGenerator.calculateOffsetX(), (int) dataArea.getY() + this.shadowGenerator.calculateOffsetY(), null);
        g2.drawImage(dataImage, (int) dataArea.getX(), (int) dataArea.getY(), null);
    }
    g2.setClip(savedClip);
    g2.setComposite(originalComposite);
    if (!foundData) {
        drawNoDataMessage(g2, dataArea);
    }
    int datasetIndex = crosshairState.getDatasetIndex();
    setCrosshairDatasetIndex(datasetIndex, false);
    // draw domain crosshair if required...
    R rowKey = crosshairState.getRowKey();
    C columnKey = crosshairState.getColumnKey();
    setDomainCrosshairRowKey(rowKey, false);
    setDomainCrosshairColumnKey(columnKey, false);
    if (isDomainCrosshairVisible() && columnKey != null) {
        Paint paint = getDomainCrosshairPaint();
        Stroke stroke = getDomainCrosshairStroke();
        drawDomainCrosshair(g2, dataArea, this.orientation, datasetIndex, rowKey, columnKey, stroke, paint);
    }
    // draw range crosshair if required...
    ValueAxis yAxis = getRangeAxisForDataset(datasetIndex);
    RectangleEdge yAxisEdge = getRangeAxisEdge();
    if (!this.rangeCrosshairLockedOnData && anchor != null) {
        double yy;
        if (getOrientation() == PlotOrientation.VERTICAL) {
            yy = yAxis.java2DToValue(anchor.getY(), dataArea, yAxisEdge);
        } else {
            yy = yAxis.java2DToValue(anchor.getX(), dataArea, yAxisEdge);
        }
        crosshairState.setCrosshairY(yy);
    }
    setRangeCrosshairValue(crosshairState.getCrosshairY(), false);
    if (isRangeCrosshairVisible()) {
        double y = getRangeCrosshairValue();
        Paint paint = getRangeCrosshairPaint();
        Stroke stroke = getRangeCrosshairStroke();
        drawRangeCrosshair(g2, dataArea, getOrientation(), y, yAxis, stroke, paint);
    }
    // draw an outline around the plot area...
    if (isOutlineVisible()) {
        if (getRenderer() != null) {
            getRenderer().drawOutline(g2, this, dataArea);
        } else {
            drawOutline(g2, dataArea);
        }
    }
}
Also used : Shape(java.awt.Shape) BufferedImage(java.awt.image.BufferedImage) ValueAxis(org.jfree.chart.axis.ValueAxis) AxisSpace(org.jfree.chart.axis.AxisSpace) CategoryAxis(org.jfree.chart.axis.CategoryAxis) Axis(org.jfree.chart.axis.Axis) ValueAxis(org.jfree.chart.axis.ValueAxis) BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) Rectangle2D(java.awt.geom.Rectangle2D) Paint(java.awt.Paint) Paint(java.awt.Paint) Graphics2D(java.awt.Graphics2D) AxisState(org.jfree.chart.axis.AxisState) RectangleInsets(org.jfree.chart.api.RectangleInsets) RectangleEdge(org.jfree.chart.api.RectangleEdge)

Example 29 with RectangleEdge

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

the class CategoryPlot method drawDomainGridlines.

/**
 * Draws the domain gridlines for the plot, if they are visible.
 *
 * @param g2  the graphics device.
 * @param dataArea  the area inside the axes.
 *
 * @see #drawRangeGridlines(Graphics2D, Rectangle2D, List)
 */
protected void drawDomainGridlines(Graphics2D g2, Rectangle2D dataArea) {
    if (!isDomainGridlinesVisible()) {
        return;
    }
    CategoryAnchor anchor = getDomainGridlinePosition();
    RectangleEdge domainAxisEdge = getDomainAxisEdge();
    CategoryDataset<R, C> dataset = getDataset();
    if (dataset == null) {
        return;
    }
    CategoryAxis axis = getDomainAxis();
    if (axis != null) {
        int columnCount = dataset.getColumnCount();
        for (int c = 0; c < columnCount; c++) {
            double xx = axis.getCategoryJava2DCoordinate(anchor, c, columnCount, dataArea, domainAxisEdge);
            CategoryItemRenderer renderer1 = getRenderer();
            if (renderer1 != null) {
                renderer1.drawDomainGridline(g2, this, dataArea, xx);
            }
        }
    }
}
Also used : CategoryAnchor(org.jfree.chart.axis.CategoryAnchor) CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) CategoryAxis(org.jfree.chart.axis.CategoryAxis) Paint(java.awt.Paint) RectangleEdge(org.jfree.chart.api.RectangleEdge)

Example 30 with RectangleEdge

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

the class CategoryPlot method calculateRangeAxisSpace.

/**
 * Calculates the space required for the range axis/axes.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 * @param space  a carrier for the result ({@code null} permitted).
 *
 * @return The required space.
 */
protected AxisSpace calculateRangeAxisSpace(Graphics2D g2, Rectangle2D plotArea, AxisSpace space) {
    if (space == null) {
        space = new AxisSpace();
    }
    // reserve some space for the range axis...
    if (this.fixedRangeAxisSpace != null) {
        if (this.orientation.isHorizontal()) {
            space.ensureAtLeast(this.fixedRangeAxisSpace.getTop(), RectangleEdge.TOP);
            space.ensureAtLeast(this.fixedRangeAxisSpace.getBottom(), RectangleEdge.BOTTOM);
        } else if (this.orientation == PlotOrientation.VERTICAL) {
            space.ensureAtLeast(this.fixedRangeAxisSpace.getLeft(), RectangleEdge.LEFT);
            space.ensureAtLeast(this.fixedRangeAxisSpace.getRight(), RectangleEdge.RIGHT);
        }
    } else {
        // reserve space for the range axes (if any)...
        for (ValueAxis yAxis : this.rangeAxes.values()) {
            if (yAxis != null) {
                int i = findRangeAxisIndex(yAxis);
                RectangleEdge edge = getRangeAxisEdge(i);
                space = yAxis.reserveSpace(g2, this, plotArea, edge, space);
            }
        }
    }
    return space;
}
Also used : ValueAxis(org.jfree.chart.axis.ValueAxis) AxisSpace(org.jfree.chart.axis.AxisSpace) Paint(java.awt.Paint) 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