Example usage for org.jfree.chart.axis AxisSpace shrink

List of usage examples for org.jfree.chart.axis AxisSpace shrink

Introduction

In this page you can find the example usage for org.jfree.chart.axis AxisSpace shrink.

Prototype

public Rectangle2D shrink(Rectangle2D area, Rectangle2D result) 

Source Link

Document

Shrinks an area by the space attributes.

Usage

From source file:peakml.util.jfreechart.FastSpectrumPlot.java

@Override
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState,
        PlotRenderingInfo info) {/* w  w w  . j  a v  a 2s .co  m*/
    // add the plot area to the info (used amongst other by the axis for zooming)
    if (info != null)
        info.setPlotArea(area);

    // add the insets (if any)
    RectangleInsets insets = getInsets();
    insets.trim(area);

    // draw the axis and add the dataArea to the info (used amongst other by the axis for zooming)
    AxisSpace space = new AxisSpace();
    space = xaxis.reserveSpace(g2, this, area, RectangleEdge.BOTTOM, space);
    space = yaxis.reserveSpace(g2, this, area, RectangleEdge.LEFT, space);

    Rectangle2D dataArea = space.shrink(area, null);
    if (info != null)
        info.setDataArea(dataArea);

    // flood fill the whole area with the background color
    drawBackground(g2, dataArea);

    // draw the axis
    xaxis.draw(g2, dataArea.getMaxY(), area, dataArea, RectangleEdge.BOTTOM, info);
    yaxis.draw(g2, dataArea.getMinX(), area, dataArea, RectangleEdge.LEFT, info);

    // sanity check
    if (dataseries.size() == 0)
        return;

    // clip the draw area
    Shape originalclip = g2.getClip();
    g2.clip(dataArea);

    // draw all the values
    for (Data data : dataseries) {
        int xpos = (int) xaxis.valueToJava2D(data.mass, dataArea, RectangleEdge.BOTTOM);
        int ypos = (int) yaxis.valueToJava2D(data.intensity, dataArea, RectangleEdge.LEFT);
        g2.drawLine(xpos, (int) yaxis.valueToJava2D(0, dataArea, RectangleEdge.LEFT), xpos, ypos);

        // draw the label
        if (data.description != null && data.description.length() != 0) {
            g2.setColor(Color.RED);
            g2.drawLine(xpos + 2, ypos - 2, xpos + 15, ypos - 15);
            g2.setColor(Color.BLACK);
            g2.drawString(data.description, xpos + 17, ypos - 17);
        }
    }

    // reset
    g2.setClip(originalclip);
}

From source file:peakml.util.jfreechart.FastTimePlot.java

@Override
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState,
        PlotRenderingInfo info) {//w ww  . j  a va 2s  . c o m
    // add the plot area to the info (used amongst other by the axis for zooming)
    if (info != null)
        info.setPlotArea(area);

    // add the insets (if any)
    RectangleInsets insets = getInsets();
    insets.trim(area);

    // draw the axis and add the dataArea to the info (used amongst other by the axis for zooming)
    AxisSpace space = new AxisSpace();
    space = xaxis.reserveSpace(g2, this, area, RectangleEdge.BOTTOM, space);
    space = yaxis.reserveSpace(g2, this, area, RectangleEdge.LEFT, space);

    Rectangle2D dataArea = space.shrink(area, null);
    if (info != null)
        info.setDataArea(dataArea);

    // flood fill the whole area with the background color
    drawBackground(g2, dataArea);

    // draw the axis
    xaxis.draw(g2, dataArea.getMaxY(), area, dataArea, RectangleEdge.BOTTOM, info);
    yaxis.draw(g2, dataArea.getMinX(), area, dataArea, RectangleEdge.LEFT, info);

    // sanity check
    if (dataseries.size() == 0)
        return;

    // clip the draw area
    Shape originalclip = g2.getClip();
    g2.clip(dataArea);

    // draw all the values
    int index = 0;
    for (Data data : dataseries.values()) {
        g2.setColor(new Color(data.color == -1 ? colormap.getColor(index++) : data.color));
        for (int i = 0; i < data.size - 1; ++i) {
            g2.drawLine((int) xaxis.valueToJava2D(data.time[i], dataArea, RectangleEdge.BOTTOM),
                    (int) yaxis.valueToJava2D(data.values[i], dataArea, RectangleEdge.LEFT),
                    (int) xaxis.valueToJava2D(data.time[i + 1], dataArea, RectangleEdge.BOTTOM),
                    (int) yaxis.valueToJava2D(data.values[i + 1], dataArea, RectangleEdge.LEFT));
        }
    }

    // reset
    g2.setClip(originalclip);
}

From source file:peakml.util.jfreechart.FastErrorBarPlot.java

@Override
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState,
        PlotRenderingInfo info) {//  w ww  .j a v a 2s  .c o  m
    // add the plot area to the info (used amongst other by the axis for zooming)
    if (info != null)
        info.setPlotArea(area);

    // add the insets (if any)
    RectangleInsets insets = getInsets();
    insets.trim(area);

    // draw the axis and add the dataArea to the info (used amongst other by the axis for zooming)
    AxisSpace space = new AxisSpace();
    space = xaxis.reserveSpace(g2, this, area, RectangleEdge.BOTTOM, space);
    space = yaxis.reserveSpace(g2, this, area, RectangleEdge.LEFT, space);

    Rectangle2D dataArea = space.shrink(area, null);
    if (info != null)
        info.setDataArea(dataArea);

    // flood fill the whole area with the background color
    drawBackground(g2, dataArea);

    // draw the axis
    xaxis.draw(g2, dataArea.getMaxY(), area, dataArea, RectangleEdge.BOTTOM, info);
    yaxis.draw(g2, dataArea.getMinX(), area, dataArea, RectangleEdge.LEFT, info);

    // sanity check
    if (dataseries.size() == 0)
        return;

    // clip the draw area
    Shape originalclip = g2.getClip();
    g2.clip(dataArea);

    // create the strokes
    BasicStroke stroke_solid = new BasicStroke(1.f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1.f);
    BasicStroke stroke_dashed = new BasicStroke(1.f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1.f,
            new float[] { 2, 4 }, 0);

    g2.setStroke(stroke_solid);

    // count the number of labels
    int categoryCount = 0;
    if (showall) {
        for (Data data : dataseries)
            categoryCount += data.yvalues.length;
    } else
        categoryCount = dataseries.size();

    // draw all the values
    int pos = 0;
    boolean dashed = false;
    double prevx = -1, prevy = -1;
    for (Data data : dataseries) {
        if (data.yvalues.length == 0) {
            dashed = true;
            pos++;
            continue;
        }

        double mean[] = showall ? data.yvalues : new double[] { data.getMeanY() };
        double min[] = showall ? data.yvalues : new double[] { data.getMinY() };
        double max[] = showall ? data.yvalues : new double[] { data.getMaxY() };
        for (int i = 0; i < mean.length; ++i) {
            double ypos, xpos = xaxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, pos++, categoryCount,
                    dataArea, RectangleEdge.BOTTOM);

            // draw the mean value
            g2.setColor(Color.RED);
            ypos = yaxis.valueToJava2D(mean[i], dataArea, RectangleEdge.LEFT);
            g2.drawLine((int) xpos - 2, (int) ypos, (int) xpos + 2, (int) ypos);

            // conect the dots
            if (prevx != -1 && prevy != -1) {
                g2.setColor(Color.BLACK);
                if (dashed)
                    g2.setStroke(stroke_dashed);
                g2.drawLine((int) prevx, (int) prevy, (int) xpos, (int) ypos);
                if (dashed) {
                    dashed = false;
                    g2.setStroke(stroke_solid);
                }

            }
            prevy = ypos;
            prevx = xpos;

            // draw the outer values
            g2.setColor(Color.LIGHT_GRAY);
            double ypos_min = yaxis.valueToJava2D(min[i], dataArea, RectangleEdge.LEFT);
            g2.drawLine((int) xpos - 2, (int) ypos_min, (int) xpos + 2, (int) ypos_min);
            double ypos_max = yaxis.valueToJava2D(max[i], dataArea, RectangleEdge.LEFT);
            g2.drawLine((int) xpos - 2, (int) ypos_max, (int) xpos + 2, (int) ypos_max);
            g2.drawLine((int) xpos, (int) ypos_min, (int) xpos, (int) ypos_max);
        }
    }

    // reset
    g2.setClip(originalclip);
}

From source file:org.tsho.dmc2.core.chart.AbstractDmcPlot.java

/**
 * Draws the fast scatter plot on a Java 2D graphics device (such as the screen or
 * a printer)./*ww w.  ja v a  2s  .c om*/
 *
 * @param g2  the graphics device.
 * @param plotArea   the area within which the plot (including axis labels) should be drawn.
 * @param info  collects chart drawing information (<code>null</code> permitted).
 */
public void draw(Graphics2D g2, Rectangle2D plotArea, PlotState parentState, PlotRenderingInfo info) {
    //        if (data == null)
    //            return;

    // set up info collection...
    if (info != null) {
        info.setPlotArea(plotArea);
    }

    // adjust the drawing area for plot insets (if any)...
    Insets insets = getInsets();
    if (insets != null) {
        plotArea.setRect(plotArea.getX() + insets.left, plotArea.getY() + insets.top,
                plotArea.getWidth() - insets.left - insets.right,
                plotArea.getHeight() - insets.top - insets.bottom);
    }

    AxisSpace space = new AxisSpace();
    space = this.domainAxis.reserveSpace(g2, this, plotArea, RectangleEdge.BOTTOM, space);
    space = this.rangeAxis.reserveSpace(g2, this, plotArea, RectangleEdge.LEFT, space);
    Rectangle2D dataArea = space.shrink(plotArea, null);

    if (info != null) {
        info.setDataArea(dataArea);
    }

    // draw the plot background and axes...
    drawBackground(g2, dataArea);

    /* if automatic bounds... */
    if (!isNoData()) {
        if (this instanceof DmcRenderablePlot) {
            DmcPlotRenderer renderer;
            renderer = ((DmcRenderablePlot) this).getPlotRenderer();
            if (renderer != null) {
                renderer.initialize();
                if (renderer.getState() == DmcPlotRenderer.STATE_STOPPED) {
                    return;
                }
            }
        }
    }

    AxisState domainAxisState = null, rangeAxisState = null;
    if (this.domainAxis != null) {
        double cursor;
        cursor = dataArea.getMaxY();
        domainAxisState = this.domainAxis.draw(g2, cursor, plotArea, dataArea, RectangleEdge.BOTTOM, info);
        // cursor = info.getCursor();
    }
    if (this.rangeAxis != null) {
        double cursor;
        cursor = dataArea.getMinX();
        rangeAxisState = this.rangeAxis.draw(g2, cursor, plotArea, dataArea, RectangleEdge.LEFT, info);
    }

    if (drawGridlines == true && domainAxisState != null && rangeAxisState != null) {
        drawGridlines(g2, dataArea, domainAxisState.getTicks(), rangeAxisState.getTicks());
    }

    Shape originalClip = g2.getClip();
    g2.clip(dataArea);

    //        Composite originalComposite = g2.getComposite();
    //        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
    //                                                   getForegroundAlpha()));
    //        g2.setStroke(new BasicStroke(12.0F));

    if (isNoData()) {
        drawNoDataMessage(g2, plotArea);
    } else {
        drawPlot(g2, dataArea, info);
    }

    g2.setClip(originalClip);
    drawOutline(g2, dataArea);
}

From source file:org.proteosuite.FastScatterPlot.java

/**
 * Draws the fast scatter plot on a Java 2D graphics device (such as the 
 * screen or a printer)./*  w  w  w .j av  a2s  .c o  m*/
 *
 * @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 chart drawing information (<code>null</code> 
 *              permitted).
 */
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 = new AxisSpace();
    space = this.domainAxis.reserveSpace(g2, this, area, RectangleEdge.BOTTOM, space);
    space = this.rangeAxis.reserveSpace(g2, this, area, RectangleEdge.LEFT, space);
    Rectangle2D dataArea = space.shrink(area, null);

    if (info != null) {
        info.setDataArea(dataArea);
    }

    // draw the plot background and axes...
    drawBackground(g2, dataArea);

    AxisState domainAxisState = null;
    AxisState rangeAxisState = null;
    if (this.domainAxis != null) {
        domainAxisState = this.domainAxis.draw(g2, dataArea.getMaxY(), area, dataArea, RectangleEdge.BOTTOM,
                info);
    }
    if (this.rangeAxis != null) {
        rangeAxisState = this.rangeAxis.draw(g2, dataArea.getMinX(), area, dataArea, RectangleEdge.LEFT, info);
    }
    drawDomainGridlines(g2, dataArea, domainAxisState.getTicks());
    drawRangeGridlines(g2, dataArea, rangeAxisState.getTicks());

    Shape originalClip = g2.getClip();
    Composite originalComposite = g2.getComposite();

    g2.clip(dataArea);
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));

    render(g2, dataArea, info, null);

    g2.setClip(originalClip);
    g2.setComposite(originalComposite);
    drawOutline(g2, dataArea);

}

From source file:net.sf.maltcms.chromaui.charts.FastHeatMapPlot.java

/**
 * Draws the fast scatter plot on a Java 2D graphics device (such as the
 * screen or a printer).//w  ww  .j  a  v a  2s .  com
 *
 * @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 (ignored).
 * @param info collects chart drawing information (<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();
    insets.trim(area);

    AxisSpace space = new AxisSpace();
    space = this.domainAxis.reserveSpace(g2, this, area, RectangleEdge.BOTTOM, space);
    space = this.rangeAxis.reserveSpace(g2, this, area, RectangleEdge.LEFT, space);
    Rectangle2D dataArea = space.shrink(area, null);

    if (info != null) {
        info.setDataArea(dataArea);
    }

    // draw the plot background and axes...
    drawBackground(g2, dataArea);

    AxisState domainAxisState = this.domainAxis.draw(g2, dataArea.getMaxY(), area, dataArea,
            RectangleEdge.BOTTOM, info);
    AxisState rangeAxisState = this.rangeAxis.draw(g2, dataArea.getMinX(), area, dataArea, RectangleEdge.LEFT,
            info);
    drawDomainGridlines(g2, dataArea, domainAxisState.getTicks());
    drawRangeGridlines(g2, dataArea, rangeAxisState.getTicks());

    Shape originalClip = g2.getClip();
    Composite originalComposite = g2.getComposite();

    g2.clip(dataArea);
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));
    render(g2, dataArea, info, null);

    g2.setClip(originalClip);
    g2.setComposite(originalComposite);
    drawOutline(g2, dataArea);

}

From source file:org.gumtree.vis.awt.JChartPanel.java

@Override
public void draw(Graphics2D g2, Rectangle2D area, double shiftX, double shiftY) {
    //       g2.setPaint(Color.white);
    //      g2.fill(new Rectangle2D.Double(0, 0, getWidth(), getHeight()));
    //      if (getChart() != null) {
    ////         Image chartImage = getChart().createBufferedImage((int) area.getWidth(),
    ////               (int) area.getHeight());
    ////         g2.drawImage(chartImage, (int) area.getMinX(), (int) area.getMinY(), 
    ////               this);
    //         getChart().draw(g2, area, getAnchor(), null);
    //         ChartMaskingUtilities.drawMasks(g2, getScreenDataArea(), maskList, 
    //               null, getChart());
    //      }//w  w  w . ja va 2s.  co  m
    double widthRatio = area.getWidth() / getWidth();
    double heightRatio = area.getHeight() / getHeight();
    double overallRatio = 1;
    overallRatio = widthRatio < heightRatio ? widthRatio : heightRatio;

    XYPlot plot = (XYPlot) getChart().getPlot();
    Font domainFont = plot.getDomainAxis().getLabelFont();
    int domainSize = domainFont.getSize();
    Font rangeFont = plot.getRangeAxis().getLabelFont();
    int rangeSize = rangeFont.getSize();
    TextTitle titleBlock = getChart().getTitle();
    Font titleFont = null;
    int titleSize = 0;
    if (titleBlock != null) {
        titleFont = titleBlock.getFont();
        titleSize = titleFont.getSize();
        getChart().getTitle().setFont(titleFont.deriveFont((float) (titleSize * overallRatio)));
    }
    Font domainScaleFont = plot.getDomainAxis().getTickLabelFont();
    int domainScaleSize = domainScaleFont.getSize();
    Font rangeScaleFont = plot.getRangeAxis().getTickLabelFont();
    int rangeScaleSize = rangeScaleFont.getSize();
    plot.getDomainAxis().setLabelFont(domainFont.deriveFont((float) (domainSize * overallRatio)));
    plot.getRangeAxis().setLabelFont(rangeFont.deriveFont((float) (rangeSize * overallRatio)));
    plot.getDomainAxis().setTickLabelFont(domainScaleFont.deriveFont((float) (domainScaleSize * overallRatio)));
    plot.getRangeAxis().setTickLabelFont(rangeScaleFont.deriveFont((float) (rangeScaleSize * overallRatio)));
    LegendTitle legend = getChart().getLegend();
    Font legendFont = null;
    int legendFontSize = 0;
    if (legend != null) {
        legendFont = legend.getItemFont();
        legendFontSize = legendFont.getSize();
        legend.setItemFont(legendFont.deriveFont((float) (legendFontSize * overallRatio)));
    }

    Rectangle2D chartArea = (Rectangle2D) area.clone();
    getChart().getPadding().trim(chartArea);
    if (titleBlock != null) {
        AxisUtilities.trimTitle(chartArea, g2, titleBlock, titleBlock.getPosition());
    }

    Axis scaleAxis = null;
    Font scaleAxisFont = null;
    int scaleAxisFontSize = 0;
    for (Object object : getChart().getSubtitles()) {
        Title title = (Title) object;
        if (title instanceof PaintScaleLegend) {
            scaleAxis = ((PaintScaleLegend) title).getAxis();
            scaleAxisFont = scaleAxis.getTickLabelFont();
            scaleAxisFontSize = scaleAxisFont.getSize();
            scaleAxis.setTickLabelFont(scaleAxisFont.deriveFont((float) (scaleAxisFontSize * overallRatio)));
        }
        AxisUtilities.trimTitle(chartArea, g2, title, title.getPosition());
    }
    AxisSpace axisSpace = AxisUtilities.calculateAxisSpace(getChart().getXYPlot(), g2, chartArea);
    Rectangle2D dataArea = axisSpace.shrink(chartArea, null);
    getChart().getXYPlot().getInsets().trim(dataArea);
    getChart().getXYPlot().getAxisOffset().trim(dataArea);

    //        Rectangle2D screenArea = getScreenDataArea();
    //        Rectangle2D visibleArea = getVisibleRect();
    //        Rectangle2D printScreenArea = new Rectangle2D.Double(screenArea.getMinX() * overallRatio + x, 
    //              screenArea.getMinY() * overallRatio + y, 
    //              printArea.getWidth() - visibleArea.getWidth() + screenArea.getWidth(), 
    //              printArea.getHeight() - visibleArea.getHeight() + screenArea.getHeight());

    getChart().draw(g2, area, getAnchor(), null);
    ChartMaskingUtilities.drawMasks(g2, dataArea, maskList, null, getChart(), overallRatio);
    ChartMaskingUtilities.drawShapes(g2, dataArea, shapeMap, getChart());
    ChartMaskingUtilities.drawText(g2, dataArea, textContentMap, getChart());
    plot.getDomainAxis().setLabelFont(domainFont);
    plot.getRangeAxis().setLabelFont(rangeFont);
    if (titleBlock != null) {
        titleBlock.setFont(titleFont);
    }
    if (legend != null) {
        legend.setItemFont(legendFont);
    }
    plot.getDomainAxis().setTickLabelFont(domainScaleFont);
    plot.getRangeAxis().setTickLabelFont(rangeScaleFont);
    if (scaleAxis != null) {
        scaleAxis.setTickLabelFont(scaleAxisFont);
    }
    //        System.out.println("print " + titleBlock.getText() + 
    //              " at [" + area.getX() + ", " + area.getY() + ", " + 
    //              area.getWidth() + ", " + area.getHeight() + "]");
}

From source file:ucar.unidata.idv.control.chart.MyXYPlot.java

/**
 * Draws the plot within the specified area on a graphics device.
 *
 * @param g2  the graphics device./*  w  w  w.  jav  a 2  s.co m*/
 * @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).
 */
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);

    if (info != null) {
        info.setDataArea(dataArea);
    }

    // draw the plot background and axes...
    drawBackground(g2, dataArea);
    Map axisStateMap = drawAxes(g2, area, dataArea, info);

    if ((anchor != null) && !dataArea.contains(anchor)) {
        anchor = null;
    }
    CrosshairState crosshairState = new CrosshairState();
    crosshairState.setCrosshairDistance(Double.POSITIVE_INFINITY);
    crosshairState.setAnchor(anchor);
    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());
        }
    }
    if (domainAxisState != null) {
        drawDomainTickBands(g2, dataArea, domainAxisState.getTicks());
        drawDomainGridlines(g2, dataArea, domainAxisState.getTicks());
    }

    AxisState rangeAxisState = (AxisState) axisStateMap.get(getRangeAxis());
    if (rangeAxisState == null) {
        if (parentState != null) {
            rangeAxisState = (AxisState) parentState.getSharedAxisStates().get(getRangeAxis());
        }
    }
    if (rangeAxisState != null) {
        drawRangeTickBands(g2, dataArea, rangeAxisState.getTicks());
        drawRangeGridlines(g2, dataArea, rangeAxisState.getTicks());
        drawZeroRangeBaseline(g2, dataArea);
    }

    // draw the markers that are associated with a specific renderer...
    for (int i = 0; i < this.renderers.size(); i++) {
        drawDomainMarkers(g2, dataArea, i, Layer.BACKGROUND);
    }
    for (int i = 0; i < this.renderers.size(); i++) {
        drawRangeMarkers(g2, dataArea, i, Layer.BACKGROUND);
    }

    // now draw annotations and render data items...
    boolean foundData = false;
    DatasetRenderingOrder order = getDatasetRenderingOrder();
    if (order == DatasetRenderingOrder.FORWARD) {

        // draw background annotations
        int rendererCount = this.renderers.size();
        for (int i = 0; i < rendererCount; i++) {
            XYItemRenderer r = getRenderer(i);
            if (r != null) {
                ValueAxis domainAxis = getDomainAxisForDataset(i);
                ValueAxis rangeAxis = getRangeAxisForDataset(i);
                r.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, Layer.BACKGROUND, info);
            }
        }

        // render data items...
        for (int i = 0; i < getDatasetCount(); i++) {
            foundData = render(g2, dataArea, i, info, crosshairState) || foundData;
        }

        // draw foreground annotations
        for (int i = 0; i < rendererCount; i++) {
            XYItemRenderer r = getRenderer(i);
            if (r != null) {
                ValueAxis domainAxis = getDomainAxisForDataset(i);
                ValueAxis rangeAxis = getRangeAxisForDataset(i);
                r.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, Layer.FOREGROUND, info);
            }
        }

    } else if (order == DatasetRenderingOrder.REVERSE) {

        // draw background annotations
        int rendererCount = this.renderers.size();
        for (int i = rendererCount - 1; i >= 0; i--) {
            XYItemRenderer r = getRenderer(i);
            if (r != null) {
                ValueAxis domainAxis = getDomainAxisForDataset(i);
                ValueAxis rangeAxis = getRangeAxisForDataset(i);
                r.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, Layer.BACKGROUND, info);
            }
        }

        ucar.unidata.util.Trace.call1("renderData");
        for (int i = getDatasetCount() - 1; i >= 0; i--) {
            foundData = render(g2, dataArea, i, info, crosshairState) || foundData;
        }
        ucar.unidata.util.Trace.call2("renderData");

        // draw foreground annotations
        for (int i = rendererCount - 1; i >= 0; i--) {
            XYItemRenderer r = getRenderer(i);
            if (r != null) {
                ValueAxis domainAxis = getDomainAxisForDataset(i);
                ValueAxis rangeAxis = getRangeAxisForDataset(i);
                r.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, Layer.FOREGROUND, info);
            }
        }

    }

    PlotOrientation orient = getOrientation();

    // draw domain crosshair if required...
    if (!this.domainCrosshairLockedOnData && (anchor != null)) {
        double xx = getDomainAxis().java2DToValue(anchor.getX(), dataArea, getDomainAxisEdge());
        crosshairState.setCrosshairX(xx);
    }
    setDomainCrosshairValue(crosshairState.getCrosshairX(), false);
    if (isDomainCrosshairVisible()) {
        double x = getDomainCrosshairValue();
        Paint paint = getDomainCrosshairPaint();
        Stroke stroke = getDomainCrosshairStroke();
        if (orient == PlotOrientation.HORIZONTAL) {
            drawHorizontalLine(g2, dataArea, x, stroke, paint);
        } else if (orient == PlotOrientation.VERTICAL) {
            drawVerticalLine(g2, dataArea, x, stroke, paint);
        }
    }

    // draw range crosshair if required...
    if (!this.rangeCrosshairLockedOnData && (anchor != null)) {
        double yy = getRangeAxis().java2DToValue(anchor.getY(), dataArea, getRangeAxisEdge());
        crosshairState.setCrosshairX(yy);
    }
    setRangeCrosshairValue(crosshairState.getCrosshairY(), false);
    if (isRangeCrosshairVisible() && getRangeAxis().getRange().contains(getRangeCrosshairValue())) {
        double y = getRangeCrosshairValue();
        Paint paint = getRangeCrosshairPaint();
        Stroke stroke = getRangeCrosshairStroke();
        if (orient == PlotOrientation.HORIZONTAL) {
            drawVerticalLine(g2, dataArea, y, stroke, paint);
        } else if (orient == PlotOrientation.VERTICAL) {
            drawHorizontalLine(g2, dataArea, y, stroke, paint);
        }
    }

    if (!foundData) {
        drawNoDataMessage(g2, dataArea);
    }

    for (int i = 0; i < this.renderers.size(); i++) {
        drawDomainMarkers(g2, dataArea, i, Layer.FOREGROUND);
    }
    for (int i = 0; i < this.renderers.size(); i++) {
        drawRangeMarkers(g2, dataArea, i, Layer.FOREGROUND);
    }

    drawAnnotations(g2, dataArea, info);
    g2.setClip(originalClip);
    g2.setComposite(originalComposite);

    drawOutline(g2, dataArea);

}

From source file:org.jfree.chart.plot.StackedXYPlot.java

/**
 * Draws the plot.// w w  w  .j ava2 s .co  m
 * @param graphics2d the graphics device.
 * @param plotArea the plot plotArea (in Java2D space).
 * @param anchor an anchor point in Java2D space (<code>null</code>
        permitted).
 * @param parentState the state from the parent plot
             (<code>null</code> permitted).
 * @param plotRenderingInfo chart drawing information (<code>null</code>
      permitted).
 */
@Override
public void draw(Graphics2D graphics2d, Rectangle2D plotArea, Point2D anchor, PlotState parentState,
        PlotRenderingInfo plotRenderingInfo) {

    if (plotRenderingInfo != null) {
        plotRenderingInfo.setPlotArea(plotArea);
    }

    RectangleInsets insets = getInsets();
    insets.trim(plotArea);

    setFixedRangeAxisSpaceForSubplots(null);
    //calculateAxisSpace will also calculate sub-plot plotArea
    AxisSpace space = calculateAxisSpace(graphics2d, plotArea);
    Rectangle2D dataArea = space.shrink(plotArea, null);
    Rectangle2D[] calculatedSubPlotAreas = null;
    //get subplotsAreas from parent class
    try {
        calculatedSubPlotAreas = (Rectangle2D[]) FieldUtils.readField(this, "subplotAreas", true);
    } catch (IllegalAccessException ex) {
        Logger.getLogger(StackedXYPlot.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
    }

    setFixedRangeAxisSpaceForSubplots(space);

    // draw all the subplots         
    for (int i = 0; i < getSubplots().size(); i++) {
        XYPlot plot = (XYPlot) getSubplots().get(i);
        PlotRenderingInfo subplotInfo = null;
        if (plotRenderingInfo != null) {
            subplotInfo = new PlotRenderingInfo(plotRenderingInfo.getOwner());
            plotRenderingInfo.addSubplotInfo(subplotInfo);
        }
        plot.draw(graphics2d, calculatedSubPlotAreas[i], anchor, parentState, subplotInfo);
    }

    if (plotRenderingInfo != null) {
        plotRenderingInfo.setDataArea(dataArea);
    }
}