Example usage for org.jfree.data.xy XYSeriesCollection setIntervalWidth

List of usage examples for org.jfree.data.xy XYSeriesCollection setIntervalWidth

Introduction

In this page you can find the example usage for org.jfree.data.xy XYSeriesCollection setIntervalWidth.

Prototype

public void setIntervalWidth(double width) 

Source Link

Document

Sets the interval width and sends a DatasetChangeEvent to all registered listeners.

Usage

From source file:org.jfree.chart.demo.XYAreaChartDemo1.java

private static XYDataset createDataset() {
    XYSeries xyseries = new XYSeries("Random 1");
    xyseries.add(new Integer(1), new Double(500.19999999999999D));
    xyseries.add(new Integer(2), new Double(694.10000000000002D));
    xyseries.add(new Integer(3), new Double(-734.39999999999998D));
    xyseries.add(new Integer(4), new Double(453.19999999999999D));
    xyseries.add(new Integer(5), new Double(500.19999999999999D));
    xyseries.add(new Integer(6), new Double(300.69999999999999D));
    xyseries.add(new Integer(7), new Double(734.39999999999998D));
    xyseries.add(new Integer(8), new Double(453.19999999999999D));
    XYSeries xyseries1 = new XYSeries("Random 2");
    xyseries1.add(new Integer(1), new Double(700.20000000000005D));
    xyseries1.add(new Integer(2), new Double(534.10000000000002D));
    xyseries1.add(new Integer(3), new Double(323.39999999999998D));
    xyseries1.add(new Integer(4), new Double(125.2D));
    xyseries1.add(new Integer(5), new Double(653.20000000000005D));
    xyseries1.add(new Integer(6), new Double(432.69999999999999D));
    xyseries1.add(new Integer(7), new Double(564.39999999999998D));
    xyseries1.add(new Integer(8), new Double(322.19999999999999D));
    XYSeriesCollection xyseriescollection = new XYSeriesCollection();
    xyseriescollection.addSeries(xyseries);
    xyseriescollection.addSeries(xyseries1);
    xyseriescollection.setIntervalWidth(0.0D);
    return xyseriescollection;
}

From source file:edu.ucla.stat.SOCR.chart.demo.XYAreaChartDemo1.java

protected XYDataset createDataset(boolean isDemo) {
    if (isDemo) {
        XYSeries series1 = new XYSeries("Random 1");
        series1.add(new Integer(1), new Double(500.2));
        series1.add(new Integer(2), new Double(694.1));
        series1.add(new Integer(3), new Double(-734.4));
        series1.add(new Integer(4), new Double(453.2));
        series1.add(new Integer(5), new Double(500.2));
        series1.add(new Integer(6), new Double(300.7));
        series1.add(new Integer(7), new Double(734.4));
        series1.add(new Integer(8), new Double(453.2));

        XYSeries series2 = new XYSeries("Random 2");
        series2.add(new Integer(1), new Double(700.2));
        series2.add(new Integer(2), new Double(534.1));
        series2.add(new Integer(3), new Double(323.4));
        series2.add(new Integer(4), new Double(125.2));
        series2.add(new Integer(5), new Double(653.2));
        series2.add(new Integer(6), new Double(432.7));
        series2.add(new Integer(7), new Double(564.4));
        series2.add(new Integer(8), new Double(322.2));

        XYSeriesCollection dataset = new XYSeriesCollection();
        dataset.addSeries(series1);/*from w  w w . j  a va2 s .  c  o  m*/
        dataset.addSeries(series2);
        dataset.setIntervalWidth(0.0);
        return dataset;
    } else
        return super.createDataset(false);
}

From source file:fungus.UtilizationChartFrame.java

public UtilizationChartFrame(String prefix) {
    simulationCycles = Configuration.getDouble(PAR_SIMULATION_CYCLES);
    this.setTitle("MycoNet Statistics Chart");
    graph = JungGraphObserver.getGraph();

    //data.add(-1,0);
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.setAutoWidth(false);// w  ww . j ava 2  s  .c o  m
    dataset.setIntervalWidth(simulationCycles);

    averageUtilizationData = new XYSeries("Average Utilization");
    dataset.addSeries(averageUtilizationData);
    averageStableUtilizationData = new XYSeries("Avg Stable Util");
    dataset.addSeries(averageStableUtilizationData);
    hyphaRatioData = new XYSeries("Hypha Ratio");
    dataset.addSeries(hyphaRatioData);
    stableHyphaRatioData = new XYSeries("Stable Hypha Ratio");
    dataset.addSeries(stableHyphaRatioData);

    //XYSeriesCollection dataset;

    JFreeChart utilizationChart = ChartFactory.createXYLineChart("Utilization Metrics", "Cycle",
            "Average Utilization", dataset, PlotOrientation.VERTICAL, true, false, false);
    ChartPanel utilizationChartPanel = new ChartPanel(utilizationChart);

    //chart.setBackgroundPaint(Color.white);
    //XYPlot plot = chart.getXYPlot();

    //        BufferedImage chartImage = chart.createBufferedImage(500,300);
    //        chartLabel = new JLabel();
    //chartLabel.setIcon(new ImageIcon(chartImage));

    Container contentPane = getContentPane();
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));
    JPanel labelPane = new JPanel();
    labelPane.setLayout(new GridLayout(1, 1));
    //chartPane.setPreferredSize(new java.awt.Dimension(500, 300));
    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));

    ////contentPane.add(labelPane,BorderLayout.PAGE_START);
    //contentPane.add(Box.createRigidArea(new Dimension(0,5)));
    contentPane.add(utilizationChartPanel, BorderLayout.CENTER);
    //contentPane.add(Box.createRigidArea(new Dimension(0,5)));
    ////contentPane.add(buttonPane, BorderLayout.PAGE_END);

    //data = node.getHyphaData();
    //link = node.getHyphaLink();
    //mycocast = node.getMycoCast();

    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    //chartPanel.add(chartLabel);

    /*JButton updateButton = new JButton("Refresh");
      ActionListener updater = new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      refreshData();
      }
      };
      updateButton.addActionListener(updater);
            
      JButton closeButton = new JButton("Close");
      ActionListener closer = new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      closeFrame();
      }
      };
      closeButton.addActionListener(closer);
            
      buttonPane.add(Box.createHorizontalGlue());
      buttonPane.add(updateButton);
      buttonPane.add(Box.createRigidArea(new Dimension(5,0)));
      buttonPane.add(closeButton);
      refreshData();
    */

    //JungGraphObserver.addChangeListener(this);

    this.pack();
    this.setVisible(true);
}

From source file:fungus.PeerRatioChartFrame.java

public PeerRatioChartFrame(String prefix) {
    simulationCycles = Configuration.getDouble(PAR_SIMULATION_CYCLES);
    this.setTitle("MycoNet Statistics Chart");
    graph = JungGraphObserver.getGraph();

    //data.add(-1,0);
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.setAutoWidth(false);/*www  .j  av a  2  s .co m*/
    dataset.setIntervalWidth(simulationCycles);

    //averageUtilizationData = new XYSeries("Average Utilization");
    //dataset.addSeries(averageUtilizationData);
    //averageStableUtilizationData = new XYSeries("Avg Stable Util");
    //dataset.addSeries(averageStableUtilizationData);
    bulwarkRatioData = new XYSeries("Bulwark Ratio");
    dataset.addSeries(bulwarkRatioData);
    biomassRatioData = new XYSeries("Biomass Ratio");
    dataset.addSeries(biomassRatioData);
    hyphaRatioData = new XYSeries("Hypha Ratio");
    dataset.addSeries(hyphaRatioData);
    // stableHyphaRatioData = new XYSeries("Stable Hypha Ratio");
    // dataset.addSeries(stableHyphaRatioData);

    //XYSeriesCollection dataset;

    JFreeChart peerRatioChart = ChartFactory.createXYLineChart("Bulwark Metrics", "Cycle", "Peer State Ratio",
            dataset, PlotOrientation.VERTICAL, true, false, false);
    ChartPanel peerRatioChartPanel = new ChartPanel(peerRatioChart);

    XYPlot xyplot = peerRatioChart.getXYPlot();

    NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis();
    NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setRange(0, 1);

    //chart.setBackgroundPaint(Color.white);
    //XYPlot plot = chart.getXYPlot();

    //        BufferedImage chartImage = chart.createBufferedImage(500,300);
    //        chartLabel = new JLabel();
    //chartLabel.setIcon(new ImageIcon(chartImage));

    Container contentPane = getContentPane();
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));
    JPanel labelPane = new JPanel();
    labelPane.setLayout(new GridLayout(1, 1));
    //chartPane.setPreferredSize(new java.awt.Dimension(500, 300));
    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));

    ////contentPane.add(labelPane,BorderLayout.PAGE_START);
    //contentPane.add(Box.createRigidArea(new Dimension(0,5)));
    contentPane.add(peerRatioChartPanel, BorderLayout.CENTER);
    //contentPane.add(Box.createRigidArea(new Dimension(0,5)));
    ////contentPane.add(buttonPane, BorderLayout.PAGE_END);

    //data = node.getHyphaData();
    //link = node.getHyphaLink();
    //mycocast = node.getMycoCast();

    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    //chartPanel.add(chartLabel);

    /*JButton updateButton = new JButton("Refresh");
      ActionListener updater = new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      refreshData();
      }
      };
      updateButton.addActionListener(updater);
            
      JButton closeButton = new JButton("Close");
      ActionListener closer = new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      closeFrame();
      }
      };
      closeButton.addActionListener(closer);
            
      buttonPane.add(Box.createHorizontalGlue());
      buttonPane.add(updateButton);
      buttonPane.add(Box.createRigidArea(new Dimension(5,0)));
      buttonPane.add(closeButton);
      refreshData();
    */

    //JungGraphObserver.addChangeListener(this);

    this.pack();
    this.setVisible(true);
}

From source file:org.jfree.data.xy.junit.XYSeriesCollectionTest.java

/**
 * Confirm that the equals method can distinguish all the required fields.
 *///from   w w w. ja  va2s.co m
public void testEquals() {
    XYSeries s1 = new XYSeries("Series");
    s1.add(1.0, 1.1);
    XYSeriesCollection c1 = new XYSeriesCollection();
    c1.addSeries(s1);
    XYSeries s2 = new XYSeries("Series");
    s2.add(1.0, 1.1);
    XYSeriesCollection c2 = new XYSeriesCollection();
    c2.addSeries(s2);
    assertTrue(c1.equals(c2));
    assertTrue(c2.equals(c1));

    c1.addSeries(new XYSeries("Empty Series"));
    assertFalse(c1.equals(c2));
    c2.addSeries(new XYSeries("Empty Series"));
    assertTrue(c1.equals(c2));

    c1.setIntervalWidth(5.0);
    assertFalse(c1.equals(c2));
    c2.setIntervalWidth(5.0);
    assertTrue(c1.equals(c2));

    c1.setIntervalPositionFactor(0.75);
    assertFalse(c1.equals(c2));
    c2.setIntervalPositionFactor(0.75);
    assertTrue(c1.equals(c2));

    c1.setAutoWidth(true);
    assertFalse(c1.equals(c2));
    c2.setAutoWidth(true);
    assertTrue(c1.equals(c2));

}

From source file:org.jfree.data.xy.XYSeriesCollectionTest.java

/**
 * Confirm that the equals method can distinguish all the required fields.
 *//* www .  ja  va  2s  . c  o  m*/
@Test
public void testEquals() {
    XYSeries s1 = new XYSeries("Series");
    s1.add(1.0, 1.1);
    XYSeriesCollection c1 = new XYSeriesCollection();
    c1.addSeries(s1);
    XYSeries s2 = new XYSeries("Series");
    s2.add(1.0, 1.1);
    XYSeriesCollection c2 = new XYSeriesCollection();
    c2.addSeries(s2);
    assertEquals(c1, c2);
    assertEquals(c2, c1);

    c1.addSeries(new XYSeries("Empty Series"));
    assertFalse(c1.equals(c2));
    c2.addSeries(new XYSeries("Empty Series"));
    assertEquals(c1, c2);

    c1.setIntervalWidth(5.0);
    assertFalse(c1.equals(c2));
    c2.setIntervalWidth(5.0);
    assertEquals(c1, c2);

    c1.setIntervalPositionFactor(0.75);
    assertFalse(c1.equals(c2));
    c2.setIntervalPositionFactor(0.75);
    assertEquals(c1, c2);

    c1.setAutoWidth(true);
    assertFalse(c1.equals(c2));
    c2.setAutoWidth(true);
    assertEquals(c1, c2);

}

From source file:org.fhcrc.cpl.viewer.gui.SpectrumComponent.java

/**
 * update the chart with new data/*  w w  w. ja  v a 2 s.c om*/
 */
public void updateChart(boolean preserveDomain) {
    _log.debug("updateChart: start");
    float[][] spectrumIN = null;
    MSRun run = (MSRun) ApplicationContext.getProperty(SharedProperties.MS_RUN);
    MSRun.MSScan selectedScan = getSelectedScan();

    FloatRange rangeSpectrum = null; // restricted range of displayed data (for autoZoom)
    Pair<Spectrum.Peak, Spectrum.Peak> chartRange = null; // tell other components what we are displaying

    Range domainRange = null;
    if (preserveDomain && _chart != null)
        domainRange = _chart.getXYPlot().getDomainAxis().getRange();

    if (null == run || null == selectedScan) {
        clearChart();
        //if no chart to display, show white background
        chartArea.setBackground(java.awt.Color.WHITE);
        return;
    }

    chartArea.setBackground(_backgroundColor);

    if ("scan".equals(_type)) {
        scanSpinner.setValue(new Integer(selectedScan.getNum()));
        double t = selectedScan.getDoubleRetentionTime();
        timeTextField.setText("" + Math.round(t * 10) / 10.0);
        scanSpinner.setEnabled(true);
        //mzTextField.setText("");
        //mzTextField.setEnabled(false);
        mzSpinner.setValue(new Double(_selectedMZ));
        mzSpinner.setEnabled(false);

        /*         ArrayList l = new ArrayList();
                 l.add(selectedScan.getSpectrum());
                    spectrumIN = Spectrum.CombineRawSpectra(
            run.getTemplateSpectrum(),
            l,
            new FloatRange(selectedScan.getLowMz(),selectedScan.getHighMz())
            ); */

        spectrumIN = selectedScan.getSpectrum();

        if (autoZoom()) {
            // we don't want to filter the analyzed data, in case
            // that affects any of the algorithms
            // we only filter the result Datasets
            // UNDONE: choose range based on size of MSDetailPanel

            // range of 27+ is enough to see 4 ICAT labelled features (9*(4-1))
            rangeSpectrum = new FloatRange((float) _selectedMZ - 10F, (float) _selectedMZ + 30F);
        }

        if (null == rangeSpectrum) {
            chartRange = new Pair<Spectrum.Peak, Spectrum.Peak>(
                    new Spectrum.Peak(_selectedScanNum, spectrumIN[0][0], 0.0F),
                    new Spectrum.Peak(_selectedScanNum, spectrumIN[0][spectrumIN[0].length - 1]));
        } else {
            chartRange = new Pair<Spectrum.Peak, Spectrum.Peak>(
                    new Spectrum.Peak(_selectedScanNum, rangeSpectrum.min, 0.0F),
                    new Spectrum.Peak(_selectedScanNum, rangeSpectrum.max, 0.0F));
        }
    } else // elution
    {
        if (_selectedMZ == -1) {
            clearChart();
            return;
        }

        int RESAMPLE = 36;
        float mz = (float) Math.round(_selectedMZ * RESAMPLE) / RESAMPLE;
        _log.debug("updateChart mz=" + mz);

        scanSpinner.setValue(new Integer(selectedScan.getNum()));
        scanSpinner.setEnabled(false);
        double t = selectedScan.getDoubleRetentionTime();
        timeTextField.setText("" + Math.round(t * 10) / 10.0);
        //mzTextField.setText("" + mz);
        //mzTextField.setEnabled(true);
        mzSpinner.setValue(new Double(_selectedMZ));
        mzSpinner.setEnabled(true);

        FloatArray arrayIntensity = new FloatArray();
        FloatArray arrayScan = new FloatArray();
        int scanIndex = run.getIndexForScanNum(selectedScan.getNum());
        int scanStart = Math.max(0, scanIndex - 64);
        int scanEnd = Math.min(run.getScanCount() - 1, scanStart + 128);
        FloatRange r = new FloatRange(mz, mz);
        for (int s = scanStart; s < scanEnd; s++) {
            MSRun.MSScan scan = run.getScan(s);
            float[][] spectrumRaw = scan.getSpectrum();
            float[] resample = Spectrum.Resample(spectrumRaw, r, RESAMPLE);
            float f = resample[0];
            arrayIntensity.add(f);
            //arrayScan.add((float)scan.getDoubleRetentionTime());
            //            arrayScan.add((float)s);
            arrayScan.add((float) scan.getNum());
        }
        spectrumIN = new float[][] { arrayScan.toArray(null), arrayIntensity.toArray(null) };

        chartRange = new Pair<Spectrum.Peak, Spectrum.Peak>(
                new Spectrum.Peak(run.getScan(scanStart).getNum(), mz, 0.0F),
                new Spectrum.Peak(run.getScan(scanEnd).getNum(), mz, 0.0F));
    }

    String mode = (String) displayMode.getSelectedItem();

    java.util.List<XYSeriesCollection> listMultipleCharts = null;
    XYSeriesCollection series = new XYSeriesCollection();
    series.setIntervalWidth(0.0);

    //
    // Process source spectrum
    //

    float[][] spectrum = new float[][] { (float[]) spectrumIN[0].clone(), (float[]) spectrumIN[1].clone() };
    ProcessSpectrum: {
        if ("raw".equals(mode)) {
            break ProcessSpectrum;
        }

        if ("background centroided".equals(mode)) {
            if (run.getHeaderInfo().getDataProcessing().getCentroided() == 1)
                spectrum = FeatureStrategyCentroided.backgroundSpectrum(spectrum);
            break ProcessSpectrum;
        }

        if ("clean centroided".equals(mode)) {
            if (run.getHeaderInfo().getDataProcessing().getCentroided() == 1)
                spectrum = FeatureStrategyCentroided.cleanSpectrum(spectrum);
            break ProcessSpectrum;
        }

        // all subsequent processing expects resampling
        // don't resample elution profile
        if ("scan".equals(_type)) {
            int len = spectrum[0].length;
            spectrum = Spectrum.ResampleSpectrum(spectrumIN,
                    new FloatRange((float) Math.floor(spectrum[0][0]), (float) Math.ceil(spectrum[0][len - 1])),
                    36, false);
        } else {
            spectrum[1] = Spectrum.MedianSmooth(spectrum[1]);
            Spectrum.SmoothALittle(spectrum[1]);
        }

        if ("resampled".equals(mode))
            break ProcessSpectrum;

        /*         if ("compressed".equals(mode)) (data encoding test)
                    {
                    float[] s = spectrum[1];
                    short c[] = new short[s.length];
                    double m = 1.0;
                    for (int i = 0 ; i<c.length ; i++)
                       m = Math.max(m, s[i]);
                    double sqrt = Math.sqrt(m+1);
                    m = Math.round(Math.log(sqrt))+1;
                    double f = Math.floor(0x7fff / Math.log(sqrt));
                    m = 0;
                    for (int i = 0 ; i<c.length ; i++)
                       {
                       c[i] = (short)(Math.round(Math.log((s[i]+1)/sqrt) * f));
                       m = Math.max(m, Math.abs(c[i]));
                       }
                    System.err.println("MAX " + m);
                    for (int i = 0 ; i<c.length ; i++)
                       s[i] = (float)((Math.exp((double)c[i]/f) * sqrt) - 1);
                    break ProcessSpectrum;
                    } */

        // remove background for further processing
        if (run.getHeaderInfo().getDataProcessing().getCentroided() != 1) {
            int window = "scan".equals(_type) ? 72 : 15;
            float x[] = spectrum[1];
            float bg[] = Spectrum.MinimaWindow(x, spectrum[0].length, window, null);
            for (int i = 0; i < bg.length; i++)
                bg[i] = Math.max(0, x[i] - bg[i]);
            spectrum = new float[][] { spectrum[0], bg };
        }

        if ("subtract background".equals(mode))
            break ProcessSpectrum;

        if (mode.startsWith("threshold")) {
            spectrum[1] = Spectrum.WaveletD3(spectrum[1], null);
            break ProcessSpectrum;
        }

        if ("peaks".equals(mode) || "smoothed".equals(mode)) {
            if ("scan".equals(_type)) {
                double s = Smooth2D.smoothYfactor;
                spectrum[1] = Spectrum.FFTsmooth(spectrum[1], s, false);
            } else {
                //FeatureStrategyPeakClusters.smoothTHRESHOLD sm = new FeatureStrategyPeakClusters.smoothTHRESHOLD();
                spectrum[1] = SmootherCreator._thresholdElution(spectrum[1]);
            }
            break ProcessSpectrum;
        }
    } // ProcessSpectrum:

    //
    // This is the source spectrum
    //

    String name = mode.indexOf("peaks") != -1 ? "-spectrum" : "|spectrum";
    series.addSeries(new SpectrumXYSeries(name, spectrum, rangeSpectrum));
    _spectrum = spectrum;

    //
    // add additional series/charts
    //

    // show min/med for reference
    if (mode.equals("resampled") || mode.equals("subtract background")) {
        float[] T;
        if (mode.equals("resampled")) {
            T = Spectrum.MinimaWindow(spectrum[1], spectrum[0].length, 72, null);
            series.addSeries(new SpectrumXYSeries("-min", new float[][] { spectrum[0], T }, rangeSpectrum));
        }
        T = Spectrum.MedianWindow(spectrum[1], spectrum[0].length, 72, false);
        series.addSeries(new SpectrumXYSeries("-med", new float[][] { spectrum[0], T }, rangeSpectrum));
    }

    if (mode.startsWith("wavelet decomposition") || mode.startsWith("wavelet multiresolution")) {
        Filter f = new Filter("haar");
        float[] signal = spectrum[1]; // Spectrum.PadToDouble(spectrum[1], 32);
        int N = spectrum[0].length; // signal.length;
        int levels = 5;

        //if ("wavelet decomposition 2".equals(mode)) Spectrum.SmoothALittle(signal);

        float[][] modwt1 = Transform.decompose(signal, N, levels, f, "modwt", "periodic", null);
        float[][] t = modwt1;

        if ("wavelet multiresolution".equals(mode)) {
            t = Transform.multiresolution(t, N, levels, f, "modwt", "periodic", null);
        } else if ("wavelet decomposition 2".equals(mode)) {
            float[][] mra = Transform.multiresolution(t, N, levels, f, "modwt", "periodic", null);
            float[][] modwt2 = Transform.decompose(t[2], N, levels, f, "modwt", "periodic", null);
            // show original, d1, and d2
            float[] a = modwt1[2];
            float[] b = modwt2[2];
            float[] m = mra[2];
            Spectrum.Rotate(a, -3);
            Spectrum.Rotate(b, -7);
            t = new float[][] { a, /*b,*/ m }; // b is a mirror image of m
        }

        // copy array into data series
        listMultipleCharts = new java.util.LinkedList<XYSeriesCollection>();
        XYSeriesCollection ds = new XYSeriesCollection(
                new SpectrumXYSeries("spectrum", spectrum, rangeSpectrum));
        ds.setIntervalWidth(0.0);
        listMultipleCharts.add(ds);
        for (int i = 0; i < t.length; i++) {
            //float[] s = Spectrum.UnpadToFloat(t[i], 32, null);
            float[][] l = new float[][] { spectrum[0], t[i] };
            ds = new XYSeriesCollection(new SpectrumXYSeries("level " + (i + 1), l, rangeSpectrum));
            ds.setIntervalWidth(0.0);
            listMultipleCharts.add(ds);
        }
    } else if (mode.startsWith("haar")) {
        int l = Integer.parseInt(mode.substring(4));
        listMultipleCharts = new LinkedList<XYSeriesCollection>();

        float[] t1 = Haar.transform(spectrum[1], l);
        float[] t2 = Haar.transform(t1, l);
        XYSeriesCollection ds = new XYSeriesCollection(
                new SpectrumXYSeries("spectrum", spectrum, rangeSpectrum));
        ds.setIntervalWidth(0.0);
        listMultipleCharts.add(ds);
        XYSeriesCollection ds1 = new XYSeriesCollection(
                new SpectrumXYSeries(mode, new float[][] { spectrum[0], t1 }, rangeSpectrum));
        ds1.setIntervalWidth(0.0);
        listMultipleCharts.add(ds1);
        XYSeriesCollection ds2 = new XYSeriesCollection(
                new SpectrumXYSeries(mode, new float[][] { spectrum[0], t2 }, rangeSpectrum));
        ds2.setIntervalWidth(0.0);
        listMultipleCharts.add(ds2);
    } else if ("peaks".equals(mode) || "threshold peaks".equals(mode)) {
        double noise = 0.1; //"peaks".equals(mode) ? 2.0 : 1.0; // Spectrum.Noise(spectrum[1], 0, spectrum[1].length);
        int[] peakList = Spectrum.PickPeakIndexes(spectrum[1], noise);

        float[][] peaks = new float[2][peakList.length];
        for (int i = 0; i < peakList.length; i++) {
            int p = peakList[i];
            if (p >= spectrum[0].length)
                continue;
            peaks[0][i] = spectrum[0][p];
            peaks[1][i] = spectrum[1][p];
        }
        series.addSeries(new SpectrumXYSeries("|peaks", peaks, rangeSpectrum));
        _spectrum = peaks;
    } else if ("wavelet peaks".equals(mode)) {
        //Spectrum.Peak[] peaks = Spectrum.WaveletPeaks(spectrum);
        Spectrum.Peak[] peaks = Spectrum.WaveletPeaksD3(spectrum);
        float[][] peakSpectrum = new float[2][peaks.length];
        for (int p = 0; p < peaks.length; p++) {
            peakSpectrum[0][p] = peaks[p].mz;
            peakSpectrum[1][p] = peaks[p].intensity;
        }

        // show d3 and thresholded spectrum
        int levels = 3, N = spectrum[0].length;
        Filter f = new Filter("haar");
        float[][] modwt = Transform.decompose(spectrum[1], N, levels, f, "modwt", "periodic", null);
        float[][] mra = Transform.multiresolution(modwt, N, levels, f, "modwt", "periodic", null);
        float[] thresholded = new float[N];
        for (int i = 0; i < N; i++)
            thresholded[i] = mra[2][i] + mra[3][i];

        series.removeAllSeries();
        //series.addSeries(new SpectrumXYSeries("-spectrum", new float[][] {spectrum[0],thresholded}, rangeSpectrum));
        series.addSeries(new SpectrumXYSeries("-mra", new float[][] { spectrum[0], mra[2] }, rangeSpectrum));
        series.addSeries(new SpectrumXYSeries("|peaks", peakSpectrum, rangeSpectrum));
        _spectrum = peakSpectrum;
    }

    //
    // now update or create chart
    //

    Color[] colors = series.getSeriesCount() == 3 ? new Color[] { Color.RED, Color.BLUE, Color.BLUE }
            : series.getSeriesCount() == 2 ? new Color[] { Color.BLUE, Color.RED } : new Color[] { Color.RED };

    // NOTE: the more often we call setDatasets instead of creating new chart the better
    // CONSIDER: if we don't save chart, at least preserve zoom settings
    if (false && _chart != null && _chartPanel != null && !(_chart.getPlot() instanceof CombinedDomainXYPlot)
            && listMultipleCharts == null) {
        SpectrumChartFactory.setColors(_chartPanel, colors);
        _chart.getXYPlot().setDataset(series);
        _chartPanel.updateUI();
    } else {
        if (listMultipleCharts == null) {
            _log.debug(
                    "updateChart: series=" + series.getSeriesCount() + " length(0)=" + series.getItemCount(0));
            _chartPanel = SpectrumChartFactory.CreateChartPanel(series, colors);
        } else {
            _log.debug("updateChart: charts=" + listMultipleCharts.size());
            _chartPanel = SpectrumChartFactory.CreateChartPanel(listMultipleCharts, colors);
        }
        _chart = _chartPanel.getChart();

        // there seem to be mystery margins so give a little extra space
        Dimension size = chartArea.getSize();
        _chartPanel.setPreferredSize(new Dimension(size.width - 10, size.height - 10));
        chartArea.removeAll();
        chartArea.add(_chartPanel);
        chartArea.doLayout();
    }
    if (null != domainRange)
        _chart.getXYPlot().getDomainAxis().setRange(domainRange);

    //dhmay: if the user has locked the Y axis, then try to use the stored Y axis range
    if (isYAxisLocked()) {
        //a locked axis value won't be available if the axis was _just_ locked
        if (null == _lockedYAxisRange) {
            //if we've already displayed a chart, use that chart's axis range.  Otherwise,
            //don't force, and record this chart's axis range
            if (_previousYAxisRange != null)
                _lockedYAxisRange = _previousYAxisRange;
            else
                _lockedYAxisRange = _chart.getXYPlot().getRangeAxis().getRange();
        }
        _chart.getXYPlot().getRangeAxis().setRange(_lockedYAxisRange);
    } else {
        //if the Y axis isn't locked, then dump the stored range so it isn't used later
        _lockedYAxisRange = null;
    }

    //always store the previous Y axis range
    if (_chart.getXYPlot() != null && _chart.getXYPlot().getRangeAxis() != null
            && _chart.getXYPlot().getRangeAxis().getRange() != null) {
        _previousYAxisRange = _chart.getXYPlot().getRangeAxis().getRange();
    }

    ApplicationContext.setProperty(SharedProperties.CHART_RANGE, chartRange);
}