/** * 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()); }
/** * Tests the equals() method. */ public void testEquals() { TimePeriodValuesCollection c1 = new TimePeriodValuesCollection(); TimePeriodValuesCollection c2 = new TimePeriodValuesCollection(); assertTrue(c1.equals(c2)); c1.setDomainIsPointsInTime(!c1.getDomainIsPointsInTime()); assertFalse(c1.equals(c2)); c2.setDomainIsPointsInTime(c1.getDomainIsPointsInTime()); 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)); }
@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; }
/** * Resets the display. */ @Override void resetUI() { super.resetUI(); XYPlot xyPlot = mChart.getXYPlot(); AbstractXYItemRenderer br = new XYBarRenderer(); mDatasetsSyncHist = new TimePeriodValues[NUM_AUTHS+1]; @SuppressWarnings("unchecked") Map<SimpleTimePeriod, Integer> mTimePeriodMapTmp[] = new HashMap[NUM_AUTHS + 1]; mTimePeriodMap = mTimePeriodMapTmp; TimePeriodValuesCollection tpvc = new TimePeriodValuesCollection(); xyPlot.setDataset(tpvc); xyPlot.setRenderer(br); for (int i = 0; i < NUM_AUTHS + 1; i++) { br.setSeriesPaint(i, AUTH_COLORS[i]); mDatasetsSyncHist[i] = new TimePeriodValues(AUTH_NAMES[i]); tpvc.addSeries(mDatasetsSyncHist[i]); mTimePeriodMap[i] = new HashMap<SimpleTimePeriod, Integer>(); } }
/** * 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)); }
/** * 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); }
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; }
@Override public String generateLabel(XYDataset dataset, int series, int item) { Comparable<?> seriesName = dataset.getSeriesKey(series); Map<TimePeriod, String> labels = labelsMap.get(seriesName); if(labels != null) { return labels.get(((TimePeriodValuesCollection)dataset).getSeries(series).getTimePeriod(item)); } return super.generateLabel( dataset, series, item ); }
@Override public Dataset getCustomDataset() { TimePeriodValuesCollection dataset = new TimePeriodValuesCollection(); if (seriesNames != null) { for(int i = 0; i < seriesNames.size(); i++) { Comparable<?> seriesName = seriesNames.get(i); dataset.addSeries(seriesMap.get(seriesName)); } } return dataset; }
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; }
public void processNode(Object name, Map map, Object value) throws Exception { if(value != null && value instanceof TimePeriodValuesCollection) { this.collection = (TimePeriodValuesCollection)value; }else { // TODO } }
/** * Resets the display. */ @Override void resetUI() { super.resetUI(); XYPlot xyPlot = mChart.getXYPlot(); xyPlot.getRangeAxis().setVisible(false); mTooltipGenerator = new CustomXYToolTipGenerator(); @SuppressWarnings("unchecked") List<String>[] mTooltipsTmp = new List[NUM_SERIES]; mTooltips = mTooltipsTmp; XYBarRenderer br = new XYBarRenderer(); br.setUseYInterval(true); mDatasets = new TimePeriodValues[NUM_SERIES]; TimePeriodValuesCollection tpvc = new YIntervalTimePeriodValuesCollection(1); xyPlot.setDataset(tpvc); xyPlot.setRenderer(br); for (int i = 0; i < NUM_SERIES; i++) { br.setSeriesPaint(i, SERIES_COLORS[i]); mDatasets[i] = new TimePeriodValues(SERIES_NAMES[i]); tpvc.addSeries(mDatasets[i]); mTooltips[i] = new ArrayList<String>(); mTooltipGenerator.addToolTipSeries(mTooltips[i]); br.setSeriesToolTipGenerator(i, mTooltipGenerator); } }
/** * 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); }
/** * Resets the display. */ @Override void resetUI() { super.resetUI(); XYPlot xyPlot = mChart.getXYPlot(); XYBarRenderer br = new XYBarRenderer(); mDatasetsSync = new TimePeriodValues[NUM_AUTHS]; @SuppressWarnings("unchecked") List<String> mTooltipsSyncTmp[] = new List[NUM_AUTHS]; mTooltipsSync = mTooltipsSyncTmp; mTooltipGenerators = new CustomXYToolTipGenerator[NUM_AUTHS]; TimePeriodValuesCollection tpvc = new TimePeriodValuesCollection(); xyPlot.setDataset(tpvc); xyPlot.setRenderer(0, br); XYLineAndShapeRenderer ls = new XYLineAndShapeRenderer(); ls.setBaseLinesVisible(false); mDatasetsSyncTickle = new TimeSeries[NUM_AUTHS]; TimeSeriesCollection tsc = new TimeSeriesCollection(); xyPlot.setDataset(1, tsc); xyPlot.setRenderer(1, ls); mDatasetError = new TimeSeries("Errors", FixedMillisecond.class); xyPlot.setDataset(2, new TimeSeriesCollection(mDatasetError)); XYLineAndShapeRenderer errls = new XYLineAndShapeRenderer(); errls.setBaseLinesVisible(false); errls.setSeriesPaint(0, Color.RED); xyPlot.setRenderer(2, errls); for (int i = 0; i < NUM_AUTHS; i++) { br.setSeriesPaint(i, AUTH_COLORS[i]); ls.setSeriesPaint(i, AUTH_COLORS[i]); mDatasetsSync[i] = new TimePeriodValues(AUTH_NAMES[i]); tpvc.addSeries(mDatasetsSync[i]); mTooltipsSync[i] = new ArrayList<String>(); mTooltipGenerators[i] = new CustomXYToolTipGenerator(); br.setSeriesToolTipGenerator(i, mTooltipGenerators[i]); mTooltipGenerators[i].addToolTipSeries(mTooltipsSync[i]); mDatasetsSyncTickle[i] = new TimeSeries(AUTH_NAMES[i] + " tickle", FixedMillisecond.class); tsc.addSeries(mDatasetsSyncTickle[i]); ls.setSeriesShape(i, ShapeUtilities.createUpTriangle(2.5f)); } }
/** * Getter for property collection. * @return Value of property collection. */ public TimePeriodValuesCollection getCollection() { return this.collection; }
/** * Setter for property collection. * @param collection New value of property collection. */ public void setCollection(TimePeriodValuesCollection collection) { this.collection = collection; }