Search in sources :

Example 21 with AxisSpace

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

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</code> 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</code>).
 */
@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 axisStateMap = drawAxes(g2, area, dataArea, state);
    // clicked - the crosshairs will be driven off this point...
    if (anchor != null && !dataArea.contains(anchor)) {
        anchor = ShapeUtilities.getPointInRectangle(anchor.getX(), anchor.getY(), dataArea);
    }
    CategoryCrosshairState 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 = (AxisState) axisStateMap.get(getRangeAxis());
    if (rangeAxisState == null) {
        if (parentState != null) {
            rangeAxisState = (AxisState) 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...
    Comparable rowKey = crosshairState.getRowKey();
    Comparable 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 : BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) Shape(java.awt.Shape) AbstractCategoryItemRenderer(org.jfree.chart.renderer.category.AbstractCategoryItemRenderer) CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) 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) AxisSpace(org.jfree.chart.axis.AxisSpace) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 22 with AxisSpace

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

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</code> 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.ui.RectangleEdge)

Example 23 with AxisSpace

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

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</code> permitted).
 * @param parentState  the state from the parent plot, if there is one.
 * @param info  collects information about the drawing (<code>null</code>
 *              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.ui.RectangleInsets) 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