Example usage for org.jfree.data.time TimeSeries TimeSeries

List of usage examples for org.jfree.data.time TimeSeries TimeSeries

Introduction

In this page you can find the example usage for org.jfree.data.time TimeSeries TimeSeries.

Prototype

public TimeSeries(Comparable name) 

Source Link

Document

Creates a new (empty) time series.

Usage

From source file:org.jfree.data.time.junit.TimeSeriesTest.java

/**
 * Checks that the min and max y values are updated correctly when copying
 * a subset./*  w ww . java 2s.  c om*/
 *
 * @throws java.lang.CloneNotSupportedException
 */
public void testCreateCopy3() throws CloneNotSupportedException {
    TimeSeries s1 = new TimeSeries("S1");
    s1.add(new Year(2009), 100.0);
    s1.add(new Year(2010), 101.0);
    s1.add(new Year(2011), 102.0);
    assertEquals(100.0, s1.getMinY(), EPSILON);
    assertEquals(102.0, s1.getMaxY(), EPSILON);

    TimeSeries s2 = s1.createCopy(0, 1);
    assertEquals(100.0, s2.getMinY(), EPSILON);
    assertEquals(101.0, s2.getMaxY(), EPSILON);

    TimeSeries s3 = s1.createCopy(1, 2);
    assertEquals(101.0, s3.getMinY(), EPSILON);
    assertEquals(102.0, s3.getMaxY(), EPSILON);
}

From source file:org.jfree.data.time.TimeSeriesTest.java

/**
 * Test the add branch of the addOrUpdate() method.
 *//*www  .ja v  a  2 s  .c o m*/
@Test
public void testAddOrUpdate2() {
    TimeSeries s1 = new TimeSeries("S1");
    s1.setMaximumItemCount(2);
    s1.addOrUpdate(new Year(2010), 1.1);
    s1.addOrUpdate(new Year(2011), 2.2);
    s1.addOrUpdate(new Year(2012), 3.3);
    assertEquals(2, s1.getItemCount());
    assertEquals(2.2, s1.getMinY(), EPSILON);
    assertEquals(3.3, s1.getMaxY(), EPSILON);
}

From source file:org.jfree.data.time.junit.TimeSeriesTest.java

/**
 * Test the setMaximumItemCount() method to ensure that it removes items
 * from the series if necessary.//from  w  ww.ja v  a2  s.com
 */
public void testSetMaximumItemCount() {
    TimeSeries s1 = new TimeSeries("S1");
    s1.add(new Year(2000), 13.75);
    s1.add(new Year(2001), 11.90);
    s1.add(new Year(2002), null);
    s1.add(new Year(2005), 19.32);
    s1.add(new Year(2007), 16.89);
    assertTrue(s1.getItemCount() == 5);

    s1.setMaximumItemCount(3);
    assertTrue(s1.getItemCount() == 3);
    TimeSeriesDataItem item = s1.getDataItem(0);
    assertTrue(item.getPeriod().equals(new Year(2002)));
    assertEquals(16.89, s1.getMinY(), EPSILON);
    assertEquals(19.32, s1.getMaxY(), EPSILON);
}

From source file:org.mwc.debrief.track_shift.views.StackedDotHelper.java

/**
 * ok, our track has been dragged, calculate the new series of offsets
 * /*from  ww  w.  j a v a2  s.co m*/
 * @param linePlot
 * @param dotPlot
 * @param onlyVis
 * @param holder
 * @param logger
 * 
 * @param currentOffset
 *          how far the current track has been dragged
 */
public void updateFrequencyData(final XYPlot dotPlot, final XYPlot linePlot, final TrackDataProvider tracks,
        final boolean onlyVis, final Composite holder, final ErrorLogger logger, final boolean updateDoublets) {

    // do we have anything?
    if (_primaryTrack == null)
        return;

    // ok, find the track wrappers
    if (_secondaryTrack == null)
        initialise(tracks, false, onlyVis, holder, logger, "Frequency", false, true);

    // ok - the tracks have moved. better update the doublets
    if (updateDoublets)
        updateDoublets(onlyVis, false, true);

    // aah - but what if we've ditched our doublets?
    // aah - but what if we've ditched our doublets?
    if ((_primaryDoublets == null) || (_primaryDoublets.size() == 0)) {
        // better clear the plot
        dotPlot.setDataset(null);
        linePlot.setDataset(null);
        return;
    }

    // create the collection of series
    final TimeSeriesCollection errorSeries = new TimeSeriesCollection();
    final TimeSeriesCollection actualSeries = new TimeSeriesCollection();

    // produce a dataset for each track
    final TimeSeries errorValues = new TimeSeries(_primaryTrack.getName());

    final TimeSeries measuredValues = new TimeSeries("Measured");
    final TimeSeries correctedValues = new TimeSeries("Corrected");
    final TimeSeries predictedValues = new TimeSeries("Predicted");
    final TimeSeries baseValues = new TimeSeries("Base");

    // ok, run through the points on the primary track
    final Iterator<Doublet> iter = _primaryDoublets.iterator();
    while (iter.hasNext()) {
        final Doublet thisD = iter.next();
        try {

            final Color thisColor = thisD.getColor();
            final double measuredFreq = thisD.getMeasuredFrequency();
            final HiResDate currentTime = thisD.getDTG();
            final FixedMillisecond thisMilli = new FixedMillisecond(currentTime.getDate().getTime());

            final ColouredDataItem mFreq = new ColouredDataItem(thisMilli, measuredFreq, thisColor, false,
                    null);

            // final ColouredDataItem corrFreq = new ColouredDataItem(
            // new FixedMillisecond(currentTime.getDate().getTime()),
            // correctedFreq, thisColor, false, null);
            measuredValues.add(mFreq);

            // do we have target data?
            if (thisD.getTarget() != null) {
                final double correctedFreq = thisD.getCorrectedFrequency();
                final double baseFreq = thisD.getBaseFrequency();
                final Color calcColor = thisD.getTarget().getColor();

                final ColouredDataItem corrFreq = new ColouredDataItem(thisMilli, correctedFreq, thisColor,
                        true, null);

                // did we get a base frequency? We may have a track
                // with a section of data that doesn't have frequency, you see.
                if (baseFreq != Doublet.INVALID_BASE_FREQUENCY) {
                    final double predictedFreq = thisD.getPredictedFrequency();
                    final double thisError = thisD.calculateFreqError(measuredFreq, predictedFreq);
                    final ColouredDataItem bFreq = new ColouredDataItem(thisMilli, baseFreq, thisColor, true,
                            null);
                    final ColouredDataItem pFreq = new ColouredDataItem(thisMilli, predictedFreq, calcColor,
                            false, null);
                    final ColouredDataItem eFreq = new ColouredDataItem(thisMilli, thisError, thisColor, false,
                            null);
                    baseValues.add(bFreq);
                    predictedValues.add(pFreq);
                    errorValues.add(eFreq);
                }

                correctedValues.add(corrFreq);
            }

        } catch (final SeriesException e) {
            CorePlugin.logError(Status.INFO, "some kind of trip whilst updating frequency plot", e);
        }

    }

    // ok, add these new series
    if (errorValues.getItemCount() > 0)
        errorSeries.addSeries(errorValues);

    actualSeries.addSeries(measuredValues);
    actualSeries.addSeries(correctedValues);

    if (predictedValues.getItemCount() > 0)
        actualSeries.addSeries(predictedValues);
    if (baseValues.getItemCount() > 0)
        actualSeries.addSeries(baseValues);

    dotPlot.setDataset(errorSeries);
    linePlot.setDataset(actualSeries);
}

From source file:org.jfree.data.time.TimeSeriesTest.java

/**
 * Test that the addOrUpdate() method won't allow multiple time period
 * classes.//  w  w w  .java 2s  .  c om
 */
@Test
public void testAddOrUpdate3() {
    TimeSeries s1 = new TimeSeries("S1");
    s1.addOrUpdate(new Year(2010), 1.1);
    assertEquals(Year.class, s1.getTimePeriodClass());

    boolean pass = false;
    try {
        s1.addOrUpdate(new Month(1, 2009), 0.0);
    } catch (SeriesException e) {
        pass = true;
    }
    assertTrue(pass);
}

From source file:org.jfree.data.time.junit.TimeSeriesTest.java

/**
 * Some checks for the addOrUpdate() method.
 *///from   www  .  j  a va 2s. c  om
public void testAddOrUpdate() {
    TimeSeries s1 = new TimeSeries("S1");
    s1.setMaximumItemCount(2);
    s1.addOrUpdate(new Year(2000), 100.0);
    assertEquals(1, s1.getItemCount());
    s1.addOrUpdate(new Year(2001), 101.0);
    assertEquals(2, s1.getItemCount());
    s1.addOrUpdate(new Year(2001), 102.0);
    assertEquals(2, s1.getItemCount());
    s1.addOrUpdate(new Year(2002), 103.0);
    assertEquals(2, s1.getItemCount());
}

From source file:org.jfree.data.time.TimeSeriesTest.java

/**
 * Some more checks for the addOrUpdate() method.
 *//* w  w w  .  j a v a  2 s . c  o m*/
@Test
public void testAddOrUpdate4() {
    TimeSeries ts = new TimeSeries("S");
    TimeSeriesDataItem overwritten = ts.addOrUpdate(new Year(2009), 20.09);
    assertNull(overwritten);
    overwritten = ts.addOrUpdate(new Year(2009), 1.0);
    assertEquals(new Double(20.09), overwritten.getValue());
    assertEquals(new Double(1.0), ts.getValue(new Year(2009)));

    // changing the overwritten record shouldn't affect the series
    overwritten.setValue(null);
    assertEquals(new Double(1.0), ts.getValue(new Year(2009)));

    TimeSeriesDataItem item = new TimeSeriesDataItem(new Year(2010), 20.10);
    overwritten = ts.addOrUpdate(item);
    assertNull(overwritten);
    assertEquals(new Double(20.10), ts.getValue(new Year(2010)));
    // changing the item that was added should not change the series
    item.setValue(null);
    assertEquals(new Double(20.10), ts.getValue(new Year(2010)));
}

From source file:org.jfree.data.time.junit.TimeSeriesTest.java

/**
 * Test the add branch of the addOrUpdate() method.
 *//*w ww .  jav a2s . c  o  m*/
public void testAddOrUpdate2() {
    TimeSeries s1 = new TimeSeries("S1");
    s1.setMaximumItemCount(2);
    s1.addOrUpdate(new Year(2010), 1.1);
    s1.addOrUpdate(new Year(2011), 2.2);
    s1.addOrUpdate(new Year(2012), 3.3);
    assertEquals(2, s1.getItemCount());
    assertEquals(2.2, s1.getMinY(), EPSILON);
    assertEquals(3.3, s1.getMaxY(), EPSILON);
}