Example usage for org.jfree.data.xy XYZDataset getXValue

List of usage examples for org.jfree.data.xy XYZDataset getXValue

Introduction

In this page you can find the example usage for org.jfree.data.xy XYZDataset getXValue.

Prototype

public double getXValue(int series, int item);

Source Link

Document

Returns the x-value for an item within a series.

Usage

From source file:ch.zhaw.ias.dito.ui.util.BlockPlotPanel.java

public BlockPlotPanel(Matrix m, double lowerBound, double upperBound) {
    super(new BorderLayout());
    NumberAxis xAxis = new NumberAxis();
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    xAxis.setLowerMargin(1.0);/* ww  w.j  a  va2s . c  o m*/
    xAxis.setUpperMargin(0.0);
    NumberAxis yAxis = new NumberAxis();
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    yAxis.setLowerMargin(1.0);
    yAxis.setUpperMargin(0.0);
    XYBlockRenderer renderer = new XYBlockRenderer();
    renderer.setBaseToolTipGenerator(new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset dataset, int series, int item) {
            XYZDataset xyzDataset = (XYZDataset) dataset;
            double x = xyzDataset.getXValue(series, item);
            double y = xyzDataset.getYValue(series, item);
            double z = xyzDataset.getZValue(series, item);
            return ("X=" + x + ", Y=" + y + ", Z=" + z);
        }
    });
    PaintScale scale = new ColorPaintScale(lowerBound, upperBound);
    renderer.setPaintScale(scale);
    ValueAxis axis = new NumberAxis();
    axis.setLowerBound(scale.getLowerBound());
    axis.setUpperBound(scale.getUpperBound());
    PaintScaleLegend legend = new PaintScaleLegend(scale, axis);
    legend.setMargin(new RectangleInsets(10, 10, 10, 10));
    legend.setPosition(RectangleEdge.RIGHT);

    MatrixXYDataset dataset = new MatrixXYDataset(m);
    plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    chart = new JFreeChart(plot);
    chart.removeLegend();
    chart.addSubtitle(legend);
    chart.setBackgroundPaint(Color.white);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setDisplayToolTips(true);
    this.add(chartPanel, BorderLayout.CENTER);
}

From source file:net.sf.dynamicreports.test.jasper.AbstractJasperChartTest.java

protected void xyzChartDataTest(JFreeChart chart, int series, String seriesName, Number[][] values) {
    XYZDataset dataset = (XYZDataset) chart.getXYPlot().getDataset();
    int index = 0;
    for (Number[] numbers : values) {
        Assert.assertEquals("chart data series name", seriesName, dataset.getSeriesKey(series));
        Assert.assertEquals("chart data x", numbers[0], dataset.getXValue(series, index));
        Assert.assertEquals("chart data y", numbers[1], dataset.getYValue(series, index));
        Assert.assertEquals("chart data z", numbers[2], dataset.getZValue(series, index));
        index++;//www. j  a  va  2s.  com
    }
}

From source file:net.sf.maltcms.chromaui.charts.events.TICChartHandler.java

/**
 *
 * @param v//  w ww.jav a  2  s.c  o m
 */

@Override
public void listen(final IEvent<XYItemEntity> v) {
    if (!(v.get().getDataset() instanceof XYZDataset)) {
        Logger.getLogger(getClass().getName()).warning("Can not handle instances other than XYZDataset!");
        return;
    }
    final ValueAxis domainAxis = xypl.getDomainAxis();
    //System.out.println("Received event");
    //           Runnable r = new Runnable() {
    //            
    //            @Override
    //            public void run() {
    //               xypl.setNoDataMessage("Loading...");
    //               xypl.setDataset(null);
    //            }
    //           };
    //           
    //           SwingUtilities.invokeLater(r);
    //           
    Runnable s = new Runnable() {

        @Override
        public void run() {
            long start = System.currentTimeMillis();
            //System.out.println("Running update of TICChartHandler");
            XYItemEntity e = v.get();
            if (e.getDataset() instanceof XYZDataset) {
                final XYZDataset xyz = (XYZDataset) e.getDataset();
                final int seriesIndex = e.getSeriesIndex();
                final int y = (int) xyz.getYValue(seriesIndex, e.getItem());
                final int x = (int) xyz.getXValue(seriesIndex, e.getItem());
                XYDataset xydss;
                if (ticCache.containsKey(y)) {
                    xydss = ticCache.get(y);
                } else {
                    final DefaultXYDataset xyds = new DefaultXYDataset();
                    double[][] d = new double[2][scanlines];
                    Index idx = data.getIndex();
                    //columns, y
                    for (int j = 0; j < scanlines; j++) {
                        idx.set(scansPerMod * j + y);
                        d[0][j] = j;
                        d[1][j] = data.getDouble(idx);
                    }
                    xyds.addSeries("TIC@[" + y + "]", d);
                    xydss = xyds;
                    ticCache.put(y, xyds);
                }
                final XYDataset fds = xydss;
                Runnable runnable = new Runnable() {

                    @Override
                    public void run() {
                        xypl.setDataset(fds);
                        xypl.getRenderer().setBaseItemLabelsVisible(true);
                        xypl.getRenderer().setBasePaint(Color.GRAY);
                        xypl.getRenderer().setBaseOutlinePaint(Color.DARK_GRAY);
                        xypl.setDomainCrosshairLockedOnData(true);
                        xypl.setDomainCrosshairValue(x, true);
                        if (valueAxisFixed) {
                            xypl.getRangeAxis().setAutoRange(false);
                            xypl.getRangeAxis().setLowerBound(valueAxisMin);
                            xypl.getRangeAxis().setUpperBound(valueAxisMax);
                        } else {
                            xypl.getRangeAxis().setAutoRange(true);
                        }

                    }
                };
                SwingUtilities.invokeLater(runnable);
                //               }else{
                //                  System.err.println("Can only handle XYZDatasets!");
                //               }
                //System.out.println("Set TIC data in "+(System.currentTimeMillis()-start));
            }
        }
    };
    es.submit(s);
}

From source file:org.talend.dataprofiler.chart.util.TopChartFactory.java

/**
 * Creates a bubble chart with default settings. The chart is composed of an {@link XYPlot}, with a {@link NumberAxis} for the
 * domain axis, a {@link NumberAxis} for the range axis, and an {@link XYBubbleRenderer} to draw the data items.
 * //from w w  w  .ja  v  a 2  s . c  o m
 * This method is copied from
 * {@link org.jfree.chart.ChartFactory#createBubbleChart(String, String, String, XYZDataset, PlotOrientation, boolean, boolean, boolean)}
 * 
 * @param title the chart title (<code>null</code> permitted).
 * @param xAxisLabel a label for the X-axis (<code>null</code> permitted).
 * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted).
 * @param dataset the dataset for the chart (<code>null</code> permitted).
 * @param orientation the orientation (horizontal or vertical) (<code>null</code> NOT permitted).
 * @param legend a flag specifying whether or not a legend is required.
 * @param tooltips configure chart to generate tool tips?
 * @param urls configure chart to generate URLs?
 * 
 * @return A bubble chart.
 */
public static JFreeChart createBubbleChart(String title, String xAxisLabel, String yAxisLabel,
        XYZDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) {

    if (orientation == null) {
        throw new IllegalArgumentException(Messages.getString("TopChartFactory.argument")); //$NON-NLS-1$
    }
    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    yAxis.setAutoRangeIncludesZero(false);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);

    XYItemRenderer renderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS) {

        @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) {

            // return straight away if the item is not visible
            if (!getItemVisible(series, item)) {
                return;
            }

            PlotOrientation orientation = plot.getOrientation();

            // get the data point...
            double x = dataset.getXValue(series, item);
            double y = dataset.getYValue(series, item);
            double z = Double.NaN;
            if (dataset instanceof XYZDataset) {
                XYZDataset xyzData = (XYZDataset) dataset;
                z = xyzData.getZValue(series, item);
            }
            if (!Double.isNaN(z)) {
                RectangleEdge domainAxisLocation = plot.getDomainAxisEdge();
                RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
                double transX = domainAxis.valueToJava2D(x, dataArea, domainAxisLocation);
                double transY = rangeAxis.valueToJava2D(y, dataArea, rangeAxisLocation);

                double transDomain = 0.0;
                double transRange = 0.0;
                double zero;

                // MOD scorreia +2L avoid points: minimal size of circle must be 1
                // z = z * transX + 1;

                // ADD xqliu 2009-07-06 bug 8035
                double zSize = getBubbleSize(z); // calculate the multiple of bubble's default size
                z = 0; // use bubble's default size
                // ~

                switch (getScaleType()) {
                case SCALE_ON_DOMAIN_AXIS:
                    zero = domainAxis.valueToJava2D(0.0, dataArea, domainAxisLocation);
                    transDomain = domainAxis.valueToJava2D(z, dataArea, domainAxisLocation) - zero;
                    transRange = transDomain;
                    break;
                case SCALE_ON_RANGE_AXIS:
                    zero = rangeAxis.valueToJava2D(0.0, dataArea, rangeAxisLocation);
                    transRange = zero - rangeAxis.valueToJava2D(z, dataArea, rangeAxisLocation);
                    transDomain = transRange;
                    break;
                default:
                    double zero1 = domainAxis.valueToJava2D(0.0, dataArea, domainAxisLocation);
                    double zero2 = rangeAxis.valueToJava2D(0.0, dataArea, rangeAxisLocation);
                    transDomain = domainAxis.valueToJava2D(z, dataArea, domainAxisLocation) - zero1;
                    transRange = zero2 - rangeAxis.valueToJava2D(z, dataArea, rangeAxisLocation);
                }
                transDomain = Math.abs(transDomain);
                transRange = Math.abs(transRange);

                // MODSCA 2008-11-27 enlarge ellipse by diag% of the total diagonal
                double diag = Math.sqrt(dataArea.getHeight() * dataArea.getHeight()
                        + dataArea.getWidth() * dataArea.getWidth());
                transDomain += diag / 100;
                transRange += diag / 100;

                Ellipse2D circle = null;

                // ADD xqliu 2009-07-06 bug 8035
                transDomain *= zSize;
                transRange *= zSize;
                // ~

                if (orientation == PlotOrientation.VERTICAL) {
                    circle = new Ellipse2D.Double(transX - transDomain / 2.0, transY - transRange / 2.0,
                            transDomain, transRange);
                } else if (orientation == PlotOrientation.HORIZONTAL) {
                    circle = new Ellipse2D.Double(transY - transRange / 2.0, transX - transDomain / 2.0,
                            transRange, transDomain);
                }
                g2.setPaint(getItemPaint(series, item));
                g2.fill(circle);
                g2.setStroke(getItemOutlineStroke(series, item));
                g2.setPaint(getItemOutlinePaint(series, item));
                g2.draw(circle);

                if (isItemLabelVisible(series, item)) {
                    if (orientation == PlotOrientation.VERTICAL) {
                        drawItemLabel(g2, orientation, dataset, series, item, transX, transY, false);
                    } else if (orientation == PlotOrientation.HORIZONTAL) {
                        drawItemLabel(g2, orientation, dataset, series, item, transY, transX, false);
                    }
                }

                // add an entity if this info is being collected
                EntityCollection entities = null;
                if (info != null) {
                    entities = info.getOwner().getEntityCollection();
                    if (entities != null && circle.intersects(dataArea)) {
                        addEntity(entities, circle, dataset, series, item, circle.getCenterX(),
                                circle.getCenterY());
                    }
                }

                int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
                int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
                updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY,
                        orientation);
            }

        }

        /**
         * DOC xqliu : calculate the size of bubble. for bug 8035 2009-07-06.
         * 
         * @param z multiple of bubble's default size
         * @return
         */
        private double getBubbleSize(double z) {
            if (z > 0 && z <= 10) {
                return 2;
            } else if (z > 10 && z <= 100) {
                return 3;
            } else if (z > 100) {
                return 4;
            }
            return 1;
        }

    };
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator());
    }
    if (urls) {
        renderer.setURLGenerator(new StandardXYZURLGenerator());
    }
    plot.setRenderer(renderer);
    plot.setOrientation(orientation);

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

    return chart;

}

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

/**
 *
 * @param dataset//from www .  j  a  va  2 s .c  om
 * @param tooltipGenerator
 * @param minRange
 * @param maxRange
 * @param useRT
 * @return
 */
public XYPlot provide1DCoPlot(XYZDataset dataset, SelectionAwareXYTooltipGenerator tooltipGenerator,
        double minRange, double maxRange, boolean useRT) {
    XYBlockRenderer xyb = new XYBlockRenderer();
    GradientPaintScale ps = new GradientPaintScale(ImageTools.createSampleTable(256), minRange, maxRange,
            ImageTools.rampToColorArray(new ColorRampReader().readColorRamp("res/colorRamps/bcgyr.csv")));

    xyb.setPaintScale(ps);
    final String[] colnames = new String[dataset.getSeriesCount()];
    for (int i = 0; i < dataset.getSeriesCount(); i++) {
        colnames[i] = "" + dataset.getSeriesKey(i);//StringTools.removeFileExt(fragments.get(i).getName());
    }
    NumberAxis na = null;
    if (useRT) {
        na = new NumberAxis("time [s]");
        na.setAutoRangeIncludesZero(false);
        na.setLowerMargin(0);
        na.setUpperMargin(0);
    } else {
        na = new NumberAxis("scan index");
    }
    // na.setVerticalTickLabels(true);
    XYPlot xyp = new XYPlot(dataset, na, new SymbolAxis("chromatogram", colnames), xyb);
    //xyb.setBlockWidth(1);
    xyp.setBackgroundPaint(ps.getPaint(ps.getLowerBound()));
    tooltipGenerator.setXYToolTipGenerator(new XYZToolTipGenerator() {
        @Override
        public String generateToolTip(XYZDataset xyzd, int i, int i1) {
            return colnames[xyzd.getY(i, i1).intValue()] + " @" + xyzd.getXValue(i, i1) + " = "
                    + xyzd.getZValue(i, i1);
        }

        @Override
        public String generateToolTip(XYDataset xyd, int i, int i1) {
            if (xyd instanceof XYZDataset) {
                return generateToolTip((XYZDataset) xyd, i, i1);
            }
            return colnames[xyd.getY(i, i1).intValue()] + ":" + xyd.getXValue(i, i1);
        }
    });
    xyb.setBaseToolTipGenerator(tooltipGenerator);
    return xyp;
}

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

/**
 *
 * @param fragments/*from  w  w w. jav a  2 s .com*/
 * @param ticvar
 * @param useRT
 * @return
 */
public XYPlot provide1DCoPlot(List<IFileFragment> fragments, String ticvar, boolean useRT) {

    final String satVar = "scan_acquisition_time";

    DefaultXYZDataset cd = new DefaultXYZDataset();
    int rowIdx = 0;
    double min = 0;
    double max = 1;
    double minRT = Double.POSITIVE_INFINITY;
    double maxRT = Double.NEGATIVE_INFINITY;

    int y = 0;
    for (IFileFragment f : fragments) {

        double[] domainValues = null;
        if (useRT) {
            domainValues = (double[]) f.getChild(satVar).getArray().get1DJavaArray(double.class);
        } else {
            domainValues = (double[]) f.getChild("scan_index").getArray().get1DJavaArray(double.class);
        }

        double[] tic = (double[]) f.getChild(ticvar).getArray().get1DJavaArray(double.class);
        double maxtic = MathTools.max(tic);
        double mintic = MathTools.min(tic);
        double[][] values = new double[3][tic.length];
        for (int i = 0; i < tic.length; i++) {
            values[0][i] = domainValues[i];
            values[1][i] = y;
            values[2][i] = Math.sqrt((tic[i] - mintic) / (maxtic - mintic));
        }

        y++;
        cd.addSeries(f.getName(), values);
    }

    // ArrayDouble.D1 a = new ArrayDouble.D1(npoints);
    // int offset = 0;
    // for (IFileFragment f : t) {
    // Array tic = f.getChild(ticvar).getArray();
    // int len = tic.getShape()[0];
    // Array.arraycopy(tic, 0, a, offset, len);
    // offset += len;
    // }
    // histogram with fixed binsize
    // fill intensities into adequate bin, raise count in bin by one
    // afterwards, relative frequency within a bin gives a normalization
    // coefficient
    XYBlockRenderer xyb = new XYBlockRenderer();
    GradientPaintScale ps = new GradientPaintScale(ImageTools.createSampleTable(256), min, max,
            ImageTools.rampToColorArray(new ColorRampReader().readColorRamp("res/colorRamps/bcgyr.csv")));

    xyb.setPaintScale(ps);
    final String[] colnames = new String[fragments.size()];
    for (int i = 0; i < colnames.length; i++) {
        colnames[i] = StringTools.removeFileExt(fragments.get(i).getName());
    }
    NumberAxis na = null;
    if (useRT) {
        na = new NumberAxis("time [s]");
        na.setAutoRangeIncludesZero(false);
        na.setLowerMargin(0);
        na.setUpperMargin(0);
    } else {
        na = new NumberAxis("scan index");
    }
    // na.setVerticalTickLabels(true);
    XYPlot xyp = new XYPlot(cd, na, new SymbolAxis("chromatogram", colnames), xyb);
    xyb.setBlockWidth(1);
    xyp.setBackgroundPaint(Color.BLACK);
    xyb.setBaseToolTipGenerator(new XYZToolTipGenerator() {
        @Override
        public String generateToolTip(XYZDataset xyzd, int i, int i1) {
            return colnames[xyzd.getY(i, i1).intValue()] + " @" + xyzd.getXValue(i, i1) + " = "
                    + xyzd.getZValue(i, i1);
        }

        @Override
        public String generateToolTip(XYDataset xyd, int i, int i1) {
            if (xyd instanceof XYZDataset) {
                return generateToolTip((XYZDataset) xyd, i, i1);
            }
            return colnames[xyd.getY(i, i1).intValue()] + ":" + xyd.getXValue(i, i1);
        }
    });
    return xyp;
}

From source file:org.gumtree.vis.hist2d.Hist2DPanel.java

private boolean updateCurrentMaskRectangle(XYItemEntity startEntity, XYItemEntity endEntity) {
    if (currentMaskRectangle != null) {
        if (startEntity != null && endEntity != null) {
            IDataset startDataset = (IDataset) startEntity.getDataset();
            IDataset endDataset = (IDataset) endEntity.getDataset();
            if (startDataset instanceof XYZDataset && endDataset instanceof XYZDataset) {
                XYZDataset start = (XYZDataset) startDataset;
                XYZDataset end = (XYZDataset) endDataset;
                double xStart = start.getXValue(0, startEntity.getItem());
                double yStart = start.getYValue(0, startEntity.getItem());
                double xEnd = end.getXValue(0, endEntity.getItem());
                double yEnd = end.getYValue(0, endEntity.getItem());
                currentMaskRectangle.setRectangleFrame(new Rectangle2D.Double(Math.min(xStart, xEnd),
                        Math.min(yStart, yEnd), Math.abs(xStart - xEnd), Math.abs(yStart - yEnd)));
                //                System.out.println("[" + xStart + ", " + yStart + ", " + xEnd + ", " + yEnd);
                fireMaskUpdateEvent(currentMaskRectangle);
                return true;
            }/*from w  w w .  j  a va2s .  c o  m*/
        }
    }
    return false;
}

From source file:org.jfree.data.general.DatasetUtils.java

/**
 * Returns the range of z-values in the specified dataset for the
 * data items belonging to the visible series and with x-values in the
 * given range./* ww  w  . j a va 2  s.c  o  m*/
 *
 * @param dataset  the dataset ({@code null} not permitted).
 * @param visibleSeriesKeys  the visible series keys ({@code null} not
 *     permitted).
 * @param xRange  the x-range ({@code null} not permitted).
 * @param includeInterval  a flag that determines whether or not the
 *     z-interval for the dataset is included (this only applies if the
 *     dataset has an interval, which is currently not supported).
 *
 * @return The y-range (possibly {@code null}).
 */
public static Range iterateToFindZBounds(XYZDataset dataset, List visibleSeriesKeys, Range xRange,
        boolean includeInterval) {
    Args.nullNotPermitted(dataset, "dataset");
    Args.nullNotPermitted(visibleSeriesKeys, "visibleSeriesKeys");
    Args.nullNotPermitted(xRange, "xRange");

    double minimum = Double.POSITIVE_INFINITY;
    double maximum = Double.NEGATIVE_INFINITY;

    Iterator iterator = visibleSeriesKeys.iterator();
    while (iterator.hasNext()) {
        Comparable seriesKey = (Comparable) iterator.next();
        int series = dataset.indexOf(seriesKey);
        int itemCount = dataset.getItemCount(series);
        for (int item = 0; item < itemCount; item++) {
            double x = dataset.getXValue(series, item);
            double z = dataset.getZValue(series, item);
            if (xRange.contains(x)) {
                if (!Double.isNaN(z)) {
                    minimum = Math.min(minimum, z);
                    maximum = Math.max(maximum, z);
                }
            }
        }
    }

    if (minimum == Double.POSITIVE_INFINITY) {
        return null;
    } else {
        return new Range(minimum, maximum);
    }
}

From source file:org.jfree.data.general.DatasetUtilities.java

/**
 * Returns the range of z-values in the specified dataset for the
 * data items belonging to the visible series and with x-values in the
 * given range.//ww  w  .j a va 2s  .  c om
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param visibleSeriesKeys  the visible series keys (<code>null</code> not
 *     permitted).
 * @param xRange  the x-range (<code>null</code> not permitted).
 * @param includeInterval  a flag that determines whether or not the
 *     z-interval for the dataset is included (this only applies if the
 *     dataset has an interval, which is currently not supported).
 *
 * @return The y-range (possibly <code>null</code>).
 */
public static Range iterateToFindZBounds(XYZDataset dataset, List visibleSeriesKeys, Range xRange,
        boolean includeInterval) {
    ParamChecks.nullNotPermitted(dataset, "dataset");
    ParamChecks.nullNotPermitted(visibleSeriesKeys, "visibleSeriesKeys");
    ParamChecks.nullNotPermitted(xRange, "xRange");

    double minimum = Double.POSITIVE_INFINITY;
    double maximum = Double.NEGATIVE_INFINITY;

    Iterator iterator = visibleSeriesKeys.iterator();
    while (iterator.hasNext()) {
        Comparable seriesKey = (Comparable) iterator.next();
        int series = dataset.indexOf(seriesKey);
        int itemCount = dataset.getItemCount(series);
        for (int item = 0; item < itemCount; item++) {
            double x = dataset.getXValue(series, item);
            double z = dataset.getZValue(series, item);
            if (xRange.contains(x)) {
                if (!Double.isNaN(z)) {
                    minimum = Math.min(minimum, z);
                    maximum = Math.max(maximum, z);
                }
            }
        }
    }

    if (minimum == Double.POSITIVE_INFINITY) {
        return null;
    } else {
        return new Range(minimum, maximum);
    }
}

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

/**
 *
 * @param xyz/*from   w  w  w .  j a  va 2s  .  c o m*/
 * @param sl
 * @param spm
 * @param xybr
 * @param activeGraphics
 * @param dataArea
 * @param info
 * @param crosshairState
 * @return
 */
public BufferedImage prepareData(final XYZDataset xyz, final int sl, final int spm, final XYBlockRenderer xybr,
        Graphics2D activeGraphics, Rectangle2D dataArea, PlotRenderingInfo info,
        CrosshairState crosshairState) {
    long start = System.currentTimeMillis();
    final PaintScale ps = xybr.getPaintScale();
    double minz = Double.POSITIVE_INFINITY, maxz = Double.NEGATIVE_INFINITY;

    for (int i = 0; i < xyz.getSeriesCount(); i++) {
        final int items = xyz.getItemCount(i);
        for (int j = 0; j < items; j++) {
            minz = Math.min(xyz.getZValue(i, j), minz);
            maxz = Math.max(xyz.getZValue(i, j), maxz);
        }
    }
    if (ps instanceof GradientPaintScale) {
        ((GradientPaintScale) ps).setUpperBound(maxz);
        ((GradientPaintScale) ps).setLowerBound(minz);
    }
    Logger.getLogger(getClass().getName()).log(Level.INFO, "Finding min and max data took{0}ms",
            (System.currentTimeMillis() - start));

    //        VolatileImage bi = null;
    //        if (bi == null) {
    //        if (this.getOrientation() == PlotOrientation.VERTICAL) {
    BufferedImage bi = createCompatibleImage(sl, spm, BufferedImage.TRANSLUCENT);
    //        } else {
    //            bi = createCompatibleImage(spm, sl);
    //        }
    //        }else{
    //            img.validate(g.getDeviceConfiguration())
    //        }

    Graphics2D g2 = (Graphics2D) bi.getGraphics();
    g2.setColor((Color) ps.getPaint(ps.getLowerBound()));
    g2.fillRect(0, 0, sl, spm);
    // System.out.println("Using Threshold: " + threshold);
    int height = bi.getHeight();
    //final WritableRaster wr = bi.getRaster();
    XYItemRendererState xyrs = xybr.initialise(g2, dataArea, this, xyz, info);
    for (int i = 0; i < xyz.getSeriesCount(); i++) {
        final int items = xyz.getItemCount(i);
        for (int j = 0; j < items; j++) {
            final double tmp = xyz.getZValue(i, j);
            if (tmp > this.threshholdCutOff) {
                //if(j%50==0)System.out.println("Value > threshold: "+tmp);
                final Paint p = ps.getPaint(tmp);
                //                    final Paint tp = ps.getPaint(this.threshholdCutOff);
                //                    if (!tp.equals(p)) {
                if (p instanceof Color) {
                    final Color c = (Color) p;
                    g2.setColor(c);
                    //                    xybr.drawItem(g2, xyrs, dataArea, info, this, domainAxis, rangeAxis, xyz, i, j, crosshairState, 0);
                    //                        if (this.getOrientation() == PlotOrientation.VERTICAL) {

                    g2.fillRect((int) xyz.getXValue(i, j), height - (int) xyz.getYValue(i, j), 1, 1);
                    //                            wr.setPixel(, , new int[]{c.getRed(),
                    //                                        c.getGreen(), c.getBlue(), c.getAlpha()});
                    //                        } else {
                    //                            wr.setPixel((int) xyz.getYValue(i, j), (int) xyz.getXValue(i, j), new int[]{c.getRed(),
                    //                                        c.getGreen(), c.getBlue(), c.getAlpha()});
                    //                        }
                    //                }
                    //                    }
                }
            }
        }
    }

    Logger.getLogger(getClass().getName()).log(Level.INFO, "Creating image and drawing items took {0}ms",
            (System.currentTimeMillis() - start));

    return bi;
}