/** * Confirm that the equals method can distinguish all the required fields. */ public void testEquals() { XYIntervalSeriesCollection c1 = new XYIntervalSeriesCollection(); XYIntervalSeriesCollection c2 = new XYIntervalSeriesCollection(); assertEquals(c1, c2); // add a series XYIntervalSeries s1 = new XYIntervalSeries("Series"); s1.add(1.0, 1.1, 1.2, 1.3, 1.4, 1.5); c1.addSeries(s1); assertFalse(c1.equals(c2)); XYIntervalSeries s2 = new XYIntervalSeries("Series"); s2.add(1.0, 1.1, 1.2, 1.3, 1.4, 1.5); c2.addSeries(s2); assertTrue(c1.equals(c2)); // add an empty series c1.addSeries(new XYIntervalSeries("Empty Series")); assertFalse(c1.equals(c2)); c2.addSeries(new XYIntervalSeries("Empty Series")); assertTrue(c1.equals(c2)); }
/** * Some checks for the add() method for an UNSORTED series. */ public void testAdd() { XYIntervalSeries series = new XYIntervalSeries("Series", false, true); series.add(5.0, 5.50, 5.50, 5.50, 5.50, 5.50); series.add(5.1, 5.51, 5.51, 5.51, 5.51, 5.51); series.add(6.0, 6.6, 6.6, 6.6, 6.6, 6.6); series.add(3.0, 3.3, 3.3, 3.3, 3.3, 3.3); series.add(4.0, 4.4, 4.4, 4.4, 4.4, 4.4); series.add(2.0, 2.2, 2.2, 2.2, 2.2, 2.2); series.add(1.0, 1.1, 1.1, 1.1, 1.1, 1.1); assertEquals(5.5, series.getYValue(0), EPSILON); assertEquals(5.51, series.getYValue(1), EPSILON); assertEquals(6.6, series.getYValue(2), EPSILON); assertEquals(3.3, series.getYValue(3), EPSILON); assertEquals(4.4, series.getYValue(4), EPSILON); assertEquals(2.2, series.getYValue(5), EPSILON); assertEquals(1.1, series.getYValue(6), EPSILON); }
/** * A test for the findDomainBounds method to ensure it correctly accounts * for the series visibility. */ @Test public void testFindDomainBounds2() { XYIntervalSeries s1 = new XYIntervalSeries("S1"); s1.add(1.0, 0.5, 1.5, 10.0, 9.5, 10.5); s1.add(2.0, 1.9, 2.1, 20.0, 19.8, 20.3); XYIntervalSeries s2 = new XYIntervalSeries("S2"); s2.add(3.0, 2.5, 3.5, 30.0, 29.5, 30.5); s2.add(4.0, 3.9, 4.1, 9.0, 9.0, 9.0); XYIntervalSeriesCollection dataset = new XYIntervalSeriesCollection(); dataset.addSeries(s1); dataset.addSeries(s2); XYBarRenderer renderer = new XYBarRenderer(); Range r = renderer.findDomainBounds(dataset); assertEquals(0.5, r.getLowerBound(), EPSILON); assertEquals(4.1, r.getUpperBound(), EPSILON); renderer.setSeriesVisible(1, Boolean.FALSE); r = renderer.findDomainBounds(dataset); assertEquals(0.5, r.getLowerBound(), EPSILON); assertEquals(2.1, r.getUpperBound(), EPSILON); }
/** * A test for the findRangeBounds method to ensure it correctly accounts * for the series visibility. */ @Test public void testFindRangeBounds2() { XYIntervalSeries s1 = new XYIntervalSeries("S1"); s1.add(1.0, 0.5, 1.5, 10.0, 9.5, 10.5); s1.add(2.0, 1.9, 2.1, 20.0, 19.8, 20.3); XYIntervalSeries s2 = new XYIntervalSeries("S2"); s2.add(3.0, 2.5, 3.5, 30.0, 29.5, 30.5); s2.add(4.0, 3.9, 4.1, 9.0, 9.0, 9.0); XYIntervalSeriesCollection dataset = new XYIntervalSeriesCollection(); dataset.addSeries(s1); dataset.addSeries(s2); XYBarRenderer renderer = new XYBarRenderer(); renderer.setUseYInterval(false); Range r = renderer.findRangeBounds(dataset); assertEquals(9.0, r.getLowerBound(), EPSILON); assertEquals(30.0, r.getUpperBound(), EPSILON); renderer.setSeriesVisible(1, Boolean.FALSE); r = renderer.findRangeBounds(dataset); assertEquals(10.0, r.getLowerBound(), EPSILON); assertEquals(20.0, r.getUpperBound(), EPSILON); }
/** * Another test for bug 2849731. */ @Test public void testBug2849731_2() { XYIntervalSeriesCollection d = new XYIntervalSeriesCollection(); XYIntervalSeries s = new XYIntervalSeries("S1"); s.add(1.0, Double.NaN, Double.NaN, Double.NaN, 1.5, Double.NaN); d.addSeries(s); Range r = DatasetUtilities.iterateDomainBounds(d); assertEquals(1.0, r.getLowerBound(), EPSILON); assertEquals(1.0, r.getUpperBound(), EPSILON); s.add(1.0, 1.5, Double.NaN, Double.NaN, 1.5, Double.NaN); r = DatasetUtilities.iterateDomainBounds(d); assertEquals(1.0, r.getLowerBound(), EPSILON); assertEquals(1.5, r.getUpperBound(), EPSILON); s.add(1.0, Double.NaN, 0.5, Double.NaN, 1.5, Double.NaN); r = DatasetUtilities.iterateDomainBounds(d); assertEquals(0.5, r.getLowerBound(), EPSILON); assertEquals(1.5, r.getUpperBound(), EPSILON); }
/** * Yet another test for bug 2849731. */ @Test public void testBug2849731_3() { XYIntervalSeriesCollection d = new XYIntervalSeriesCollection(); XYIntervalSeries s = new XYIntervalSeries("S1"); s.add(1.0, Double.NaN, Double.NaN, 1.5, Double.NaN, Double.NaN); d.addSeries(s); Range r = DatasetUtilities.iterateRangeBounds(d); assertEquals(1.5, r.getLowerBound(), EPSILON); assertEquals(1.5, r.getUpperBound(), EPSILON); s.add(1.0, 1.5, Double.NaN, Double.NaN, Double.NaN, 2.5); r = DatasetUtilities.iterateRangeBounds(d); assertEquals(1.5, r.getLowerBound(), EPSILON); assertEquals(2.5, r.getUpperBound(), EPSILON); s.add(1.0, Double.NaN, 0.5, Double.NaN, 3.5, Double.NaN); r = DatasetUtilities.iterateRangeBounds(d); assertEquals(1.5, r.getLowerBound(), EPSILON); assertEquals(3.5, r.getUpperBound(), EPSILON); }
/** * Another test for bug 2849731. */ @Test public void testBug2849731_2() { XYIntervalSeriesCollection d = new XYIntervalSeriesCollection(); XYIntervalSeries s = new XYIntervalSeries("S1"); s.add(1.0, Double.NaN, Double.NaN, Double.NaN, 1.5, Double.NaN); d.addSeries(s); Range r = DatasetUtils.iterateDomainBounds(d); assertEquals(1.0, r.getLowerBound(), EPSILON); assertEquals(1.0, r.getUpperBound(), EPSILON); s.add(1.0, 1.5, Double.NaN, Double.NaN, 1.5, Double.NaN); r = DatasetUtils.iterateDomainBounds(d); assertEquals(1.0, r.getLowerBound(), EPSILON); assertEquals(1.5, r.getUpperBound(), EPSILON); s.add(1.0, Double.NaN, 0.5, Double.NaN, 1.5, Double.NaN); r = DatasetUtils.iterateDomainBounds(d); assertEquals(0.5, r.getLowerBound(), EPSILON); assertEquals(1.5, r.getUpperBound(), EPSILON); }
/** * Yet another test for bug 2849731. */ @Test public void testBug2849731_3() { XYIntervalSeriesCollection d = new XYIntervalSeriesCollection(); XYIntervalSeries s = new XYIntervalSeries("S1"); s.add(1.0, Double.NaN, Double.NaN, 1.5, Double.NaN, Double.NaN); d.addSeries(s); Range r = DatasetUtils.iterateRangeBounds(d); assertEquals(1.5, r.getLowerBound(), EPSILON); assertEquals(1.5, r.getUpperBound(), EPSILON); s.add(1.0, 1.5, Double.NaN, Double.NaN, Double.NaN, 2.5); r = DatasetUtils.iterateRangeBounds(d); assertEquals(1.5, r.getLowerBound(), EPSILON); assertEquals(2.5, r.getUpperBound(), EPSILON); s.add(1.0, Double.NaN, 0.5, Double.NaN, 3.5, Double.NaN); r = DatasetUtils.iterateRangeBounds(d); assertEquals(1.5, r.getLowerBound(), EPSILON); assertEquals(3.5, r.getUpperBound(), EPSILON); }
public void delete() { if(xySeries == null){ return; } int[] selectedRows = table.getSelectedRows(); for (int row = selectedRows.length -1; row >= 0; row--) { int rowIndex = selectedRows[row]; if (rowIndex >= xySeries.getItemCount()) { clearBufferRow(rowIndex - xySeries.getItemCount()); } else { if(graph instanceof Graph) ((PrismXYSeries)xySeries).remove(rowIndex); else if(graph instanceof Histogram) ((XYIntervalSeries)xySeries).remove(rowIndex); } } }
/** * Add a series to the buffered graph data. * * @param seriesName * Name of series to add to graph. */ public SeriesKey addSeries(String seriesName) { SeriesKey key; synchronized (seriesCollection) { seriesName = getUniqueSeriesName(seriesName); // create a new XYSeries without sorting, disallowing duplicates XYIntervalSeries newSeries = new XYIntervalSeries(seriesName); this.seriesCollection.addSeries(newSeries); // allocate a new cache for this series key = new SeriesKey(); this.keyToSeries.put(key, newSeries); SeriesSettings graphSeries = new SeriesSettings(this, key); this.keyToGraphSeries.put(key, graphSeries); graphSeries.addObserver(this); this.seriesList.updateSeriesList(); } return key; }
/** * Wholly remove a series from the current graph, by key. * @param seriesKey SeriesKey of series to remove. */ public void removeSeries(SeriesKey seriesKey) { synchronized (seriesCollection) { // Delete from keyToSeries and seriesCollection. if (keyToSeries.containsKey(seriesKey)) { XYIntervalSeries series = keyToSeries.get(seriesKey); seriesCollection.removeSeries(series); keyToSeries.remove(seriesKey); } if (keyToGraphSeries.containsKey(seriesKey)) { keyToGraphSeries.get(seriesKey).deleteObservers(); keyToGraphSeries.remove(seriesKey); } this.seriesList.updateSeriesList(); } seriesList.updateSeriesList(); }
/** * Should always be synchronised on seriesCollection when called. * @return >0 when series found. */ public int getJFreeChartIndex(SeriesKey key) { synchronized (seriesCollection) { XYIntervalSeries series = keyToSeries.get(key); for (int i = 0; i < seriesCollection.getSeriesCount(); i++) { if (seriesCollection.getSeries(i).equals((series))) return i; } return -1; } }
/** * Another test for bug 2849731. */ public void testBug2849731_2() { XYIntervalSeriesCollection d = new XYIntervalSeriesCollection(); XYIntervalSeries s = new XYIntervalSeries("S1"); s.add(1.0, Double.NaN, Double.NaN, Double.NaN, 1.5, Double.NaN); d.addSeries(s); Range r = DatasetUtilities.iterateDomainBounds(d); assertEquals(1.0, r.getLowerBound(), EPSILON); assertEquals(1.0, r.getUpperBound(), EPSILON); s.add(1.0, 1.5, Double.NaN, Double.NaN, 1.5, Double.NaN); r = DatasetUtilities.iterateDomainBounds(d); assertEquals(1.0, r.getLowerBound(), EPSILON); assertEquals(1.5, r.getUpperBound(), EPSILON); s.add(1.0, Double.NaN, 0.5, Double.NaN, 1.5, Double.NaN); r = DatasetUtilities.iterateDomainBounds(d); assertEquals(0.5, r.getLowerBound(), EPSILON); assertEquals(1.5, r.getUpperBound(), EPSILON); }
/** * Yet another test for bug 2849731. */ public void testBug2849731_3() { XYIntervalSeriesCollection d = new XYIntervalSeriesCollection(); XYIntervalSeries s = new XYIntervalSeries("S1"); s.add(1.0, Double.NaN, Double.NaN, 1.5, Double.NaN, Double.NaN); d.addSeries(s); Range r = DatasetUtilities.iterateRangeBounds(d); assertEquals(1.5, r.getLowerBound(), EPSILON); assertEquals(1.5, r.getUpperBound(), EPSILON); s.add(1.0, 1.5, Double.NaN, Double.NaN, Double.NaN, 2.5); r = DatasetUtilities.iterateRangeBounds(d); assertEquals(1.5, r.getLowerBound(), EPSILON); assertEquals(2.5, r.getUpperBound(), EPSILON); s.add(1.0, Double.NaN, 0.5, Double.NaN, 3.5, Double.NaN); r = DatasetUtilities.iterateRangeBounds(d); assertEquals(1.5, r.getLowerBound(), EPSILON); assertEquals(3.5, r.getUpperBound(), EPSILON); }
private void computeRegressionAndAcceptableDeviationData() { acceptableDeviationDataset.removeAllSeries(); regressionDataset.removeAllSeries(); getPlot().removeAnnotation(r2Annotation); if (computedDatas != null) { final ValueAxis domainAxis = getPlot().getDomainAxis(); final double min = domainAxis.getLowerBound(); final double max = domainAxis.getUpperBound(); acceptableDeviationDataset.addSeries(computeAcceptableDeviationData(min, max)); if (scatterPlotModel.showRegressionLine) { final XYIntervalSeries series = computeRegressionData(min, max); if (series != null) { regressionDataset.addSeries(series); computeCoefficientOfDetermination(); } } } }
private XYIntervalSeries computeRegressionData(double xStart, double xEnd) { if (scatterpointsDataset.getItemCount(0) > 1) { final double[] coefficients = Regression.getOLSRegression(scatterpointsDataset, 0); final Function2D curve = new LineFunction2D(coefficients[0], coefficients[1]); final XYSeries regressionData = DatasetUtilities.sampleFunction2DToSeries(curve, xStart, xEnd, 100, "regression line"); final XYIntervalSeries xyIntervalRegression = new XYIntervalSeries(regressionData.getKey()); for (int i = 0; i < regressionData.getItemCount(); i++) { XYDataItem item = regressionData.getDataItem(i); final double x = item.getXValue(); final double y = item.getYValue(); xyIntervalRegression.add(x, x, x, y, y, y); } return xyIntervalRegression; } else { Dialogs.showInformation("Unable to compute regression line.\n" + "At least 2 values are needed to compute regression coefficients."); return null; } }