List of usage examples for org.jfree.data.time TimeSeries getTimePeriodClass
public Class getTimePeriodClass()
From source file:org.jfree.data.time.junit.TimeSeriesTest.java
/** * Test that the addOrUpdate() method won't allow multiple time period * classes.//from w w w .j a va 2s . c om */ 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.TimeSeriesTest.java
/** * Test that the addOrUpdate() method won't allow multiple time period * classes./*from w w w . jav a 2s . c o m*/ */ @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.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.ChartHelper.java
/*********************************************************************************************** * Create a dummy TimeSeriesDataItem at the origin of the Domain. * * @param timeseriescollection/*from w w w . j a v a 2 s. c o m*/ * @param timeseries * @param domainstart * @param debug * * @return TimeSeriesDataItem */ public static TimeSeriesDataItem createDummyTimeSeriesDataItemAtOrigin( final TimeSeriesCollection timeseriescollection, final TimeSeries timeseries, final int domainstart, final boolean debug) { final String SOURCE = "ChartHelper.createDummyTimeSeriesDataItemAtOrigin() [domainstart=" + domainstart + "]"; LOGGER.debug(debug, SOURCE); return new TimeSeriesDataItem( RegularTimePeriod.createInstance(timeseries.getTimePeriodClass(), new Date(calculateDomainSliderMillis(ChartUIComponentPlugin.DOMAIN_SLIDER_MINIMUM, ChartUIComponentPlugin.DOMAIN_SLIDER_MAXIMUM, domainstart, timeseriescollection.getDomainLowerBound(true), timeseriescollection.getDomainUpperBound(true), debug)), TimeZone.getDefault()), timeseries.getMinY()); }
From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.ChartHelper.java
/*********************************************************************************************** * Preserve, Truncate or Decimate an XYDataset to try to achieve the requested display limit. * Decimation requested overrides all other modes. * Transform the dataset in accordance with the ChannelSelection Modes. * TRUNCATE is not currently used.// ww w . j a v a 2 s .c o m * * ChartUpdate isdecimated Outcome * * PRESERVE N Always PRESERVE, don't use displaylimit * Y ditto * * DECIMATE N Do same as PRESERVE * Y Skip enough to leave displaylimit * * TRUNCATE N Use only displaylimit, ignore isdecimated * Y ditto * * * @param dataset * @param timezone * @param chartupdatetype * @param displaylimit * @param isdecimated * @param selectionmodes * * @return XYDataset */ private static XYDataset copyTransformedXYDataset(final XYDataset dataset, final TimeZone timezone, final DataUpdateType chartupdatetype, final int displaylimit, final boolean isdecimated, final List<ChannelSelectionMode> selectionmodes) { final String SOURCE = "ChartHelper.copyTransformedXYDataset() "; final DataUpdateType updateTypeToTransform; final XYDataset xyResult; // If decimation is NOT requested by the user for a DECIMATE chart then just do PRESERVE // Otherwise do exactly as the Chart configuration requests if ((DataUpdateType.DECIMATE.equals(chartupdatetype)) && (!isdecimated)) { updateTypeToTransform = DataUpdateType.PRESERVE; } else { updateTypeToTransform = chartupdatetype; } // System.out.println(SOURCE + "displaylimit=" + displaylimit // + " isdecimated=" + isdecimated // + " chartupdatetype=" + chartupdatetype.getName() // + " updateTypeToTransform=" + updateTypeToTransform.getName()); //----------------------------------------------------------------------------------------- // Use the whole dataset immediately if requested if (DataUpdateType.PRESERVE.equals(updateTypeToTransform)) { //System.out.println(SOURCE + "Preserve whole dataset"); xyResult = dataset; return (xyResult); } //----------------------------------------------------------------------------------------- // Now do the transformation: TRUNCATE or DECIMATE if (dataset instanceof TimeSeriesCollection) { xyResult = new TimeSeriesCollection(timezone); // Process each Series in turn for (int intSeriesIndex = 0; intSeriesIndex < dataset.getSeriesCount(); intSeriesIndex++) { final TimeSeries timeSeriesInput; final TimeSeries timeSeriesOutput; timeSeriesInput = ((TimeSeriesCollection) dataset).getSeries(intSeriesIndex); // Make a TimeSeries based on Seconds... // whose name is the ChannelName timeSeriesOutput = new TimeSeries(timeSeriesInput.getKey(), timeSeriesInput.getTimePeriodClass()); switch (updateTypeToTransform) { case TRUNCATE: { final int intStart; //System.out.println("truncate time series"); if (timeSeriesInput.getItemCount() > displaylimit) { intStart = timeSeriesInput.getItemCount() - displaylimit; } else { intStart = 0; } // Modify each Series in exactly the same way! // timeSeriesOutput = timeSeriesInput.createCopy(intStart, timeSeriesInput.getItemCount()-1); for (int item = intStart; item < timeSeriesInput.getItemCount(); item++) { timeSeriesOutput.add(timeSeriesInput.getDataItem(item)); } break; } case DECIMATE: { final int intSkipCount; //System.out.println("decimate time series index=" + intSeriesIndex); if (timeSeriesInput.getItemCount() > displaylimit) { intSkipCount = (timeSeriesInput.getItemCount() / displaylimit) - 1; } else { // Show all of the data items, i.e. insufficient data to decimate intSkipCount = 0; } for (int item = 0; item < timeSeriesInput.getItemCount(); item = item + intSkipCount + 1) { timeSeriesOutput.add(timeSeriesInput.getDataItem(item)); } break; } default: { LOGGER.error(SOURCE + MSG_UNSUPPORTED_UPDATE_TYPE); } } // Accumulate each Series in the output ((TimeSeriesCollection) xyResult).addSeries(timeSeriesOutput); } } else if (dataset instanceof XYSeriesCollection) { xyResult = new XYSeriesCollection(); //System.out.println(SOURCE + "XYSeriesCollection for " + displaylimit + " samples"); // Process each Series in turn for (int intSeriesIndex = 0; intSeriesIndex < dataset.getSeriesCount(); intSeriesIndex++) { final XYSeries xySeriesInput; final XYSeries xySeriesOutput; xySeriesInput = ((XYSeriesCollection) dataset).getSeries(intSeriesIndex); xySeriesOutput = new XYSeries(dataset.getSeriesKey(intSeriesIndex)); switch (updateTypeToTransform) { case TRUNCATE: { final int intStart; //System.out.println("truncate xy"); if (xySeriesInput.getItemCount() > displaylimit) { intStart = xySeriesInput.getItemCount() - displaylimit; } else { intStart = 0; } // Modify each Series in exactly the same way! // xySeriesOutput = xySeriesInput.createCopy(intStart, xySeriesInput.getItemCount()-1); for (int item = intStart; item < xySeriesInput.getItemCount(); item++) { xySeriesOutput.add(xySeriesInput.getDataItem(item)); } break; } case DECIMATE: { final int intSkipCount; //System.out.println("decimate xy series index=" + intSeriesIndex); if (xySeriesInput.getItemCount() > displaylimit) { intSkipCount = (xySeriesInput.getItemCount() / displaylimit) - 1; } else { // Show all of the data items, i.e. insufficient data to decimate intSkipCount = 0; } for (int item = 0; item < xySeriesInput.getItemCount(); item = item + intSkipCount + 1) { xySeriesOutput.add(xySeriesInput.getDataItem(item)); } break; } default: { LOGGER.error(SOURCE + MSG_UNSUPPORTED_UPDATE_TYPE); } } // Accumulate each Series in the output ((XYSeriesCollection) xyResult).addSeries(xySeriesOutput); } } else { LOGGER.error(SOURCE + "Unsupported XYDataset type"); xyResult = new XYSeriesCollection(); } return (xyResult); }
From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.ChartHelper.java
/*********************************************************************************************** * Dump the (partial) contents of each Series in an XYdatset. * * @param dump// w ww . j ava 2s . c o m * @param calendar * @param dataset * @param dumprowcount * @param title */ public static void dumpXYDataset(final boolean dump, final Calendar calendar, final XYDataset dataset, final int dumprowcount, final String title) { final String SOURCE = "ChartHelper.dumpXYDataset() "; if (dump) { LOGGER.log(title); if ((dataset != null) && (dataset instanceof XYSeriesCollection)) { final XYSeriesCollection seriesCollection; seriesCollection = (XYSeriesCollection) dataset; LOGGER.log("XYSeriesCollection"); LOGGER.log(" [series.count=" + seriesCollection.getSeriesCount() + "]"); LOGGER.log(" [domain.lowerbound.interval.true=" + (long) seriesCollection.getDomainLowerBound(true) + "]"); LOGGER.log(" [domain.lowerbound.interval.false=" + (long) seriesCollection.getDomainLowerBound(false) + "]"); LOGGER.log(" [domain.upperbound.interval.true=" + (long) seriesCollection.getDomainUpperBound(true) + "]"); LOGGER.log(" [domain.upperbound.interval.false=" + (long) seriesCollection.getDomainUpperBound(false) + "]"); LOGGER.log(" [domain.order=" + seriesCollection.getDomainOrder() + "]"); for (int intSeriesIndex = 0; intSeriesIndex < seriesCollection.getSeriesCount(); intSeriesIndex++) { final XYSeries xySeries; LOGGER.log(""); LOGGER.log(" [xyseries.index=" + intSeriesIndex + "]"); xySeries = seriesCollection.getSeries(intSeriesIndex); LOGGER.log(" [xyseries.itemcount=" + xySeries.getItemCount() + "]"); LOGGER.log(" [xyseries.key=" + xySeries.getKey() + "]"); LOGGER.log(" [xyseries.xmin=" + xySeries.getMinX() + "]"); LOGGER.log(" [xyseries.xmax=" + xySeries.getMaxX() + "]"); LOGGER.log(" [xyseries.ymin=" + xySeries.getMinY() + "]"); LOGGER.log(" [xyseries.ymax=" + xySeries.getMaxY() + "]"); LOGGER.log(" [xyseries.description=" + xySeries.getDescription() + "]"); LOGGER.log(" [xyseries.autosort=" + xySeries.getAutoSort() + "]"); LOGGER.log(" [xyseries.allowduplicatex=" + xySeries.getAllowDuplicateXValues() + "]"); // Dump the first chunk for (int intItemIndex = 0; intItemIndex < (Math.min(dumprowcount, xySeries.getItemCount())); intItemIndex++) { final XYDataItem item; item = xySeries.getDataItem(intItemIndex); LOGGER.log(" [item.index=" + intItemIndex + "] [item.x=" + item.getXValue() + "] [item.y=" + item.getYValue() + "]"); } LOGGER.log(" ..."); // Dump the last chunk for (int intItemIndex = 0; intItemIndex < (Math.min(dumprowcount, xySeries.getItemCount())); intItemIndex++) { final XYDataItem item; final int intIndex; intIndex = Math.max(0, xySeries.getItemCount() - dumprowcount) + intItemIndex; item = xySeries.getDataItem(intIndex); LOGGER.log(" [item.index=" + intIndex + "] [item.x=" + item.getXValue() + "] [item.y=" + item.getYValue() + "]"); } } } else if ((dataset != null) && (dataset instanceof TimeSeriesCollection)) { final TimeSeriesCollection seriesCollection; seriesCollection = (TimeSeriesCollection) dataset; LOGGER.log("TimeSeriesCollection"); LOGGER.log(" [series.count=" + seriesCollection.getSeriesCount() + "]"); LOGGER.log(" [domain.lowerbound.interval.true=" + (long) seriesCollection.getDomainLowerBound(true) + "]"); LOGGER.log(" [domain.lowerbound.interval.false=" + (long) seriesCollection.getDomainLowerBound(false) + "]"); LOGGER.log(" [domain.upperbound.interval.true=" + (long) seriesCollection.getDomainUpperBound(true) + "]"); LOGGER.log(" [domain.upperbound.interval.false=" + (long) seriesCollection.getDomainUpperBound(false) + "]"); LOGGER.log(" [domain.order=" + seriesCollection.getDomainOrder() + "]"); for (int intSeriesIndex = 0; intSeriesIndex < seriesCollection.getSeriesCount(); intSeriesIndex++) { final TimeSeries timeSeries; LOGGER.log(""); LOGGER.log(" [timeseries.index=" + intSeriesIndex + "]"); timeSeries = seriesCollection.getSeries(intSeriesIndex); LOGGER.log(" [timeseries.itemcount=" + timeSeries.getItemCount() + "]"); LOGGER.log(" [timeseries.key=" + timeSeries.getKey() + "]"); LOGGER.log(" [timeseries.ymin=" + timeSeries.getMinY() + "]"); LOGGER.log(" [timeseries.ymax=" + timeSeries.getMaxY() + "]"); LOGGER.log(" [timeseries.domain=" + timeSeries.getDomainDescription() + "]"); LOGGER.log(" [timeseries.range=" + timeSeries.getRangeDescription() + "]"); LOGGER.log( " [timeseries.timeperiodclass=" + timeSeries.getTimePeriodClass().getName() + "]"); for (int intItemIndex = 0; intItemIndex < (Math.min(dumprowcount, timeSeries.getItemCount())); intItemIndex++) { final TimeSeriesDataItem item; item = timeSeries.getDataItem(intItemIndex); LOGGER.log(" [item.index=" + intItemIndex + "] [item.period.serialindex=" + item.getPeriod().getSerialIndex() + "] [item.period.firstmillis=" + item.getPeriod().getFirstMillisecond(calendar) + "] [item.value=" + item.getValue() + "]"); } LOGGER.log(" ..."); for (int intItemIndex = 0; intItemIndex < (Math.min(dumprowcount, timeSeries.getItemCount())); intItemIndex++) { final TimeSeriesDataItem item; final int intIndex; intIndex = Math.max(0, timeSeries.getItemCount() - dumprowcount) + intItemIndex; item = timeSeries.getDataItem(intIndex); LOGGER.log(" [item.index=" + intIndex + "] [item.period.serialindex=" + item.getPeriod().getSerialIndex() + "] [item.period.firstmillis=" + item.getPeriod().getFirstMillisecond(calendar) + "] [item.value=" + item.getValue() + "]"); } } } else { LOGGER.error(SOURCE + "Unsupported XYDataset type"); } } }