Java Code Examples for org.jfree.data.time.RegularTimePeriod#next()

The following examples show how to use org.jfree.data.time.RegularTimePeriod#next() . 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: SWTMultipleAxisDemo1.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a sample dataset.
 *
 * @param name  the dataset name.
 * @param base  the starting value.
 * @param start  the starting period.
 * @param count  the number of values to generate.
 *
 * @return The dataset.
 */
private static XYDataset createDataset(String name, double base,
                                       RegularTimePeriod start, int count) {

    TimeSeries series = new TimeSeries(name);
    RegularTimePeriod period = start;
    double value = base;
    for (int i = 0; i < count; i++) {
        series.add(period, value);
        period = period.next();
        value = value * (1 + (Math.random() - 0.495) / 10.0);
    }

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(series);

    return dataset;

}
 
Example 2
Source File: SWTMultipleAxisDemo1.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a sample dataset.
 * 
 * @param name  the dataset name.
 * @param base  the starting value.
 * @param start  the starting period.
 * @param count  the number of values to generate.
 *
 * @return The dataset.
 */
private static XYDataset createDataset(String name, double base, 
                                       RegularTimePeriod start, int count) {

    TimeSeries series = new TimeSeries(name, start.getClass());
    RegularTimePeriod period = start;
    double value = base;
    for (int i = 0; i < count; i++) {
        series.add(period, value);    
        period = period.next();
        value = value * (1 + (Math.random() - 0.495) / 10.0);
    }

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(series);

    return dataset;

}
 
Example 3
Source File: SWTMultipleAxisDemo1.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a sample dataset.
 *
 * @param name  the dataset name.
 * @param base  the starting value.
 * @param start  the starting period.
 * @param count  the number of values to generate.
 *
 * @return The dataset.
 */
private static XYDataset createDataset(String name, double base,
                                       RegularTimePeriod start, int count) {

    TimeSeries series = new TimeSeries(name);
    RegularTimePeriod period = start;
    double value = base;
    for (int i = 0; i < count; i++) {
        series.add(period, value);
        period = period.next();
        value = value * (1 + (Math.random() - 0.495) / 10.0);
    }

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(series);

    return dataset;

}
 
Example 4
Source File: JFreeChartTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Serialize a time seroes chart, restore it, and check for equality.
 */
@Test
public void testSerialization4() {

    RegularTimePeriod t = new Day();
    TimeSeries series = new TimeSeries("Series 1");
    series.add(t, 36.4);
    t = t.next();
    series.add(t, 63.5);
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(series);

    JFreeChart c1 = ChartFactory.createTimeSeriesChart("Test", "Date",
            "Value", dataset);
    JFreeChart c2 = (JFreeChart) TestUtilities.serialised(c1);
    assertEquals(c1, c2);
}
 
Example 5
Source File: SWTMultipleAxisDemo1.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a sample dataset.
 *
 * @param name  the dataset name.
 * @param base  the starting value.
 * @param start  the starting period.
 * @param count  the number of values to generate.
 *
 * @return The dataset.
 */
private static XYDataset createDataset(String name, double base,
                                       RegularTimePeriod start, int count) {

    TimeSeries series = new TimeSeries(name);
    RegularTimePeriod period = start;
    double value = base;
    for (int i = 0; i < count; i++) {
        series.add(period, value);
        period = period.next();
        value = value * (1 + (Math.random() - 0.495) / 10.0);
    }

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(series);

    return dataset;

}
 
Example 6
Source File: JFreeChartTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Serialize a time seroes chart, restore it, and check for equality.
 */
@Test
public void testSerialization4() {

    RegularTimePeriod t = new Day();
    TimeSeries series = new TimeSeries("Series 1");
    series.add(t, 36.4);
    t = t.next();
    series.add(t, 63.5);
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(series);

    JFreeChart c1 = ChartFactory.createTimeSeriesChart("Test", "Date",
            "Value", dataset);
    JFreeChart c2 = (JFreeChart) TestUtilities.serialised(c1);
    assertEquals(c1, c2);
}
 
Example 7
Source File: TimeSeriesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests the equals method.
 */
public void testEquals() {
    TimeSeries s1 = new TimeSeries("Time Series 1");
    TimeSeries s2 = new TimeSeries("Time Series 2");
    boolean b1 = s1.equals(s2);
    assertFalse("b1", b1);

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

    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);

    s1.setMaximumItemCount(100);
    boolean b5 = s1.equals(s2);
    assertFalse("b5", b5);

    s2.setMaximumItemCount(100);
    boolean b6 = s1.equals(s2);
    assertTrue("b6", b6);

    s1.setMaximumItemAge(100);
    boolean b7 = s1.equals(s2);
    assertFalse("b7", b7);

    s2.setMaximumItemAge(100);
    boolean b8 = s1.equals(s2);
    assertTrue("b8", b8);
}
 
Example 8
Source File: TimeSeriesCollectionTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a time series for testing.
 * 
 * @return A time series.
 */
private TimeSeries createSeries() {
    RegularTimePeriod t = new Day();
    TimeSeries series = new TimeSeries("Test");
    series.add(t, 1.0);
    t = t.next();
    series.add(t, 2.0);
    t = t.next();
    series.add(t, null);
    t = t.next();
    series.add(t, 4.0);
    return series;
}
 
Example 9
Source File: TimeSeriesCollectionTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a time series for testing.
 *
 * @return A time series.
 */
private TimeSeries createSeries() {
    RegularTimePeriod t = new Day();
    TimeSeries series = new TimeSeries("Test");
    series.add(t, 1.0);
    t = t.next();
    series.add(t, 2.0);
    t = t.next();
    series.add(t, null);
    t = t.next();
    series.add(t, 4.0);
    return series;
}
 
Example 10
Source File: PeriodAxis.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the major and minor tick marks for an axis that lies at the top or
 * bottom of the plot.
 *
 * @param g2  the graphics device.
 * @param state  the axis state.
 * @param dataArea  the data area.
 * @param edge  the edge.
 */
protected void drawTickMarksHorizontal(Graphics2D g2, AxisState state,
                                       Rectangle2D dataArea,
                                       RectangleEdge edge) {
    List ticks = new ArrayList();
    double x0 = dataArea.getX();
    double y0 = state.getCursor();
    double insideLength = getTickMarkInsideLength();
    double outsideLength = getTickMarkOutsideLength();
    RegularTimePeriod t = createInstance(this.majorTickTimePeriodClass,
            this.first.getStart(), getTimeZone(), this.locale);
    long t0 = t.getFirstMillisecond();
    Line2D inside = null;
    Line2D outside = null;
    long firstOnAxis = getFirst().getFirstMillisecond();
    long lastOnAxis = getLast().getLastMillisecond() + 1;
    while (t0 <= lastOnAxis) {
        ticks.add(new NumberTick(new Double(t0), "", TextAnchor.CENTER,
                TextAnchor.CENTER, 0.0));
        x0 = valueToJava2D(t0, dataArea, edge);
        if (edge == RectangleEdge.TOP) {
            inside = new Line2D.Double(x0, y0, x0, y0 + insideLength);
            outside = new Line2D.Double(x0, y0, x0, y0 - outsideLength);
        }
        else if (edge == RectangleEdge.BOTTOM) {
            inside = new Line2D.Double(x0, y0, x0, y0 - insideLength);
            outside = new Line2D.Double(x0, y0, x0, y0 + outsideLength);
        }
        if (t0 >= firstOnAxis) {
            g2.setPaint(getTickMarkPaint());
            g2.setStroke(getTickMarkStroke());
            g2.draw(inside);
            g2.draw(outside);
        }
        // draw minor tick marks
        if (this.minorTickMarksVisible) {
            RegularTimePeriod tminor = createInstance(
                    this.minorTickTimePeriodClass, new Date(t0),
                    getTimeZone(), this.locale);
            long tt0 = tminor.getFirstMillisecond();
            while (tt0 < t.getLastMillisecond()
                    && tt0 < lastOnAxis) {
                double xx0 = valueToJava2D(tt0, dataArea, edge);
                if (edge == RectangleEdge.TOP) {
                    inside = new Line2D.Double(xx0, y0, xx0,
                            y0 + this.minorTickMarkInsideLength);
                    outside = new Line2D.Double(xx0, y0, xx0,
                            y0 - this.minorTickMarkOutsideLength);
                }
                else if (edge == RectangleEdge.BOTTOM) {
                    inside = new Line2D.Double(xx0, y0, xx0,
                            y0 - this.minorTickMarkInsideLength);
                    outside = new Line2D.Double(xx0, y0, xx0,
                            y0 + this.minorTickMarkOutsideLength);
                }
                if (tt0 >= firstOnAxis) {
                    g2.setPaint(this.minorTickMarkPaint);
                    g2.setStroke(this.minorTickMarkStroke);
                    g2.draw(inside);
                    g2.draw(outside);
                }
                tminor = tminor.next();
                tminor.peg(this.calendar);
                tt0 = tminor.getFirstMillisecond();
            }
        }
        t = t.next();
        t.peg(this.calendar);
        t0 = t.getFirstMillisecond();
    }
    if (edge == RectangleEdge.TOP) {
        state.cursorUp(Math.max(outsideLength,
                this.minorTickMarkOutsideLength));
    }
    else if (edge == RectangleEdge.BOTTOM) {
        state.cursorDown(Math.max(outsideLength,
                this.minorTickMarkOutsideLength));
    }
    state.setTicks(ticks);
}
 
Example 11
Source File: PeriodAxis.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the major and minor tick marks for an axis that lies at the top or
 * bottom of the plot.
 *
 * @param g2  the graphics device.
 * @param state  the axis state.
 * @param dataArea  the data area.
 * @param edge  the edge.
 */
protected void drawTickMarksHorizontal(Graphics2D g2, AxisState state,
        Rectangle2D dataArea, RectangleEdge edge) {
    List ticks = new ArrayList();
    double x0;
    double y0 = state.getCursor();
    double insideLength = getTickMarkInsideLength();
    double outsideLength = getTickMarkOutsideLength();
    RegularTimePeriod t = createInstance(this.majorTickTimePeriodClass, 
            this.first.getStart(), getTimeZone(), this.locale);
    long t0 = t.getFirstMillisecond();
    Line2D inside = null;
    Line2D outside = null;
    long firstOnAxis = getFirst().getFirstMillisecond();
    long lastOnAxis = getLast().getLastMillisecond() + 1;
    while (t0 <= lastOnAxis) {
        ticks.add(new NumberTick(Double.valueOf(t0), "", TextAnchor.CENTER,
                TextAnchor.CENTER, 0.0));
        x0 = valueToJava2D(t0, dataArea, edge);
        if (edge == RectangleEdge.TOP) {
            inside = new Line2D.Double(x0, y0, x0, y0 + insideLength);
            outside = new Line2D.Double(x0, y0, x0, y0 - outsideLength);
        }
        else if (edge == RectangleEdge.BOTTOM) {
            inside = new Line2D.Double(x0, y0, x0, y0 - insideLength);
            outside = new Line2D.Double(x0, y0, x0, y0 + outsideLength);
        }
        if (t0 >= firstOnAxis) {
            g2.setPaint(getTickMarkPaint());
            g2.setStroke(getTickMarkStroke());
            g2.draw(inside);
            g2.draw(outside);
        }
        // draw minor tick marks
        if (this.minorTickMarksVisible) {
            RegularTimePeriod tminor = createInstance(
                    this.minorTickTimePeriodClass, new Date(t0),
                    getTimeZone(), this.locale);
            long tt0 = tminor.getFirstMillisecond();
            while (tt0 < t.getLastMillisecond()
                    && tt0 < lastOnAxis) {
                double xx0 = valueToJava2D(tt0, dataArea, edge);
                if (edge == RectangleEdge.TOP) {
                    inside = new Line2D.Double(xx0, y0, xx0,
                            y0 + this.minorTickMarkInsideLength);
                    outside = new Line2D.Double(xx0, y0, xx0,
                            y0 - this.minorTickMarkOutsideLength);
                }
                else if (edge == RectangleEdge.BOTTOM) {
                    inside = new Line2D.Double(xx0, y0, xx0,
                            y0 - this.minorTickMarkInsideLength);
                    outside = new Line2D.Double(xx0, y0, xx0,
                            y0 + this.minorTickMarkOutsideLength);
                }
                if (tt0 >= firstOnAxis) {
                    g2.setPaint(this.minorTickMarkPaint);
                    g2.setStroke(this.minorTickMarkStroke);
                    g2.draw(inside);
                    g2.draw(outside);
                }
                tminor = tminor.next();
                tminor.peg(this.calendar);
                tt0 = tminor.getFirstMillisecond();
            }
        }
        t = t.next();
        t.peg(this.calendar);
        t0 = t.getFirstMillisecond();
    }
    if (edge == RectangleEdge.TOP) {
        state.cursorUp(Math.max(outsideLength,
                this.minorTickMarkOutsideLength));
    }
    else if (edge == RectangleEdge.BOTTOM) {
        state.cursorDown(Math.max(outsideLength,
                this.minorTickMarkOutsideLength));
    }
    state.setTicks(ticks);
}
 
Example 12
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 13
Source File: PeriodAxis.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the major and minor tick marks for an axis that lies at the top or
 * bottom of the plot.
 *
 * @param g2  the graphics device.
 * @param state  the axis state.
 * @param dataArea  the data area.
 * @param edge  the edge.
 */
protected void drawTickMarksHorizontal(Graphics2D g2, AxisState state,
        Rectangle2D dataArea, RectangleEdge edge) {
    List ticks = new ArrayList();
    double x0;
    double y0 = state.getCursor();
    double insideLength = getTickMarkInsideLength();
    double outsideLength = getTickMarkOutsideLength();
    RegularTimePeriod t = createInstance(this.majorTickTimePeriodClass, 
            this.first.getStart(), getTimeZone(), this.locale);
    long t0 = t.getFirstMillisecond();
    Line2D inside = null;
    Line2D outside = null;
    long firstOnAxis = getFirst().getFirstMillisecond();
    long lastOnAxis = getLast().getLastMillisecond() + 1;
    while (t0 <= lastOnAxis) {
        ticks.add(new NumberTick(Double.valueOf(t0), "", TextAnchor.CENTER,
                TextAnchor.CENTER, 0.0));
        x0 = valueToJava2D(t0, dataArea, edge);
        if (edge == RectangleEdge.TOP) {
            inside = new Line2D.Double(x0, y0, x0, y0 + insideLength);
            outside = new Line2D.Double(x0, y0, x0, y0 - outsideLength);
        }
        else if (edge == RectangleEdge.BOTTOM) {
            inside = new Line2D.Double(x0, y0, x0, y0 - insideLength);
            outside = new Line2D.Double(x0, y0, x0, y0 + outsideLength);
        }
        if (t0 >= firstOnAxis) {
            g2.setPaint(getTickMarkPaint());
            g2.setStroke(getTickMarkStroke());
            g2.draw(inside);
            g2.draw(outside);
        }
        // draw minor tick marks
        if (this.minorTickMarksVisible) {
            RegularTimePeriod tminor = createInstance(
                    this.minorTickTimePeriodClass, new Date(t0),
                    getTimeZone(), this.locale);
            long tt0 = tminor.getFirstMillisecond();
            while (tt0 < t.getLastMillisecond()
                    && tt0 < lastOnAxis) {
                double xx0 = valueToJava2D(tt0, dataArea, edge);
                if (edge == RectangleEdge.TOP) {
                    inside = new Line2D.Double(xx0, y0, xx0,
                            y0 + this.minorTickMarkInsideLength);
                    outside = new Line2D.Double(xx0, y0, xx0,
                            y0 - this.minorTickMarkOutsideLength);
                }
                else if (edge == RectangleEdge.BOTTOM) {
                    inside = new Line2D.Double(xx0, y0, xx0,
                            y0 - this.minorTickMarkInsideLength);
                    outside = new Line2D.Double(xx0, y0, xx0,
                            y0 + this.minorTickMarkOutsideLength);
                }
                if (tt0 >= firstOnAxis) {
                    g2.setPaint(this.minorTickMarkPaint);
                    g2.setStroke(this.minorTickMarkStroke);
                    g2.draw(inside);
                    g2.draw(outside);
                }
                tminor = tminor.next();
                tminor.peg(this.calendar);
                tt0 = tminor.getFirstMillisecond();
            }
        }
        t = t.next();
        t.peg(this.calendar);
        t0 = t.getFirstMillisecond();
    }
    if (edge == RectangleEdge.TOP) {
        state.cursorUp(Math.max(outsideLength,
                this.minorTickMarkOutsideLength));
    }
    else if (edge == RectangleEdge.BOTTOM) {
        state.cursorDown(Math.max(outsideLength,
                this.minorTickMarkOutsideLength));
    }
    state.setTicks(ticks);
}
 
Example 14
Source File: PeriodAxis.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the major and minor tick marks for an axis that lies at the top or
 * bottom of the plot.
 *
 * @param g2  the graphics device.
 * @param state  the axis state.
 * @param dataArea  the data area.
 * @param edge  the edge.
 */
protected void drawTickMarksHorizontal(Graphics2D g2, AxisState state,
        Rectangle2D dataArea, RectangleEdge edge) {
    List ticks = new ArrayList();
    double x0;
    double y0 = state.getCursor();
    double insideLength = getTickMarkInsideLength();
    double outsideLength = getTickMarkOutsideLength();
    RegularTimePeriod t = createInstance(this.majorTickTimePeriodClass, 
            this.first.getStart(), getTimeZone(), this.locale);
    long t0 = t.getFirstMillisecond();
    Line2D inside = null;
    Line2D outside = null;
    long firstOnAxis = getFirst().getFirstMillisecond();
    long lastOnAxis = getLast().getLastMillisecond() + 1;
    while (t0 <= lastOnAxis) {
        ticks.add(new NumberTick(Double.valueOf(t0), "", TextAnchor.CENTER,
                TextAnchor.CENTER, 0.0));
        x0 = valueToJava2D(t0, dataArea, edge);
        if (edge == RectangleEdge.TOP) {
            inside = new Line2D.Double(x0, y0, x0, y0 + insideLength);
            outside = new Line2D.Double(x0, y0, x0, y0 - outsideLength);
        }
        else if (edge == RectangleEdge.BOTTOM) {
            inside = new Line2D.Double(x0, y0, x0, y0 - insideLength);
            outside = new Line2D.Double(x0, y0, x0, y0 + outsideLength);
        }
        if (t0 >= firstOnAxis) {
            g2.setPaint(getTickMarkPaint());
            g2.setStroke(getTickMarkStroke());
            g2.draw(inside);
            g2.draw(outside);
        }
        // draw minor tick marks
        if (this.minorTickMarksVisible) {
            RegularTimePeriod tminor = createInstance(
                    this.minorTickTimePeriodClass, new Date(t0),
                    getTimeZone(), this.locale);
            long tt0 = tminor.getFirstMillisecond();
            while (tt0 < t.getLastMillisecond()
                    && tt0 < lastOnAxis) {
                double xx0 = valueToJava2D(tt0, dataArea, edge);
                if (edge == RectangleEdge.TOP) {
                    inside = new Line2D.Double(xx0, y0, xx0,
                            y0 + this.minorTickMarkInsideLength);
                    outside = new Line2D.Double(xx0, y0, xx0,
                            y0 - this.minorTickMarkOutsideLength);
                }
                else if (edge == RectangleEdge.BOTTOM) {
                    inside = new Line2D.Double(xx0, y0, xx0,
                            y0 - this.minorTickMarkInsideLength);
                    outside = new Line2D.Double(xx0, y0, xx0,
                            y0 + this.minorTickMarkOutsideLength);
                }
                if (tt0 >= firstOnAxis) {
                    g2.setPaint(this.minorTickMarkPaint);
                    g2.setStroke(this.minorTickMarkStroke);
                    g2.draw(inside);
                    g2.draw(outside);
                }
                tminor = tminor.next();
                tminor.peg(this.calendar);
                tt0 = tminor.getFirstMillisecond();
            }
        }
        t = t.next();
        t.peg(this.calendar);
        t0 = t.getFirstMillisecond();
    }
    if (edge == RectangleEdge.TOP) {
        state.cursorUp(Math.max(outsideLength,
                this.minorTickMarkOutsideLength));
    }
    else if (edge == RectangleEdge.BOTTOM) {
        state.cursorDown(Math.max(outsideLength,
                this.minorTickMarkOutsideLength));
    }
    state.setTicks(ticks);
}
 
Example 15
Source File: TimeSeriesBuilderTest.java    From OpenForecast with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Tests the correct input of a DataSet from a TimeSeries by creating a
 * simple TimeSeries object then inputting it using a TimeSeriesBuilder
 * instance.
 */
public void testBuilder()
{
    // Constants used to determine size of test
    int NUMBER_OF_TIME_PERIODS = 100;
    
    // Set up array for expected results
    double expectedValue[] = new double[ NUMBER_OF_TIME_PERIODS ];
    
    // Create test TimeSeries
    TimeSeries timeSeries = new TimeSeries("Simple time series");
    RegularTimePeriod period = new Day();
    
    for ( int d=0; d<NUMBER_OF_TIME_PERIODS; d++ )
        {
            expectedValue[d] = d;
            timeSeries.add(period,d);
            period = period.next();
        }
    
    // Create TimeSeriesBuilder and use it to create the DataSet
    String TIME_VARIABLE = "t";
    TimeSeriesBuilder builder
        = new TimeSeriesBuilder( timeSeries, TIME_VARIABLE );
    DataSet dataSet = builder.build();
    
    // Verify data set contains the correct number of entries
    assertEquals( "DataSet created is of the wrong size",
                  NUMBER_OF_TIME_PERIODS, dataSet.size() );
    
    // Vefify that only two independent variable names are reported
    String[] independentVariables = dataSet.getIndependentVariables();
    assertEquals( "Checking the correct number of independent variables",
                  1, independentVariables.length );
    assertEquals( "Independent variable not set as expected",
                  TIME_VARIABLE, independentVariables[0] );
    
    // Check the data points in the data set. This may not be a good
    //  test since it is dependent on the order of the data points in
    //  the 2-d array
    checkResults( dataSet, expectedValue );
}
 
Example 16
Source File: PeriodAxis.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * Draws the major and minor tick marks for an axis that lies at the top or
 * bottom of the plot.
 *
 * @param g2  the graphics device.
 * @param state  the axis state.
 * @param dataArea  the data area.
 * @param edge  the edge.
 */
protected void drawTickMarksHorizontal(Graphics2D g2, AxisState state,
        Rectangle2D dataArea, RectangleEdge edge) {
    List ticks = new ArrayList();
    double x0;
    double y0 = state.getCursor();
    double insideLength = getTickMarkInsideLength();
    double outsideLength = getTickMarkOutsideLength();
    RegularTimePeriod t = createInstance(this.majorTickTimePeriodClass, 
            this.first.getStart(), getTimeZone(), this.locale);
    long t0 = t.getFirstMillisecond();
    Line2D inside = null;
    Line2D outside = null;
    long firstOnAxis = getFirst().getFirstMillisecond();
    long lastOnAxis = getLast().getLastMillisecond() + 1;
    while (t0 <= lastOnAxis) {
        ticks.add(new NumberTick(Double.valueOf(t0), "", TextAnchor.CENTER,
                TextAnchor.CENTER, 0.0));
        x0 = valueToJava2D(t0, dataArea, edge);
        if (edge == RectangleEdge.TOP) {
            inside = new Line2D.Double(x0, y0, x0, y0 + insideLength);
            outside = new Line2D.Double(x0, y0, x0, y0 - outsideLength);
        }
        else if (edge == RectangleEdge.BOTTOM) {
            inside = new Line2D.Double(x0, y0, x0, y0 - insideLength);
            outside = new Line2D.Double(x0, y0, x0, y0 + outsideLength);
        }
        if (t0 >= firstOnAxis) {
            g2.setPaint(getTickMarkPaint());
            g2.setStroke(getTickMarkStroke());
            g2.draw(inside);
            g2.draw(outside);
        }
        // draw minor tick marks
        if (this.minorTickMarksVisible) {
            RegularTimePeriod tminor = createInstance(
                    this.minorTickTimePeriodClass, new Date(t0),
                    getTimeZone(), this.locale);
            long tt0 = tminor.getFirstMillisecond();
            while (tt0 < t.getLastMillisecond()
                    && tt0 < lastOnAxis) {
                double xx0 = valueToJava2D(tt0, dataArea, edge);
                if (edge == RectangleEdge.TOP) {
                    inside = new Line2D.Double(xx0, y0, xx0,
                            y0 + this.minorTickMarkInsideLength);
                    outside = new Line2D.Double(xx0, y0, xx0,
                            y0 - this.minorTickMarkOutsideLength);
                }
                else if (edge == RectangleEdge.BOTTOM) {
                    inside = new Line2D.Double(xx0, y0, xx0,
                            y0 - this.minorTickMarkInsideLength);
                    outside = new Line2D.Double(xx0, y0, xx0,
                            y0 + this.minorTickMarkOutsideLength);
                }
                if (tt0 >= firstOnAxis) {
                    g2.setPaint(this.minorTickMarkPaint);
                    g2.setStroke(this.minorTickMarkStroke);
                    g2.draw(inside);
                    g2.draw(outside);
                }
                tminor = tminor.next();
                tminor.peg(this.calendar);
                tt0 = tminor.getFirstMillisecond();
            }
        }
        t = t.next();
        t.peg(this.calendar);
        t0 = t.getFirstMillisecond();
    }
    if (edge == RectangleEdge.TOP) {
        state.cursorUp(Math.max(outsideLength,
                this.minorTickMarkOutsideLength));
    }
    else if (edge == RectangleEdge.BOTTOM) {
        state.cursorDown(Math.max(outsideLength,
                this.minorTickMarkOutsideLength));
    }
    state.setTicks(ticks);
}
 
Example 17
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 18
Source File: PeriodAxis.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the major and minor tick marks for an axis that lies at the top or
 * bottom of the plot.
 *
 * @param g2  the graphics device.
 * @param state  the axis state.
 * @param dataArea  the data area.
 * @param edge  the edge.
 */
protected void drawTickMarksHorizontal(Graphics2D g2, AxisState state,
        Rectangle2D dataArea, RectangleEdge edge) {
    List ticks = new ArrayList();
    double x0;
    double y0 = state.getCursor();
    double insideLength = getTickMarkInsideLength();
    double outsideLength = getTickMarkOutsideLength();
    RegularTimePeriod t = createInstance(this.majorTickTimePeriodClass, 
            this.first.getStart(), getTimeZone(), this.locale);
    long t0 = t.getFirstMillisecond();
    Line2D inside = null;
    Line2D outside = null;
    long firstOnAxis = getFirst().getFirstMillisecond();
    long lastOnAxis = getLast().getLastMillisecond() + 1;
    while (t0 <= lastOnAxis) {
        ticks.add(new NumberTick(Double.valueOf(t0), "", TextAnchor.CENTER,
                TextAnchor.CENTER, 0.0));
        x0 = valueToJava2D(t0, dataArea, edge);
        if (edge == RectangleEdge.TOP) {
            inside = new Line2D.Double(x0, y0, x0, y0 + insideLength);
            outside = new Line2D.Double(x0, y0, x0, y0 - outsideLength);
        }
        else if (edge == RectangleEdge.BOTTOM) {
            inside = new Line2D.Double(x0, y0, x0, y0 - insideLength);
            outside = new Line2D.Double(x0, y0, x0, y0 + outsideLength);
        }
        if (t0 >= firstOnAxis) {
            g2.setPaint(getTickMarkPaint());
            g2.setStroke(getTickMarkStroke());
            g2.draw(inside);
            g2.draw(outside);
        }
        // draw minor tick marks
        if (this.minorTickMarksVisible) {
            RegularTimePeriod tminor = createInstance(
                    this.minorTickTimePeriodClass, new Date(t0),
                    getTimeZone(), this.locale);
            long tt0 = tminor.getFirstMillisecond();
            while (tt0 < t.getLastMillisecond()
                    && tt0 < lastOnAxis) {
                double xx0 = valueToJava2D(tt0, dataArea, edge);
                if (edge == RectangleEdge.TOP) {
                    inside = new Line2D.Double(xx0, y0, xx0,
                            y0 + this.minorTickMarkInsideLength);
                    outside = new Line2D.Double(xx0, y0, xx0,
                            y0 - this.minorTickMarkOutsideLength);
                }
                else if (edge == RectangleEdge.BOTTOM) {
                    inside = new Line2D.Double(xx0, y0, xx0,
                            y0 - this.minorTickMarkInsideLength);
                    outside = new Line2D.Double(xx0, y0, xx0,
                            y0 + this.minorTickMarkOutsideLength);
                }
                if (tt0 >= firstOnAxis) {
                    g2.setPaint(this.minorTickMarkPaint);
                    g2.setStroke(this.minorTickMarkStroke);
                    g2.draw(inside);
                    g2.draw(outside);
                }
                tminor = tminor.next();
                tminor.peg(this.calendar);
                tt0 = tminor.getFirstMillisecond();
            }
        }
        t = t.next();
        t.peg(this.calendar);
        t0 = t.getFirstMillisecond();
    }
    if (edge == RectangleEdge.TOP) {
        state.cursorUp(Math.max(outsideLength,
                this.minorTickMarkOutsideLength));
    }
    else if (edge == RectangleEdge.BOTTOM) {
        state.cursorDown(Math.max(outsideLength,
                this.minorTickMarkOutsideLength));
    }
    state.setTicks(ticks);
}
 
Example 19
Source File: PeriodAxis.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the major and minor tick marks for an axis that lies at the top or
 * bottom of the plot.
 *
 * @param g2  the graphics device.
 * @param state  the axis state.
 * @param dataArea  the data area.
 * @param edge  the edge.
 */
protected void drawTickMarksHorizontal(Graphics2D g2, AxisState state,
        Rectangle2D dataArea, RectangleEdge edge) {
    List ticks = new ArrayList();
    double x0;
    double y0 = state.getCursor();
    double insideLength = getTickMarkInsideLength();
    double outsideLength = getTickMarkOutsideLength();
    RegularTimePeriod t = createInstance(this.majorTickTimePeriodClass, 
            this.first.getStart(), getTimeZone(), this.locale);
    long t0 = t.getFirstMillisecond();
    Line2D inside = null;
    Line2D outside = null;
    long firstOnAxis = getFirst().getFirstMillisecond();
    long lastOnAxis = getLast().getLastMillisecond() + 1;
    while (t0 <= lastOnAxis) {
        ticks.add(new NumberTick(Double.valueOf(t0), "", TextAnchor.CENTER,
                TextAnchor.CENTER, 0.0));
        x0 = valueToJava2D(t0, dataArea, edge);
        if (edge == RectangleEdge.TOP) {
            inside = new Line2D.Double(x0, y0, x0, y0 + insideLength);
            outside = new Line2D.Double(x0, y0, x0, y0 - outsideLength);
        }
        else if (edge == RectangleEdge.BOTTOM) {
            inside = new Line2D.Double(x0, y0, x0, y0 - insideLength);
            outside = new Line2D.Double(x0, y0, x0, y0 + outsideLength);
        }
        if (t0 >= firstOnAxis) {
            g2.setPaint(getTickMarkPaint());
            g2.setStroke(getTickMarkStroke());
            g2.draw(inside);
            g2.draw(outside);
        }
        // draw minor tick marks
        if (this.minorTickMarksVisible) {
            RegularTimePeriod tminor = createInstance(
                    this.minorTickTimePeriodClass, new Date(t0),
                    getTimeZone(), this.locale);
            long tt0 = tminor.getFirstMillisecond();
            while (tt0 < t.getLastMillisecond()
                    && tt0 < lastOnAxis) {
                double xx0 = valueToJava2D(tt0, dataArea, edge);
                if (edge == RectangleEdge.TOP) {
                    inside = new Line2D.Double(xx0, y0, xx0,
                            y0 + this.minorTickMarkInsideLength);
                    outside = new Line2D.Double(xx0, y0, xx0,
                            y0 - this.minorTickMarkOutsideLength);
                }
                else if (edge == RectangleEdge.BOTTOM) {
                    inside = new Line2D.Double(xx0, y0, xx0,
                            y0 - this.minorTickMarkInsideLength);
                    outside = new Line2D.Double(xx0, y0, xx0,
                            y0 + this.minorTickMarkOutsideLength);
                }
                if (tt0 >= firstOnAxis) {
                    g2.setPaint(this.minorTickMarkPaint);
                    g2.setStroke(this.minorTickMarkStroke);
                    g2.draw(inside);
                    g2.draw(outside);
                }
                tminor = tminor.next();
                tminor.peg(this.calendar);
                tt0 = tminor.getFirstMillisecond();
            }
        }
        t = t.next();
        t.peg(this.calendar);
        t0 = t.getFirstMillisecond();
    }
    if (edge == RectangleEdge.TOP) {
        state.cursorUp(Math.max(outsideLength,
                this.minorTickMarkOutsideLength));
    }
    else if (edge == RectangleEdge.BOTTOM) {
        state.cursorDown(Math.max(outsideLength,
                this.minorTickMarkOutsideLength));
    }
    state.setTicks(ticks);
}
 
Example 20
Source File: TestMultipleAxisChart.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Creates the demo chart.
 *
 * @return The chart.
 *
 *         private JFreeChart createChart() {
 * 
 *         XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(), 200);
 * 
 *         JFreeChart chart = ChartFactory.createTimeSeriesChart(
 *         "Multiple Axis Demo 1",
 *         "Time of Day",
 *         "Primary Range Axis",
 *         dataset1,
 *         true,
 *         true,
 *         false
 *         );
 * 
 *         chart.addSubtitle(new TextTitle("Four datasets and four range axes."));
 *         XYPlot plot = (XYPlot) chart.getPlot();
 *         plot.setOrientation(PlotOrientation.VERTICAL);
 * 
 *         plot.getRangeAxis().setFixedDimension(15.0);
 * 
 *         // AXIS 2
 *         NumberAxis axis2 = new NumberAxis("Range Axis 2");
 *         axis2.setFixedDimension(10.0);
 *         axis2.setAutoRangeIncludesZero(false);
 *         plot.setRangeAxis(1, axis2);
 *         plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);
 * 
 *         XYDataset dataset2 = createDataset("Series 2", 1000.0, new Minute(),
 *         170);
 *         plot.setDataset(1, dataset2);
 *         plot.mapDatasetToRangeAxis(1, 1);
 *         XYItemRenderer renderer2 = new StandardXYItemRenderer();
 *         plot.setRenderer(1, renderer2);
 * 
 *         // AXIS 3
 *         NumberAxis axis3 = new NumberAxis("Range Axis 3");
 *         plot.setRangeAxis(2, axis3);
 * 
 *         XYDataset dataset3 = createDataset("Series 3", 10000.0, new Minute(),
 *         170);
 *         plot.setDataset(2, dataset3);
 *         plot.mapDatasetToRangeAxis(2, 2);
 *         XYItemRenderer renderer3 = new StandardXYItemRenderer();
 *         plot.setRenderer(2, renderer3);
 * 
 *         // AXIS 4
 *         NumberAxis axis4 = new NumberAxis("Range Axis 4");
 *         plot.setRangeAxis(3, axis4);
 * 
 *         XYDataset dataset4 = createDataset("Series 4", 25.0, new Minute(), 200);
 *         plot.setDataset(3, dataset4);
 *         plot.mapDatasetToRangeAxis(3, 3);
 * 
 *         XYItemRenderer renderer4 = new StandardXYItemRenderer();
 *         plot.setRenderer(3, renderer4);
 * 
 *         ChartUtilities.applyCurrentTheme(chart);
 * 
 *         // change the series and axis colours after the theme has
 *         // been applied...
 *         plot.getRenderer().setSeriesPaint(0, Color.black);
 *         renderer2.setSeriesPaint(0, Color.red);
 *         axis2.setLabelPaint(Color.red);
 *         axis2.setTickLabelPaint(Color.red);
 *         renderer3.setSeriesPaint(0, Color.blue);
 *         axis3.setLabelPaint(Color.blue);
 *         axis3.setTickLabelPaint(Color.blue);
 *         renderer4.setSeriesPaint(0, Color.green);
 *         axis4.setLabelPaint(Color.green);
 *         axis4.setTickLabelPaint(Color.green);
 * 
 *         return chart;
 *         }
 * 
 *         /**
 *         Creates a sample dataset.
 *
 * @param name the dataset name.
 * @param base the starting value.
 * @param start the starting period.
 * @param count the number of values to generate.
 */
private static TimeSeries createDataset(String name, double base, RegularTimePeriod start, int count) {

  TimeSeries series = new TimeSeries(name, start.getClass());
  RegularTimePeriod period = start;
  double value = base;
  for (int i = 0; i < count; i++) {
    series.add(period, value);
    period = period.next();
    value = value * (1 + (Math.random() - 0.495) / 10.0);
  }
  return series;
}