Search in sources :

Example 21 with IntervalXYDataset

use of org.jfree.data.xy.IntervalXYDataset in project SIMVA-SoS by SESoS.

the class DeviationRenderer method drawItem.

/**
 * Draws the visual representation of a single data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the area within which the data is being drawn.
 * @param info  collects information about the drawing.
 * @param plot  the plot (can be used to obtain standard color
 *              information etc).
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param crosshairState  crosshair information for the plot
 *                        (<code>null</code> permitted).
 * @param pass  the pass index.
 */
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) {
    // do nothing if item is not visible
    if (!getItemVisible(series, item)) {
        return;
    }
    // first pass draws the shading
    if (pass == 0) {
        IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset;
        State drState = (State) state;
        double x = intervalDataset.getXValue(series, item);
        double yLow = intervalDataset.getStartYValue(series, item);
        double yHigh = intervalDataset.getEndYValue(series, item);
        RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
        RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
        double xx = domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
        double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, yAxisLocation);
        double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, yAxisLocation);
        PlotOrientation orientation = plot.getOrientation();
        if (orientation == PlotOrientation.HORIZONTAL) {
            drState.lowerCoordinates.add(new double[] { yyLow, xx });
            drState.upperCoordinates.add(new double[] { yyHigh, xx });
        } else if (orientation == PlotOrientation.VERTICAL) {
            drState.lowerCoordinates.add(new double[] { xx, yyLow });
            drState.upperCoordinates.add(new double[] { xx, yyHigh });
        }
        if (item == (dataset.getItemCount(series) - 1)) {
            // last item in series, draw the lot...
            // set up the alpha-transparency...
            Composite originalComposite = g2.getComposite();
            g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, this.alpha));
            g2.setPaint(getItemFillPaint(series, item));
            GeneralPath area = new GeneralPath(GeneralPath.WIND_NON_ZERO, drState.lowerCoordinates.size() + drState.upperCoordinates.size());
            double[] coords = (double[]) drState.lowerCoordinates.get(0);
            area.moveTo((float) coords[0], (float) coords[1]);
            for (int i = 1; i < drState.lowerCoordinates.size(); i++) {
                coords = (double[]) drState.lowerCoordinates.get(i);
                area.lineTo((float) coords[0], (float) coords[1]);
            }
            int count = drState.upperCoordinates.size();
            coords = (double[]) drState.upperCoordinates.get(count - 1);
            area.lineTo((float) coords[0], (float) coords[1]);
            for (int i = count - 2; i >= 0; i--) {
                coords = (double[]) drState.upperCoordinates.get(i);
                area.lineTo((float) coords[0], (float) coords[1]);
            }
            area.closePath();
            g2.fill(area);
            g2.setComposite(originalComposite);
            drState.lowerCoordinates.clear();
            drState.upperCoordinates.clear();
        }
    }
    if (isLinePass(pass)) {
        // all done by code in the super class
        if (item == 0) {
            State s = (State) state;
            s.seriesPath.reset();
            s.setLastPointGood(false);
        }
        if (getItemLineVisible(series, item)) {
            drawPrimaryLineAsPath(state, g2, plot, dataset, pass, series, item, domainAxis, rangeAxis, dataArea);
        }
    } else // second pass adds shapes where the items are ..
    if (isItemPass(pass)) {
        // setup for collecting optional entity info...
        EntityCollection entities = null;
        if (info != null) {
            entities = info.getOwner().getEntityCollection();
        }
        drawSecondaryPass(g2, plot, dataset, pass, series, item, domainAxis, dataArea, rangeAxis, crosshairState, entities);
    }
}
Also used : PlotOrientation(org.jfree.chart.plot.PlotOrientation) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) GeneralPath(java.awt.geom.GeneralPath) EntityCollection(org.jfree.chart.entity.EntityCollection) CrosshairState(org.jfree.chart.plot.CrosshairState) IntervalXYDataset(org.jfree.data.xy.IntervalXYDataset) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 22 with IntervalXYDataset

use of org.jfree.data.xy.IntervalXYDataset in project SIMVA-SoS by SESoS.

the class XYPlotTest method testSerialization2.

/**
 * Serialize an instance, restore it, and check for equality.  This test
 * uses a {@link DateAxis} and a {@link StandardXYToolTipGenerator}.
 */
@Test
public void testSerialization2() {
    IntervalXYDataset data1 = createDataset1();
    XYItemRenderer renderer1 = new XYBarRenderer(0.20);
    renderer1.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    XYPlot p1 = new XYPlot(data1, new DateAxis("Date"), null, renderer1);
    XYPlot p2 = (XYPlot) TestUtilities.serialised(p1);
    assertEquals(p1, p2);
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) IntervalXYDataset(org.jfree.data.xy.IntervalXYDataset) DefaultXYItemRenderer(org.jfree.chart.renderer.xy.DefaultXYItemRenderer) StandardXYItemRenderer(org.jfree.chart.renderer.xy.StandardXYItemRenderer) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) XYBarRenderer(org.jfree.chart.renderer.xy.XYBarRenderer) Test(org.junit.Test)

Aggregations

IntervalXYDataset (org.jfree.data.xy.IntervalXYDataset)22 PlotOrientation (org.jfree.chart.plot.PlotOrientation)7 RectangleEdge (org.jfree.ui.RectangleEdge)7 EntityCollection (org.jfree.chart.entity.EntityCollection)6 OHLCDataset (org.jfree.data.xy.OHLCDataset)5 Rectangle2D (java.awt.geom.Rectangle2D)4 Range (org.jfree.data.Range)4 Paint (java.awt.Paint)3 Line2D (java.awt.geom.Line2D)3 XYItemLabelGenerator (org.jfree.chart.labels.XYItemLabelGenerator)3 AlphaComposite (java.awt.AlphaComposite)2 Composite (java.awt.Composite)2 Stroke (java.awt.Stroke)2 Iterator (java.util.Iterator)2 JFreeChart (org.jfree.chart.JFreeChart)2 DateAxis (org.jfree.chart.axis.DateAxis)2 XYPlot (org.jfree.chart.plot.XYPlot)2 XYBarRenderer (org.jfree.chart.renderer.xy.XYBarRenderer)2 XYItemRenderer (org.jfree.chart.renderer.xy.XYItemRenderer)2 DomainInfo (org.jfree.data.DomainInfo)2