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

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

Introduction

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

Prototype

public AxisSpace() 

Source Link

Document

Creates a new axis space record.

Usage

From source file:com.newatlanta.bluedragon.CategoryAxis.java

public AxisSpace reserveSpace(Graphics2D g2, Plot plot, Rectangle2D plotArea, RectangleEdge edge,
        AxisSpace space) {/*w  w  w  . j a  va 2 s.  c om*/

    // create a new space object if one wasn't supplied...
    if (space == null) {
        space = new AxisSpace();
    }

    // if the axis is not visible, no additional space is required...
    if (!isVisible()) {
        return space;
    }

    // calculate the max size of the tick labels (if visible)...
    double tickLabelHeight = 0.0;
    double tickLabelWidth = 0.0;
    if (isTickLabelsVisible()) {
        g2.setFont(getTickLabelFont());
        AxisState state = new AxisState();
        // we call refresh ticks just to get the maximum width or height
        if (RectangleEdge.isTopOrBottom(edge)) {
            // BEGIN fix for category labels that wrap
            // If space has been reserved to the left and right then we need to
            // reduce the plot area
            // by this amount so that the space needed by category labels that wrap
            // on to multiple lines
            // will be calculated properly.
            Rectangle2D newPlotArea = new Rectangle2D.Double(plotArea.getX(), plotArea.getY(),
                    plotArea.getWidth() - space.getLeft() - space.getRight(), plotArea.getHeight());
            refreshTicks(g2, state, newPlotArea, edge);
            // END fix for category labels that wrap
        } else {
            refreshTicks(g2, state, plotArea, edge);
        }
        if (edge == RectangleEdge.TOP) {
            tickLabelHeight = state.getMax();
        } else if (edge == RectangleEdge.BOTTOM) {
            tickLabelHeight = state.getMax();
        } else if (edge == RectangleEdge.LEFT) {
            tickLabelWidth = state.getMax();
        } else if (edge == RectangleEdge.RIGHT) {
            tickLabelWidth = state.getMax();
        }
    }

    // get the axis label size and update the space object...
    Rectangle2D labelEnclosure = getLabelEnclosure(g2, edge);
    double labelHeight = 0.0;
    double labelWidth = 0.0;
    if (RectangleEdge.isTopOrBottom(edge)) {
        labelHeight = labelEnclosure.getHeight();
        space.add(labelHeight + tickLabelHeight + this.getCategoryLabelPositionOffset(), edge);
    } else if (RectangleEdge.isLeftOrRight(edge)) {
        labelWidth = labelEnclosure.getWidth();
        space.add(labelWidth + tickLabelWidth + this.getCategoryLabelPositionOffset(), edge);
    }
    return space;

}

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 2  s  .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
    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.FastErrorBarPlot.java

@Override
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState,
        PlotRenderingInfo info) {/*from  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.jstockchart.plot.TimeseriesPlot.java

private CombinedDomainXYPlot createCombinedXYPlot() {
    Font axisFont = new Font("Arial", 0, 12);
    Stroke stroke = new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.CAP_SQUARE, 0.0f,
            new float[] { 1.0f, 1.0f }, 1.0f);
    LogicDateAxis logicDateAxis = timeseriesArea.getlogicDateAxis();
    TimeseriesDateAxis dateAxis = new TimeseriesDateAxis(logicDateAxis.getLogicTicks());
    if (timeline != null) {
        dateAxis.setTimeline(timeline);// w w w  . j  a v a  2 s  .  c  o m
    }
    dateAxis.setTickLabelFont(axisFont);
    dateAxis.setTickMarkStroke(stroke);
    List<String> hideTick = new ArrayList<String>();
    hideTick.add("10:00");
    hideTick.add("11:00");
    hideTick.add("13:30");
    //hideTick.add("14:30");
    hideTick.add("14:30");
    dateAxis.setHideTickLabel(hideTick);
    dateAxis.setTickMarkPosition(DateTickMarkPosition.START);
    dateAxis.setTickMarksVisible(false);
    Date startTime = DateUtils.createDate(2008, 1, 1, 9, 30, 0);
    Date endTime = DateUtils.createDate(2008, 1, 1, 15, 0, 0);
    dateAxis.setRange(timeseriesArea.getStartDate(), timeseriesArea.getEndDate());
    dateAxis.setAxisLineVisible(false);
    CFXCombinedPlot combinedDomainXYPlot = new CFXCombinedPlot(dateAxis);
    combinedDomainXYPlot.setInsets(new RectangleInsets(5, 2, 4, 2));

    AxisSpace axisSpace = new AxisSpace();
    axisSpace.setBottom(22);
    axisSpace.setLeft(0);
    axisSpace.setRight(0);
    axisSpace.setTop(0);
    combinedDomainXYPlot.setFixedDomainAxisSpace(axisSpace);
    combinedDomainXYPlot.setGap(0);
    combinedDomainXYPlot.setOrientation(timeseriesArea.getOrientation());
    combinedDomainXYPlot.setDomainAxis(dateAxis);
    combinedDomainXYPlot.setDomainAxisLocation(timeseriesArea.getDateAxisLocation());

    if (timeseriesArea.getPriceWeight() <= 0 && timeseriesArea.getVolumeWeight() <= 0) {
        throw new IllegalArgumentException("Illegal weight value: priceWeight="
                + timeseriesArea.getPriceWeight() + ", volumeWeight=" + timeseriesArea.getVolumeWeight());
    }

    if (timeseriesArea.getPriceWeight() > 0) {
        XYPlot pricePlot = createPricePlot();
        combinedDomainXYPlot.add(pricePlot, timeseriesArea.getPriceWeight());
    }

    if (timeseriesArea.getVolumeWeight() > 0) {
        XYPlot volumePlot = createVolumePlot();
        combinedDomainXYPlot.add(volumePlot, timeseriesArea.getVolumeWeight());
    }

    return combinedDomainXYPlot;
}

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

@Override
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState,
        PlotRenderingInfo info) {//from   w w  w . jav  a2 s . c  om
    // 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: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)./*from w  w w.j a  v a 2  s.  com*/
 *
 * @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).//from  w  w w .j  a v a2  s . 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:org.yardstickframework.report.jfreechart.JFreeChartGraphPlotter.java

/**
 * @param folderToWrite Folder to write the resulted charts.
 * @param plots Collections of plots.//  www.j  a  v  a  2s  .c  o  m
 * @param infoMap Map with additional plot info.
 * @param mode Generation mode.
 * @throws Exception If failed.
 */
private static void processPlots(File folderToWrite, Collection<List<PlotData>> plots,
        Map<String, List<JFreeChartPlotInfo>> infoMap, JFreeChartGenerationMode mode) throws Exception {
    ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);

    int idx = -1;

    while (true) {
        idx++;

        DefaultXYDataset dataSet = new DefaultXYDataset();

        List<JFreeChartPlotInfo> infoList = new ArrayList<>();

        String xAxisLabel = "";
        String yAxisLabel = "";
        String plotName = "";

        int cnt = 0;

        for (List<PlotData> plotData0 : plots) {
            if (plotData0.size() <= idx)
                continue;

            PlotData plotData = plotData0.get(idx);

            dataSet.addSeries(plotData.plotName() + "_" + cnt++, plotData.series().data);

            xAxisLabel = plotData.xAxisLabel;
            yAxisLabel = plotData.yAxisLabel;
            plotName = plotData.plotName();

            infoList.add(info(plotData.series(), mode));
        }

        if (infoList.isEmpty())
            break;

        JFreeChart chart = ChartFactory.createXYLineChart("", xAxisLabel, yAxisLabel, dataSet,
                PlotOrientation.VERTICAL, false, false, false);

        AxisSpace as = new AxisSpace();

        as.add(150, RectangleEdge.LEFT);

        XYPlot plot = (XYPlot) chart.getPlot();

        BasicStroke stroke = new BasicStroke(1);

        plot.setRenderer(renderer);
        plot.setBackgroundPaint(WHITE);
        plot.setRangeGridlinePaint(GRAY);
        plot.setDomainGridlinePaint(GRAY);
        plot.setFixedRangeAxisSpace(as);
        plot.setOutlineStroke(stroke);

        for (int i = 0; i < infoList.size(); i++) {
            Color color = PLOT_COLORS[i % PLOT_COLORS.length];

            renderer.setSeriesPaint(i, color);
            renderer.setSeriesStroke(i, new BasicStroke(3)); // Line thickness.

            infoList.get(i).color(Integer.toHexString(color.getRGB()).substring(2));
        }

        ValueAxis axis = plot.getRangeAxis();

        Font font = new Font("Helvetica,Arial,sans-serif", Font.BOLD, axis.getTickLabelFont().getSize() + 5);

        axis.setTickLabelFont(font);
        axis.setLabelFont(font);
        plot.getDomainAxis().setTickLabelFont(font);
        plot.getDomainAxis().setLabelFont(font);

        chart.setTitle(new TextTitle(yAxisLabel, new Font(font.getName(), font.getStyle(), 30)));

        File res = new File(folderToWrite, plotName + ".png");

        ChartUtilities.saveChartAsPNG(res, chart, 1000, 500, info);

        infoMap.put(res.getAbsolutePath(), infoList);

        println("Chart is saved to file: ", res);
    }
}

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)./*from  w  w w. ja va  2  s  .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 (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.ramadda.data.services.PointFormHandler.java

/**
 * _more_//from   w  ww . ja v a2  s .com
 *
 * @param request _more_
 * @param pointEntry _more_
 * @param plotInfo _more_
 *
 * @return _more_
 *
 * @throws Exception _more_
 */
public BufferedImage makeTimeseriesImage(Request request, PointEntry pointEntry, final PlotInfo plotInfo)
        throws Exception {

    Entry entry = pointEntry.getEntry();
    int width = TIMESERIES_WIDTH;
    int height = TIMESERIES_HEIGHT;
    long numRecords = pointEntry.getNumRecords();
    final int numPointsToPlot = request.get(ARG_NUMPOINTS, TIMESERIES_POINTS);
    final int[] cnt = { 0 };
    final List<TimeSeries> series = new ArrayList<TimeSeries>();

    final List<RecordField> tmpFields = pointEntry.getRecordFile().getChartableFields();

    final List<RecordField> fields = new ArrayList<RecordField>();

    if (request.get(ARG_CHART_SHOW + FIELD_ALTITUDE, false)) {
        fields.add(new RecordField(FIELD_ALTITUDE, LABEL_ALTITUDE, "", -1, UNIT_M));
    }

    for (RecordField attr : tmpFields) {
        if (request.get(ARG_CHART_SHOW + attr.getName(), false)) {
            fields.add(attr);
        }
    }

    if ((fields.size() == 0) && (tmpFields.size() > 0)) {
        fields.add(tmpFields.get(0));
        request.put(ARG_CHART_SHOW + tmpFields.get(0).getName(), "true");
    }

    for (RecordField attr : fields) {
        series.add(new TimeSeries(attr.getLabel()));
    }

    RecordVisitor visitor = new BridgeRecordVisitor(getOutputHandler()) {
        public boolean doVisitRecord(RecordFile file, VisitInfo visitInfo, Record record) {
            PointRecord pointRecord = (PointRecord) record;
            for (int fieldCnt = 0; fieldCnt < fields.size(); fieldCnt++) {
                RecordField field = fields.get(fieldCnt);
                double value;
                //Check for altitude
                if (field.getParamId() < 0) {
                    value = pointRecord.getAltitude();
                } else {
                    value = record.getValue(field.getParamId());
                }
                long time = record.getRecordTime();
                series.get(fieldCnt).add(new FixedMillisecond(time), value);
            }
            plotInfo.setIndex(pointRecord.index);
            cnt[0]++;

            return true;
        }
    };

    long t1 = System.currentTimeMillis();
    int skip = (int) (numRecords / numPointsToPlot);
    getRecordJobManager().visitSequential(request, pointEntry, visitor, new VisitInfo(skip));
    long t2 = System.currentTimeMillis();

    JFreeChart chart = createTimeseriesChart(request, entry, new TimeSeriesCollection(), null);
    long t3 = System.currentTimeMillis();
    XYPlot plot = (XYPlot) chart.getPlot();
    int lineCnt = 0;
    int[] colorCnt = { 0 };
    int numberOfAxisLegends = 0;

    Hashtable<String, double[]> valueRanges = new Hashtable<String, double[]>();

    for (int extraCnt = 0; extraCnt < series.size(); extraCnt++) {
        TimeSeries timeSeries = series.get(extraCnt);
        RecordField field = fields.get(extraCnt);
        String unit = field.getUnit();
        if ((unit != null) && (unit.length() == 0)) {
            unit = null;
        }

        if (unit == null) {
            unit = extraCnt + "";
        }
        if (unit == null) {
            continue;
        }
        double max = timeSeries.getMaxY();
        double min = timeSeries.getMinY();
        double[] range = valueRanges.get(unit);
        if (range == null) {
            range = new double[] { min, max };
            valueRanges.put(unit, range);
        } else {
            range[0] = Math.min(range[0], min);
            range[1] = Math.max(range[1], max);
        }
    }

    Hashtable<String, NumberAxis> seenAxis = new Hashtable<String, NumberAxis>();
    for (int extraCnt = 0; extraCnt < series.size(); extraCnt++) {
        TimeSeries timeSeries = series.get(extraCnt);
        RecordField field = fields.get(extraCnt);

        String unit = field.getUnit();
        if ((unit != null) && (unit.length() == 0)) {
            unit = null;
        }

        TimeSeriesCollection dataset2 = new TimeSeriesCollection();
        dataset2.addSeries(timeSeries);
        NumberAxis axis = new NumberAxis(field.getLabel());
        numberOfAxisLegends++;
        if (unit != null) {
            double[] range = valueRanges.get(unit);
            axis.setRange(range[0], range[1]);
            NumberAxis seenOne = seenAxis.get(unit);
            if (seenOne == null) {
                seenAxis.put(unit, axis);
            } else {
                seenOne.setLabel(seenOne.getLabel() + "/" + field.getLabel());
                axis.setVisible(false);
                numberOfAxisLegends--;
            }
        } else {
            axis.setAutoRange(true);
            axis.setAutoRangeIncludesZero(true);
        }

        plot.setRangeAxis(lineCnt, axis);
        plot.setDataset(lineCnt, dataset2);
        plot.mapDatasetToRangeAxis(lineCnt, lineCnt);
        plot.setRangeAxisLocation(lineCnt, AxisLocation.BOTTOM_OR_RIGHT);

        StandardXYItemRenderer renderer = new MyStandardXYItemRenderer(plotInfo);
        renderer.setSeriesPaint(0, getColor(request, ARG_CHART_COLOR + field.getName(), colorCnt));
        plot.setRenderer(lineCnt, renderer);
        lineCnt++;
    }

    AxisSpace axisSpace = new AxisSpace();
    axisSpace.setRight(TIMESERIES_AXIS_WIDTHPER * numberOfAxisLegends);
    plot.setFixedRangeAxisSpace(axisSpace);

    long t4 = System.currentTimeMillis();
    BufferedImage newImage = chart.createBufferedImage(width + (numberOfAxisLegends * TIMESERIES_AXIS_WIDTHPER),
            height);

    long t5 = System.currentTimeMillis();

    //        System.err.println("Time series  cnt:" + cnt[0] + " " + (t2 - t1) + " "  + (t3 - t2) + " " + (t4 - t3) + " " + (t5 - t4));
    return newImage;
}