org.jfree.data.time.TimePeriodValues Java Examples

The following examples show how to use org.jfree.data.time.TimePeriodValues. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TimePeriodValuesCollectionTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A test for bug report 1161340.  I wasn't able to reproduce the problem
 * with this test.
 */
public void test1161340() {
    TimePeriodValuesCollection dataset = new TimePeriodValuesCollection();
    TimePeriodValues v1 = new TimePeriodValues("V1");
    v1.add(new Day(11, 3, 2005), 1.2);
    v1.add(new Day(12, 3, 2005), 3.4);
    dataset.addSeries(v1);
    assertEquals(1, dataset.getSeriesCount());
    dataset.removeSeries(v1);
    assertEquals(0, dataset.getSeriesCount());
    
    TimePeriodValues v2 = new TimePeriodValues("V2");
    v1.add(new Day(5, 3, 2005), 1.2);
    v1.add(new Day(6, 3, 2005), 3.4);
    dataset.addSeries(v2);
    assertEquals(1, dataset.getSeriesCount());
}
 
Example #2
Source File: ChartUtil.java    From ezScrum with GNU General Public License v2.0 6 votes vote down vote up
private XYDataset createBarDataset() {
	final TimePeriodValuesCollection result = new TimePeriodValuesCollection();
	Set<String> nameSet = this.m_dataSetMap.keySet();

	for (String name : nameSet) {
		final TimePeriodValues series = new TimePeriodValues(name);

		Map<Date, ? extends Number> map = m_dataSetMap.get(name);

		Iterator<Date> ir = map.keySet().iterator();

		while (ir.hasNext()) {
			Date key = ir.next();
			series.add(new SimpleTimePeriod(key, new Date(key.getTime()
					+ (m_interval * OneDay))), map.get(key));
		}

		result.addSeries(series);
	}
	return result;
}
 
Example #3
Source File: TimePeriodValuesCollectionTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some more checks for the getDomainBounds() method.
 * 
 * @see #testGetDomainBoundsWithoutInterval()
 */
public void testGetDomainBoundsWithInterval() {
    // check empty dataset
    TimePeriodValuesCollection dataset = new TimePeriodValuesCollection();
    Range r = dataset.getDomainBounds(true);
    assertNull(r);
    
    // check dataset with one time period
    TimePeriodValues s1 = new TimePeriodValues("S1");
    s1.add(new SimpleTimePeriod(1000L, 2000L), 1.0);
    dataset.addSeries(s1);
    r = dataset.getDomainBounds(true);
    assertEquals(1000.0, r.getLowerBound(), EPSILON);
    assertEquals(2000.0, r.getUpperBound(), EPSILON);
    
    // check dataset with two time periods
    s1.add(new SimpleTimePeriod(1500L, 3000L), 2.0);
    r = dataset.getDomainBounds(true);
    assertEquals(1000.0, r.getLowerBound(), EPSILON);
    assertEquals(3000.0, r.getUpperBound(), EPSILON);  
}
 
Example #4
Source File: TimePeriodValuesCollectionTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getDomainBounds() method.
 */
public void testGetDomainBoundsWithoutInterval() {
    // check empty dataset
    TimePeriodValuesCollection dataset = new TimePeriodValuesCollection();
    Range r = dataset.getDomainBounds(false);
    assertNull(r);
    
    // check dataset with one time period
    TimePeriodValues s1 = new TimePeriodValues("S1");
    s1.add(new SimpleTimePeriod(1000L, 2000L), 1.0);
    dataset.addSeries(s1);
    r = dataset.getDomainBounds(false);
    assertEquals(1500.0, r.getLowerBound(), EPSILON);
    assertEquals(1500.0, r.getUpperBound(), EPSILON);
    
    // check dataset with two time periods
    s1.add(new SimpleTimePeriod(1500L, 3000L), 2.0);
    r = dataset.getDomainBounds(false);
    assertEquals(1500.0, r.getLowerBound(), EPSILON);
    assertEquals(2250.0, r.getUpperBound(), EPSILON);  
}
 
Example #5
Source File: TimePeriodValuesCollectionTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests the equals() method.
 */
public void testEquals() {
    
    TimePeriodValuesCollection c1 = new TimePeriodValuesCollection();
    TimePeriodValuesCollection c2 = new TimePeriodValuesCollection();
    assertTrue(c1.equals(c2));
    
    c1.setXPosition(TimePeriodAnchor.END);
    assertFalse(c1.equals(c2));
    c2.setXPosition(TimePeriodAnchor.END);
    assertTrue(c1.equals(c2));
    
    TimePeriodValues v1 = new TimePeriodValues("Test");
    TimePeriodValues v2 = new TimePeriodValues("Test");
    
    c1.addSeries(v1);
    assertFalse(c1.equals(c2));
    c2.addSeries(v2);
    assertTrue(c1.equals(c2));
}
 
Example #6
Source File: TimePeriodValuesCollectionTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A test for bug report 1161340.  I wasn't able to reproduce the problem
 * with this test.
 */
public void test1161340() {
    TimePeriodValuesCollection dataset = new TimePeriodValuesCollection();
    TimePeriodValues v1 = new TimePeriodValues("V1");
    v1.add(new Day(11, 3, 2005), 1.2);
    v1.add(new Day(12, 3, 2005), 3.4);
    dataset.addSeries(v1);
    assertEquals(1, dataset.getSeriesCount());
    dataset.removeSeries(v1);
    assertEquals(0, dataset.getSeriesCount());
    
    TimePeriodValues v2 = new TimePeriodValues("V2");
    v1.add(new Day(5, 3, 2005), 1.2);
    v1.add(new Day(6, 3, 2005), 3.4);
    dataset.addSeries(v2);
    assertEquals(1, dataset.getSeriesCount());
}
 
Example #7
Source File: TimePeriodValuesTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the add() methods.
 */
public void testAdd() {
    TimePeriodValues tpv = new TimePeriodValues("Test");
    MySeriesChangeListener listener = new MySeriesChangeListener();
    tpv.addChangeListener(listener);
    tpv.add(new TimePeriodValue(new SimpleTimePeriod(new Date(1L), 
            new Date(3L)), 99.0));
    assertEquals(99.0, tpv.getValue(0).doubleValue(), EPSILON);
    assertEquals(tpv, listener.getLastEvent().getSource());
    
    // a null item should throw an IllegalArgumentException
    boolean pass = false;
    try {
        tpv.add((TimePeriodValue) null);
    }
    catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example #8
Source File: TimePeriodValuesCollectionTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getDomainBounds() method.
 */
public void testGetDomainBoundsWithoutInterval() {
    // check empty dataset
    TimePeriodValuesCollection dataset = new TimePeriodValuesCollection();
    Range r = dataset.getDomainBounds(false);
    assertNull(r);
    
    // check dataset with one time period
    TimePeriodValues s1 = new TimePeriodValues("S1");
    s1.add(new SimpleTimePeriod(1000L, 2000L), 1.0);
    dataset.addSeries(s1);
    r = dataset.getDomainBounds(false);
    assertEquals(1500.0, r.getLowerBound(), EPSILON);
    assertEquals(1500.0, r.getUpperBound(), EPSILON);
    
    // check dataset with two time periods
    s1.add(new SimpleTimePeriod(1500L, 3000L), 2.0);
    r = dataset.getDomainBounds(false);
    assertEquals(1500.0, r.getLowerBound(), EPSILON);
    assertEquals(2250.0, r.getUpperBound(), EPSILON);  
}
 
Example #9
Source File: TimePeriodValuesCollectionTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests the equals() method.
 */
public void testEquals() {
    
    TimePeriodValuesCollection c1 = new TimePeriodValuesCollection();
    TimePeriodValuesCollection c2 = new TimePeriodValuesCollection();
    assertTrue(c1.equals(c2));
    
    c1.setXPosition(TimePeriodAnchor.END);
    assertFalse(c1.equals(c2));
    c2.setXPosition(TimePeriodAnchor.END);
    assertTrue(c1.equals(c2));
    
    TimePeriodValues v1 = new TimePeriodValues("Test");
    TimePeriodValues v2 = new TimePeriodValues("Test");
    
    c1.addSeries(v1);
    assertFalse(c1.equals(c2));
    c2.addSeries(v2);
    assertTrue(c1.equals(c2));
}
 
Example #10
Source File: TimePeriodChartHyperlinkProvider.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public JRPrintHyperlink getEntityHyperlink(ChartEntity entity)
{
	JRPrintHyperlink printHyperlink = null;
	if (hasHyperlinks() && entity instanceof XYItemEntity)
	{
		XYItemEntity itemEntity = (XYItemEntity) entity;
		TimePeriodValuesCollection dataset = (TimePeriodValuesCollection) itemEntity.getDataset();
		TimePeriodValues series = dataset.getSeries(itemEntity.getSeriesIndex());
		Map<TimePeriod, JRPrintHyperlink> serieHyperlinks = itemHyperlinks.get(series.getKey());
		if (serieHyperlinks != null)
		{
			TimePeriod timePeriod = series.getTimePeriod(itemEntity.getItem());
			printHyperlink = serieHyperlinks.get(timePeriod);
		}
	}
	return printHyperlink;
}
 
Example #11
Source File: TimePeriodValuesTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the add() methods.
 */
public void testAdd() {
    TimePeriodValues tpv = new TimePeriodValues("Test");
    MySeriesChangeListener listener = new MySeriesChangeListener();
    tpv.addChangeListener(listener);
    tpv.add(new TimePeriodValue(new SimpleTimePeriod(new Date(1L), 
            new Date(3L)), 99.0));
    assertEquals(99.0, tpv.getValue(0).doubleValue(), EPSILON);
    assertEquals(tpv, listener.getLastEvent().getSource());
    
    // a null item should throw an IllegalArgumentException
    boolean pass = false;
    try {
        tpv.add((TimePeriodValue) null);
    }
    catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example #12
Source File: TimePeriodValuesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some tests for the getMinEndIndex() method.
 */
public void getMinEndIndex() {
    TimePeriodValues s = new TimePeriodValues("Test");
    assertEquals(-1, s.getMinEndIndex());
    s.add(new SimpleTimePeriod(100L, 200L), 1.0);
    assertEquals(0, s.getMinEndIndex());
    s.add(new SimpleTimePeriod(300L, 400L), 2.0);
    assertEquals(0, s.getMinEndIndex());
    s.add(new SimpleTimePeriod(0L, 50L), 3.0);
    assertEquals(2, s.getMinEndIndex());
}
 
Example #13
Source File: TimePeriodValuesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some tests for the getMaxEndIndex() method.
 */
public void getMaxEndIndex() {
    TimePeriodValues s = new TimePeriodValues("Test");
    assertEquals(-1, s.getMaxEndIndex());
    s.add(new SimpleTimePeriod(100L, 200L), 1.0);
    assertEquals(0, s.getMaxEndIndex());
    s.add(new SimpleTimePeriod(300L, 400L), 2.0);
    assertEquals(1, s.getMaxEndIndex());
    s.add(new SimpleTimePeriod(0L, 50L), 3.0);
    assertEquals(1, s.getMaxEndIndex());
}
 
Example #14
Source File: TimePeriodValuesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some tests for the getMaxMiddleIndex() method.
 */
public void testGetMaxMiddleIndex() {
    TimePeriodValues s = new TimePeriodValues("Test");
    assertEquals(-1, s.getMaxMiddleIndex());
    s.add(new SimpleTimePeriod(100L, 200L), 1.0);
    assertEquals(0, s.getMaxMiddleIndex());
    s.add(new SimpleTimePeriod(300L, 400L), 2.0);
    assertEquals(1, s.getMaxMiddleIndex());
    s.add(new SimpleTimePeriod(0L, 50L), 3.0);
    assertEquals(1, s.getMaxMiddleIndex());
    s.add(new SimpleTimePeriod(150L, 200L), 4.0);
    assertEquals(1, s.getMaxMiddleIndex());
}
 
Example #15
Source File: TimePeriodValuesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some tests for the getMinMiddleIndex() method.
 */
public void testGetMinMiddleIndex() {
    TimePeriodValues s = new TimePeriodValues("Test");
    assertEquals(-1, s.getMinMiddleIndex());
    s.add(new SimpleTimePeriod(100L, 200L), 1.0);
    assertEquals(0, s.getMinMiddleIndex());
    s.add(new SimpleTimePeriod(300L, 400L), 2.0);
    assertEquals(0, s.getMinMiddleIndex());
    s.add(new SimpleTimePeriod(0L, 50L), 3.0);
    assertEquals(2, s.getMinMiddleIndex());
}
 
Example #16
Source File: TimePeriodValuesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some tests for the getMaxStartIndex() method.
 */
public void testGetMaxStartIndex() {
    TimePeriodValues s = new TimePeriodValues("Test");
    assertEquals(-1, s.getMaxStartIndex());
    s.add(new SimpleTimePeriod(100L, 200L), 1.0);
    assertEquals(0, s.getMaxStartIndex());
    s.add(new SimpleTimePeriod(300L, 400L), 2.0);
    assertEquals(1, s.getMaxStartIndex());
    s.add(new SimpleTimePeriod(0L, 50L), 3.0);
    assertEquals(1, s.getMaxStartIndex());
}
 
Example #17
Source File: TimePeriodValuesCollectionTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some more checks for the getDomainBounds() method.
 * 
 * @see #testGetDomainBoundsWithoutInterval()
 */
public void testGetDomainBoundsWithInterval() {
    // check empty dataset
    TimePeriodValuesCollection dataset = new TimePeriodValuesCollection();
    Range r = dataset.getDomainBounds(true);
    assertNull(r);
    
    // check dataset with one time period
    TimePeriodValues s1 = new TimePeriodValues("S1");
    s1.add(new SimpleTimePeriod(1000L, 2000L), 1.0);
    dataset.addSeries(s1);
    r = dataset.getDomainBounds(true);
    assertEquals(1000.0, r.getLowerBound(), EPSILON);
    assertEquals(2000.0, r.getUpperBound(), EPSILON);
    
    // check dataset with two time periods
    s1.add(new SimpleTimePeriod(1500L, 3000L), 2.0);
    r = dataset.getDomainBounds(true);
    assertEquals(1000.0, r.getLowerBound(), EPSILON);
    assertEquals(3000.0, r.getUpperBound(), EPSILON);
    
    // add a third time period
    s1.add(new SimpleTimePeriod(6000L, 7000L), 1.5);
    r = dataset.getDomainBounds(true);
    assertEquals(1000.0, r.getLowerBound(), EPSILON);
    assertEquals(7000.0, r.getUpperBound(), EPSILON);

    // add a fourth time period
    s1.add(new SimpleTimePeriod(4000L, 5000L), 1.4);
    r = dataset.getDomainBounds(true);
    assertEquals(1000.0, r.getLowerBound(), EPSILON);
    assertEquals(7000.0, r.getUpperBound(), EPSILON);    
}
 
Example #18
Source File: TimePeriodValuesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add a value to series A for 1999.  It should be added at index 0.
 */
public void testAddValue() {

    TimePeriodValues tpvs = new TimePeriodValues("Test");
    try {
        tpvs.add(new Year(1999), new Integer(1));
    }
    catch (SeriesException e) {
        System.err.println("Problem adding to series.");
    }

    int value = tpvs.getValue(0).intValue();
    assertEquals(1, value);

}
 
Example #19
Source File: TimePeriodValuesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A test for bug report 1161329.
 */
public void test1161329() {
    TimePeriodValues tpv = new TimePeriodValues("Test");
    RegularTimePeriod t = new Day();
    tpv.add(t, 1.0);
    t = t.next();
    tpv.add(t, 2.0);
    tpv.delete(0, 1);
    assertEquals(0, tpv.getItemCount());
    tpv.add(t, 2.0);
    assertEquals(1, tpv.getItemCount());
}
 
Example #20
Source File: TimePeriodValuesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some tests for the getMinStartIndex() method.
 */
public void testGetMinStartIndex() {
    TimePeriodValues s = new TimePeriodValues("Test");
    assertEquals(-1, s.getMinStartIndex());
    s.add(new SimpleTimePeriod(100L, 200L), 1.0);
    assertEquals(0, s.getMinStartIndex());
    s.add(new SimpleTimePeriod(300L, 400L), 2.0);
    assertEquals(0, s.getMinStartIndex());
    s.add(new SimpleTimePeriod(0L, 50L), 3.0);
    assertEquals(2, s.getMinStartIndex());
}
 
Example #21
Source File: TimePeriodValuesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A test for bug report 1161329.
 */
public void test1161329() {
    TimePeriodValues tpv = new TimePeriodValues("Test");
    RegularTimePeriod t = new Day();
    tpv.add(t, 1.0);
    t = t.next();
    tpv.add(t, 2.0);
    tpv.delete(0, 1);
    assertEquals(0, tpv.getItemCount());
    tpv.add(t, 2.0);
    assertEquals(1, tpv.getItemCount());
}
 
Example #22
Source File: TimePeriodValuesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add a value to series A for 1999.  It should be added at index 0.
 */
public void testAddValue() {

    TimePeriodValues tpvs = new TimePeriodValues("Test");
    try {
        tpvs.add(new Year(1999), new Integer(1));
    }
    catch (SeriesException e) {
        System.err.println("Problem adding to series.");
    }

    int value = tpvs.getValue(0).intValue();
    assertEquals(1, value);

}
 
Example #23
Source File: ConvertChartContext.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
private XYDataset createTimePeriodDataset()
{
	if (sampleTimePeriodDataset == null)
	{
		TimePeriodValuesCollection dataset = new TimePeriodValuesCollection();

		Day today = new Day();
		TimePeriodValues series1 = new TimePeriodValues("First");
		TimePeriodValues series2 = new TimePeriodValues("Second");
		
		for (int i = 0; i < 24; i++) 
		{
			Minute m0 = new Minute(0, new Hour(i, today));
			Minute m1 = new Minute(15, new Hour(i, today));
			Minute m2 = new Minute(30, new Hour(i, today));
			Minute m3 = new Minute(45, new Hour(i, today));
			Minute m4 = new Minute(0, new Hour(i + 1, today));
			series1.add(new SimpleTimePeriod(m0.getStart(), m1.getStart()), Math.random());
			series2.add(new SimpleTimePeriod(m1.getStart(), m2.getStart()), Math.random());
			series1.add(new SimpleTimePeriod(m2.getStart(), m3.getStart()), Math.random());
			series2.add(new SimpleTimePeriod(m3.getStart(), m4.getStart()), Math.random());
		}

		dataset.addSeries(series1);
		dataset.addSeries(series2);
		
		sampleTimePeriodDataset = dataset;
	}

	return sampleTimePeriodDataset;
}
 
Example #24
Source File: TimePeriodValuesTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Tests the equals method.
 */
public void testEquals() {
    TimePeriodValues s1 = new TimePeriodValues("Time Series 1");
    TimePeriodValues s2 = new TimePeriodValues("Time Series 2");
    boolean b1 = s1.equals(s2);
    assertFalse("b1", b1);

    s2.setKey("Time Series 1");
    boolean b2 = s1.equals(s2);
    assertTrue("b2", b2);

    // domain description
    s1.setDomainDescription("XYZ");
    assertFalse(s1.equals(s2));
    s2.setDomainDescription("XYZ");
    assertTrue(s1.equals(s2));
    
    // domain description - null
    s1.setDomainDescription(null);
    assertFalse(s1.equals(s2));
    s2.setDomainDescription(null);
    assertTrue(s1.equals(s2));
    
    // range description
    s1.setRangeDescription("XYZ");
    assertFalse(s1.equals(s2));
    s2.setRangeDescription("XYZ");
    assertTrue(s1.equals(s2));
    
    // range description - null
    s1.setRangeDescription(null);
    assertFalse(s1.equals(s2));
    s2.setRangeDescription(null);
    assertTrue(s1.equals(s2));

    RegularTimePeriod p1 = new Day();
    RegularTimePeriod p2 = p1.next();
    s1.add(p1, 100.0);
    s1.add(p2, 200.0);
    boolean b3 = s1.equals(s2);
    assertFalse("b3", b3);

    s2.add(p1, 100.0);
    s2.add(p2, 200.0);
    boolean b4 = s1.equals(s2);
    assertTrue("b4", b4);

}
 
Example #25
Source File: TimePeriodValuesTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Tests the equals method.
 */
public void testEquals() {
    TimePeriodValues s1 = new TimePeriodValues("Time Series 1");
    TimePeriodValues s2 = new TimePeriodValues("Time Series 2");
    boolean b1 = s1.equals(s2);
    assertFalse("b1", b1);

    s2.setKey("Time Series 1");
    boolean b2 = s1.equals(s2);
    assertTrue("b2", b2);

    // domain description
    s1.setDomainDescription("XYZ");
    assertFalse(s1.equals(s2));
    s2.setDomainDescription("XYZ");
    assertTrue(s1.equals(s2));
    
    // domain description - null
    s1.setDomainDescription(null);
    assertFalse(s1.equals(s2));
    s2.setDomainDescription(null);
    assertTrue(s1.equals(s2));
    
    // range description
    s1.setRangeDescription("XYZ");
    assertFalse(s1.equals(s2));
    s2.setRangeDescription("XYZ");
    assertTrue(s1.equals(s2));
    
    // range description - null
    s1.setRangeDescription(null);
    assertFalse(s1.equals(s2));
    s2.setRangeDescription(null);
    assertTrue(s1.equals(s2));

    RegularTimePeriod p1 = new Day();
    RegularTimePeriod p2 = p1.next();
    s1.add(p1, 100.0);
    s1.add(p2, 200.0);
    boolean b3 = s1.equals(s2);
    assertFalse("b3", b3);

    s2.add(p1, 100.0);
    s2.add(p2, 200.0);
    boolean b4 = s1.equals(s2);
    assertTrue("b4", b4);

}