Search in sources :

Example 16 with AxisSpace

use of org.jfree.chart.axis.AxisSpace in project SIMVA-SoS by SESoS.

the class CategoryPlotTest method testEquals.

/**
 * Test that the equals() method differentiates all the required fields.
 */
@Test
public void testEquals() {
    CategoryPlot plot1 = new CategoryPlot();
    CategoryPlot plot2 = new CategoryPlot();
    assertTrue(plot1.equals(plot2));
    assertTrue(plot2.equals(plot1));
    // orientation...
    plot1.setOrientation(PlotOrientation.HORIZONTAL);
    assertFalse(plot1.equals(plot2));
    plot2.setOrientation(PlotOrientation.HORIZONTAL);
    assertTrue(plot1.equals(plot2));
    // axisOffset...
    plot1.setAxisOffset(new RectangleInsets(0.05, 0.05, 0.05, 0.05));
    assertFalse(plot1.equals(plot2));
    plot2.setAxisOffset(new RectangleInsets(0.05, 0.05, 0.05, 0.05));
    assertTrue(plot1.equals(plot2));
    // domainAxis - no longer a separate field but test anyway...
    plot1.setDomainAxis(new CategoryAxis("Category Axis"));
    assertFalse(plot1.equals(plot2));
    plot2.setDomainAxis(new CategoryAxis("Category Axis"));
    assertTrue(plot1.equals(plot2));
    // domainAxes...
    plot1.setDomainAxis(11, new CategoryAxis("Secondary Axis"));
    assertFalse(plot1.equals(plot2));
    plot2.setDomainAxis(11, new CategoryAxis("Secondary Axis"));
    assertTrue(plot1.equals(plot2));
    // domainAxisLocation - no longer a separate field but test anyway...
    plot1.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
    assertFalse(plot1.equals(plot2));
    plot2.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
    assertTrue(plot1.equals(plot2));
    // domainAxisLocations...
    plot1.setDomainAxisLocation(11, AxisLocation.TOP_OR_RIGHT);
    assertFalse(plot1.equals(plot2));
    plot2.setDomainAxisLocation(11, AxisLocation.TOP_OR_RIGHT);
    assertTrue(plot1.equals(plot2));
    // draw shared domain axis...
    plot1.setDrawSharedDomainAxis(!plot1.getDrawSharedDomainAxis());
    assertFalse(plot1.equals(plot2));
    plot2.setDrawSharedDomainAxis(!plot2.getDrawSharedDomainAxis());
    assertTrue(plot1.equals(plot2));
    // rangeAxis - no longer a separate field but test anyway...
    plot1.setRangeAxis(new NumberAxis("Range Axis"));
    assertFalse(plot1.equals(plot2));
    plot2.setRangeAxis(new NumberAxis("Range Axis"));
    assertTrue(plot1.equals(plot2));
    // rangeAxes...
    plot1.setRangeAxis(11, new NumberAxis("Secondary Range Axis"));
    assertFalse(plot1.equals(plot2));
    plot2.setRangeAxis(11, new NumberAxis("Secondary Range Axis"));
    assertTrue(plot1.equals(plot2));
    // rangeAxisLocation - no longer a separate field but test anyway...
    plot1.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT);
    assertFalse(plot1.equals(plot2));
    plot2.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT);
    assertTrue(plot1.equals(plot2));
    // rangeAxisLocations...
    plot1.setRangeAxisLocation(11, AxisLocation.TOP_OR_RIGHT);
    assertFalse(plot1.equals(plot2));
    plot2.setRangeAxisLocation(11, AxisLocation.TOP_OR_RIGHT);
    assertTrue(plot1.equals(plot2));
    // datasetToDomainAxisMap...
    plot1.mapDatasetToDomainAxis(11, 11);
    assertFalse(plot1.equals(plot2));
    plot2.mapDatasetToDomainAxis(11, 11);
    assertTrue(plot1.equals(plot2));
    // datasetToRangeAxisMap...
    plot1.mapDatasetToRangeAxis(11, 11);
    assertFalse(plot1.equals(plot2));
    plot2.mapDatasetToRangeAxis(11, 11);
    assertTrue(plot1.equals(plot2));
    // renderer - no longer a separate field but test anyway...
    plot1.setRenderer(new AreaRenderer());
    assertFalse(plot1.equals(plot2));
    plot2.setRenderer(new AreaRenderer());
    assertTrue(plot1.equals(plot2));
    // renderers...
    plot1.setRenderer(11, new AreaRenderer());
    assertFalse(plot1.equals(plot2));
    plot2.setRenderer(11, new AreaRenderer());
    assertTrue(plot1.equals(plot2));
    // rendering order...
    plot1.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    assertFalse(plot1.equals(plot2));
    plot2.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    assertTrue(plot1.equals(plot2));
    // columnRenderingOrder...
    plot1.setColumnRenderingOrder(SortOrder.DESCENDING);
    assertFalse(plot1.equals(plot2));
    plot2.setColumnRenderingOrder(SortOrder.DESCENDING);
    assertTrue(plot1.equals(plot2));
    // rowRenderingOrder...
    plot1.setRowRenderingOrder(SortOrder.DESCENDING);
    assertFalse(plot1.equals(plot2));
    plot2.setRowRenderingOrder(SortOrder.DESCENDING);
    assertTrue(plot1.equals(plot2));
    // domainGridlinesVisible
    plot1.setDomainGridlinesVisible(true);
    assertFalse(plot1.equals(plot2));
    plot2.setDomainGridlinesVisible(true);
    assertTrue(plot1.equals(plot2));
    // domainGridlinePosition
    plot1.setDomainGridlinePosition(CategoryAnchor.END);
    assertFalse(plot1.equals(plot2));
    plot2.setDomainGridlinePosition(CategoryAnchor.END);
    assertTrue(plot1.equals(plot2));
    // domainGridlineStroke
    Stroke stroke = new BasicStroke(2.0f);
    plot1.setDomainGridlineStroke(stroke);
    assertFalse(plot1.equals(plot2));
    plot2.setDomainGridlineStroke(stroke);
    assertTrue(plot1.equals(plot2));
    // domainGridlinePaint
    plot1.setDomainGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.blue, 3.0f, 4.0f, Color.yellow));
    assertFalse(plot1.equals(plot2));
    plot2.setDomainGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.blue, 3.0f, 4.0f, Color.yellow));
    assertTrue(plot1.equals(plot2));
    // rangeGridlinesVisible
    plot1.setRangeGridlinesVisible(false);
    assertFalse(plot1.equals(plot2));
    plot2.setRangeGridlinesVisible(false);
    assertTrue(plot1.equals(plot2));
    // rangeGridlineStroke
    plot1.setRangeGridlineStroke(stroke);
    assertFalse(plot1.equals(plot2));
    plot2.setRangeGridlineStroke(stroke);
    assertTrue(plot1.equals(plot2));
    // rangeGridlinePaint
    plot1.setRangeGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, Color.yellow));
    assertFalse(plot1.equals(plot2));
    plot2.setRangeGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, Color.yellow));
    assertTrue(plot1.equals(plot2));
    // anchorValue
    plot1.setAnchorValue(100.0);
    assertFalse(plot1.equals(plot2));
    plot2.setAnchorValue(100.0);
    assertTrue(plot1.equals(plot2));
    // rangeCrosshairVisible
    plot1.setRangeCrosshairVisible(true);
    assertFalse(plot1.equals(plot2));
    plot2.setRangeCrosshairVisible(true);
    assertTrue(plot1.equals(plot2));
    // rangeCrosshairValue
    plot1.setRangeCrosshairValue(100.0);
    assertFalse(plot1.equals(plot2));
    plot2.setRangeCrosshairValue(100.0);
    assertTrue(plot1.equals(plot2));
    // rangeCrosshairStroke
    plot1.setRangeCrosshairStroke(stroke);
    assertFalse(plot1.equals(plot2));
    plot2.setRangeCrosshairStroke(stroke);
    assertTrue(plot1.equals(plot2));
    // rangeCrosshairPaint
    plot1.setRangeCrosshairPaint(new GradientPaint(1.0f, 2.0f, Color.white, 3.0f, 4.0f, Color.yellow));
    assertFalse(plot1.equals(plot2));
    plot2.setRangeCrosshairPaint(new GradientPaint(1.0f, 2.0f, Color.white, 3.0f, 4.0f, Color.yellow));
    assertTrue(plot1.equals(plot2));
    // rangeCrosshairLockedOnData
    plot1.setRangeCrosshairLockedOnData(false);
    assertFalse(plot1.equals(plot2));
    plot2.setRangeCrosshairLockedOnData(false);
    assertTrue(plot1.equals(plot2));
    // foreground domain markers
    plot1.addDomainMarker(new CategoryMarker("C1"), Layer.FOREGROUND);
    assertFalse(plot1.equals(plot2));
    plot2.addDomainMarker(new CategoryMarker("C1"), Layer.FOREGROUND);
    assertTrue(plot1.equals(plot2));
    // background domain markers
    plot1.addDomainMarker(new CategoryMarker("C2"), Layer.BACKGROUND);
    assertFalse(plot1.equals(plot2));
    plot2.addDomainMarker(new CategoryMarker("C2"), Layer.BACKGROUND);
    assertTrue(plot1.equals(plot2));
    // range markers - no longer separate fields but test anyway...
    plot1.addRangeMarker(new ValueMarker(4.0), Layer.FOREGROUND);
    assertFalse(plot1.equals(plot2));
    plot2.addRangeMarker(new ValueMarker(4.0), Layer.FOREGROUND);
    assertTrue(plot1.equals(plot2));
    plot1.addRangeMarker(new ValueMarker(5.0), Layer.BACKGROUND);
    assertFalse(plot1.equals(plot2));
    plot2.addRangeMarker(new ValueMarker(5.0), Layer.BACKGROUND);
    assertTrue(plot1.equals(plot2));
    // foreground range markers...
    plot1.addRangeMarker(1, new ValueMarker(4.0), Layer.FOREGROUND);
    assertFalse(plot1.equals(plot2));
    plot2.addRangeMarker(1, new ValueMarker(4.0), Layer.FOREGROUND);
    assertTrue(plot1.equals(plot2));
    // background range markers...
    plot1.addRangeMarker(1, new ValueMarker(5.0), Layer.BACKGROUND);
    assertFalse(plot1.equals(plot2));
    plot2.addRangeMarker(1, new ValueMarker(5.0), Layer.BACKGROUND);
    assertTrue(plot1.equals(plot2));
    // annotations
    plot1.addAnnotation(new CategoryTextAnnotation("Text", "Category", 43.0));
    assertFalse(plot1.equals(plot2));
    plot2.addAnnotation(new CategoryTextAnnotation("Text", "Category", 43.0));
    assertTrue(plot1.equals(plot2));
    // weight
    plot1.setWeight(3);
    assertFalse(plot1.equals(plot2));
    plot2.setWeight(3);
    assertTrue(plot1.equals(plot2));
    // fixed domain axis space...
    plot1.setFixedDomainAxisSpace(new AxisSpace());
    assertFalse(plot1.equals(plot2));
    plot2.setFixedDomainAxisSpace(new AxisSpace());
    assertTrue(plot1.equals(plot2));
    // fixed range axis space...
    plot1.setFixedRangeAxisSpace(new AxisSpace());
    assertFalse(plot1.equals(plot2));
    plot2.setFixedRangeAxisSpace(new AxisSpace());
    assertTrue(plot1.equals(plot2));
    // fixed legend items
    plot1.setFixedLegendItems(new LegendItemCollection());
    assertFalse(plot1.equals(plot2));
    plot2.setFixedLegendItems(new LegendItemCollection());
    assertTrue(plot1.equals(plot2));
    // crosshairDatasetIndex
    plot1.setCrosshairDatasetIndex(99);
    assertFalse(plot1.equals(plot2));
    plot2.setCrosshairDatasetIndex(99);
    assertTrue(plot1.equals(plot2));
    // domainCrosshairColumnKey
    plot1.setDomainCrosshairColumnKey("A");
    assertFalse(plot1.equals(plot2));
    plot2.setDomainCrosshairColumnKey("A");
    assertTrue(plot1.equals(plot2));
    // domainCrosshairRowKey
    plot1.setDomainCrosshairRowKey("B");
    assertFalse(plot1.equals(plot2));
    plot2.setDomainCrosshairRowKey("B");
    assertTrue(plot1.equals(plot2));
    // domainCrosshairVisible
    plot1.setDomainCrosshairVisible(true);
    assertFalse(plot1.equals(plot2));
    plot2.setDomainCrosshairVisible(true);
    assertTrue(plot1.equals(plot2));
    // domainCrosshairPaint
    plot1.setDomainCrosshairPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.blue));
    assertFalse(plot1.equals(plot2));
    plot2.setDomainCrosshairPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.blue));
    assertTrue(plot1.equals(plot2));
    // domainCrosshairStroke
    plot1.setDomainCrosshairStroke(new BasicStroke(1.23f));
    assertFalse(plot1.equals(plot2));
    plot2.setDomainCrosshairStroke(new BasicStroke(1.23f));
    assertTrue(plot1.equals(plot2));
    plot1.setRangeMinorGridlinesVisible(true);
    assertFalse(plot1.equals(plot2));
    plot2.setRangeMinorGridlinesVisible(true);
    assertTrue(plot1.equals(plot2));
    plot1.setRangeMinorGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.blue));
    assertFalse(plot1.equals(plot2));
    plot2.setRangeMinorGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.blue));
    assertTrue(plot1.equals(plot2));
    plot1.setRangeMinorGridlineStroke(new BasicStroke(1.23f));
    assertFalse(plot1.equals(plot2));
    plot2.setRangeMinorGridlineStroke(new BasicStroke(1.23f));
    assertTrue(plot1.equals(plot2));
    plot1.setRangeZeroBaselineVisible(!plot1.isRangeZeroBaselineVisible());
    assertFalse(plot1.equals(plot2));
    plot2.setRangeZeroBaselineVisible(!plot2.isRangeZeroBaselineVisible());
    assertTrue(plot1.equals(plot2));
    plot1.setRangeZeroBaselinePaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.blue));
    assertFalse(plot1.equals(plot2));
    plot2.setRangeZeroBaselinePaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.blue));
    assertTrue(plot1.equals(plot2));
    plot1.setRangeZeroBaselineStroke(new BasicStroke(1.23f));
    assertFalse(plot1.equals(plot2));
    plot2.setRangeZeroBaselineStroke(new BasicStroke(1.23f));
    assertTrue(plot1.equals(plot2));
    // shadowGenerator
    plot1.setShadowGenerator(new DefaultShadowGenerator(5, Color.gray, 0.6f, 4, -Math.PI / 4));
    assertFalse(plot1.equals(plot2));
    plot2.setShadowGenerator(new DefaultShadowGenerator(5, Color.gray, 0.6f, 4, -Math.PI / 4));
    assertTrue(plot1.equals(plot2));
    plot1.setShadowGenerator(null);
    assertFalse(plot1.equals(plot2));
    plot2.setShadowGenerator(null);
    assertTrue(plot1.equals(plot2));
}
Also used : BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) NumberAxis(org.jfree.chart.axis.NumberAxis) AreaRenderer(org.jfree.chart.renderer.category.AreaRenderer) LegendItemCollection(org.jfree.chart.LegendItemCollection) GradientPaint(java.awt.GradientPaint) DefaultShadowGenerator(org.jfree.chart.util.DefaultShadowGenerator) CategoryAxis(org.jfree.chart.axis.CategoryAxis) RectangleInsets(org.jfree.ui.RectangleInsets) AxisSpace(org.jfree.chart.axis.AxisSpace) CategoryTextAnnotation(org.jfree.chart.annotations.CategoryTextAnnotation) Test(org.junit.Test)

Example 17 with AxisSpace

use of org.jfree.chart.axis.AxisSpace in project SIMVA-SoS by SESoS.

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.ui.Size2D) Rectangle2D(java.awt.geom.Rectangle2D) AxisSpace(org.jfree.chart.axis.AxisSpace) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 18 with AxisSpace

use of org.jfree.chart.axis.AxisSpace in project SIMVA-SoS by SESoS.

the class XYPlot 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</code>
 *                permitted).
 * @param parentState  the state from the parent plot, if there is one
 *                     (<code>null</code> permitted).
 * @param info  collects chart drawing information (<code>null</code>
 *              permitted).
 */
@Override
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) {
    // 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 (info != null) {
        info.setPlotArea(area);
    }
    // adjust the drawing area for the 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);
    dataArea = integerise(dataArea);
    if (dataArea.isEmpty()) {
        return;
    }
    createAndAddEntity((Rectangle2D) dataArea.clone(), info, null, null);
    if (info != null) {
        info.setDataArea(dataArea);
    }
    // draw the plot background and axes...
    drawBackground(g2, dataArea);
    Map axisStateMap = drawAxes(g2, area, dataArea, info);
    PlotOrientation orient = getOrientation();
    // clicked - the crosshairs will be driven off this point...
    if (anchor != null && !dataArea.contains(anchor)) {
        anchor = null;
    }
    CrosshairState crosshairState = new CrosshairState();
    crosshairState.setCrosshairDistance(Double.POSITIVE_INFINITY);
    crosshairState.setAnchor(anchor);
    crosshairState.setAnchorX(Double.NaN);
    crosshairState.setAnchorY(Double.NaN);
    if (anchor != null) {
        ValueAxis domainAxis = getDomainAxis();
        if (domainAxis != null) {
            double x;
            if (orient == PlotOrientation.VERTICAL) {
                x = domainAxis.java2DToValue(anchor.getX(), dataArea, getDomainAxisEdge());
            } else {
                x = domainAxis.java2DToValue(anchor.getY(), dataArea, getDomainAxisEdge());
            }
            crosshairState.setAnchorX(x);
        }
        ValueAxis rangeAxis = getRangeAxis();
        if (rangeAxis != null) {
            double y;
            if (orient == PlotOrientation.VERTICAL) {
                y = rangeAxis.java2DToValue(anchor.getY(), dataArea, getRangeAxisEdge());
            } else {
                y = rangeAxis.java2DToValue(anchor.getX(), dataArea, getRangeAxisEdge());
            }
            crosshairState.setAnchorY(y);
        }
    }
    crosshairState.setCrosshairX(getDomainCrosshairValue());
    crosshairState.setCrosshairY(getRangeCrosshairValue());
    Shape originalClip = g2.getClip();
    Composite originalComposite = g2.getComposite();
    g2.clip(dataArea);
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));
    AxisState domainAxisState = (AxisState) axisStateMap.get(getDomainAxis());
    if (domainAxisState == null) {
        if (parentState != null) {
            domainAxisState = (AxisState) parentState.getSharedAxisStates().get(getDomainAxis());
        }
    }
    AxisState rangeAxisState = (AxisState) axisStateMap.get(getRangeAxis());
    if (rangeAxisState == null) {
        if (parentState != null) {
            rangeAxisState = (AxisState) parentState.getSharedAxisStates().get(getRangeAxis());
        }
    }
    if (domainAxisState != null) {
        drawDomainTickBands(g2, dataArea, domainAxisState.getTicks());
    }
    if (rangeAxisState != null) {
        drawRangeTickBands(g2, dataArea, rangeAxisState.getTicks());
    }
    if (domainAxisState != null) {
        drawDomainGridlines(g2, dataArea, domainAxisState.getTicks());
        drawZeroDomainBaseline(g2, dataArea);
    }
    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 that are associated with a specific dataset...
    for (XYDataset dataset : this.datasets.values()) {
        int datasetIndex = indexOf(dataset);
        drawDomainMarkers(g2, dataArea, datasetIndex, Layer.BACKGROUND);
    }
    for (XYDataset dataset : this.datasets.values()) {
        int datasetIndex = indexOf(dataset);
        drawRangeMarkers(g2, dataArea, datasetIndex, Layer.BACKGROUND);
    }
    // now draw annotations and render data items...
    boolean foundData = false;
    DatasetRenderingOrder order = getDatasetRenderingOrder();
    List<Integer> rendererIndices = getRendererIndices(order);
    List<Integer> datasetIndices = getDatasetIndices(order);
    // draw background annotations
    for (int i : rendererIndices) {
        XYItemRenderer renderer = getRenderer(i);
        if (renderer != null) {
            ValueAxis domainAxis = getDomainAxisForDataset(i);
            ValueAxis rangeAxis = getRangeAxisForDataset(i);
            renderer.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, Layer.BACKGROUND, info);
        }
    }
    // render data items...
    for (int datasetIndex : datasetIndices) {
        XYDataset dataset = this.getDataset(datasetIndex);
        foundData = render(g2, dataArea, datasetIndex, info, crosshairState) || foundData;
    }
    // draw foreground annotations
    for (int i : rendererIndices) {
        XYItemRenderer renderer = getRenderer(i);
        if (renderer != null) {
            ValueAxis domainAxis = getDomainAxisForDataset(i);
            ValueAxis rangeAxis = getRangeAxisForDataset(i);
            renderer.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, Layer.FOREGROUND, info);
        }
    }
    // draw domain crosshair if required...
    int datasetIndex = crosshairState.getDatasetIndex();
    ValueAxis xAxis = this.getDomainAxisForDataset(datasetIndex);
    RectangleEdge xAxisEdge = getDomainAxisEdge(getDomainAxisIndex(xAxis));
    if (!this.domainCrosshairLockedOnData && anchor != null) {
        double xx;
        if (orient == PlotOrientation.VERTICAL) {
            xx = xAxis.java2DToValue(anchor.getX(), dataArea, xAxisEdge);
        } else {
            xx = xAxis.java2DToValue(anchor.getY(), dataArea, xAxisEdge);
        }
        crosshairState.setCrosshairX(xx);
    }
    setDomainCrosshairValue(crosshairState.getCrosshairX(), false);
    if (isDomainCrosshairVisible()) {
        double x = getDomainCrosshairValue();
        Paint paint = getDomainCrosshairPaint();
        Stroke stroke = getDomainCrosshairStroke();
        drawDomainCrosshair(g2, dataArea, orient, x, xAxis, stroke, paint);
    }
    // draw range crosshair if required...
    ValueAxis yAxis = getRangeAxisForDataset(datasetIndex);
    RectangleEdge yAxisEdge = getRangeAxisEdge(getRangeAxisIndex(yAxis));
    if (!this.rangeCrosshairLockedOnData && anchor != null) {
        double yy;
        if (orient == 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, orient, y, yAxis, stroke, paint);
    }
    if (!foundData) {
        drawNoDataMessage(g2, dataArea);
    }
    for (int i : rendererIndices) {
        drawDomainMarkers(g2, dataArea, i, Layer.FOREGROUND);
    }
    for (int i : rendererIndices) {
        drawRangeMarkers(g2, dataArea, i, Layer.FOREGROUND);
    }
    drawAnnotations(g2, dataArea, info);
    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(originalClip);
    g2.setComposite(originalComposite);
    drawOutline(g2, dataArea);
}
Also used : BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) Shape(java.awt.Shape) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) Rectangle2D(java.awt.geom.Rectangle2D) Paint(java.awt.Paint) BufferedImage(java.awt.image.BufferedImage) Paint(java.awt.Paint) Graphics2D(java.awt.Graphics2D) AxisState(org.jfree.chart.axis.AxisState) ValueAxis(org.jfree.chart.axis.ValueAxis) RectangleInsets(org.jfree.ui.RectangleInsets) XYDataset(org.jfree.data.xy.XYDataset) AxisSpace(org.jfree.chart.axis.AxisSpace) AbstractXYItemRenderer(org.jfree.chart.renderer.xy.AbstractXYItemRenderer) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 19 with AxisSpace

use of org.jfree.chart.axis.AxisSpace in project SIMVA-SoS by SESoS.

the class XYPlot method calculateAxisSpace.

/**
 * Calculates the space required for all the axes in the plot.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 *
 * @return The required space.
 */
protected AxisSpace calculateAxisSpace(Graphics2D g2, Rectangle2D plotArea) {
    AxisSpace space = new AxisSpace();
    space = calculateRangeAxisSpace(g2, plotArea, space);
    Rectangle2D revPlotArea = space.shrink(plotArea, null);
    space = calculateDomainAxisSpace(g2, revPlotArea, space);
    return space;
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) AxisSpace(org.jfree.chart.axis.AxisSpace)

Example 20 with AxisSpace

use of org.jfree.chart.axis.AxisSpace in project SIMVA-SoS by SESoS.

the class XYPlot method calculateDomainAxisSpace.

/**
 * Calculates the space required for the domain axis/axes.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 * @param space  a carrier for the result (<code>null</code> permitted).
 *
 * @return The required space.
 */
protected AxisSpace calculateDomainAxisSpace(Graphics2D g2, Rectangle2D plotArea, AxisSpace space) {
    if (space == null) {
        space = new AxisSpace();
    }
    // reserve some space for the domain axis...
    if (this.fixedDomainAxisSpace != null) {
        if (this.orientation == PlotOrientation.HORIZONTAL) {
            space.ensureAtLeast(this.fixedDomainAxisSpace.getLeft(), RectangleEdge.LEFT);
            space.ensureAtLeast(this.fixedDomainAxisSpace.getRight(), RectangleEdge.RIGHT);
        } else if (this.orientation == PlotOrientation.VERTICAL) {
            space.ensureAtLeast(this.fixedDomainAxisSpace.getTop(), RectangleEdge.TOP);
            space.ensureAtLeast(this.fixedDomainAxisSpace.getBottom(), RectangleEdge.BOTTOM);
        }
    } else {
        // reserve space for the domain axes...
        for (ValueAxis axis : this.domainAxes.values()) {
            if (axis != null) {
                RectangleEdge edge = getDomainAxisEdge(findDomainAxisIndex(axis));
                space = axis.reserveSpace(g2, this, plotArea, edge, space);
            }
        }
    }
    return space;
}
Also used : ValueAxis(org.jfree.chart.axis.ValueAxis) AxisSpace(org.jfree.chart.axis.AxisSpace) RectangleEdge(org.jfree.ui.RectangleEdge)

Aggregations

AxisSpace (org.jfree.chart.axis.AxisSpace)23 RectangleEdge (org.jfree.ui.RectangleEdge)15 Rectangle2D (java.awt.geom.Rectangle2D)14 ValueAxis (org.jfree.chart.axis.ValueAxis)11 RectangleInsets (org.jfree.ui.RectangleInsets)9 AxisState (org.jfree.chart.axis.AxisState)7 AlphaComposite (java.awt.AlphaComposite)4 Composite (java.awt.Composite)4 Paint (java.awt.Paint)4 Shape (java.awt.Shape)4 CategoryAxis (org.jfree.chart.axis.CategoryAxis)4 BasicStroke (java.awt.BasicStroke)3 Stroke (java.awt.Stroke)3 NumberAxis (org.jfree.chart.axis.NumberAxis)3 Color (java.awt.Color)2 Graphics2D (java.awt.Graphics2D)2 Point2D (java.awt.geom.Point2D)2 BufferedImage (java.awt.image.BufferedImage)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2