Java Code Examples for org.jfree.data.xy.XYSeries#getItemCount()

The following examples show how to use org.jfree.data.xy.XYSeries#getItemCount() . 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: FunctionPanel.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
public void updateSelectedNodesAfterAddition(int series, int node) {
   XYSeriesCollection seriesCollection = (XYSeriesCollection)getChart().getXYPlot().getDataset();
   XYSeries dSeries = seriesCollection.getSeries(series);

   // Unhighlight all nodes in the series that are after the added one.
   for (int i=node; i<dSeries.getItemCount(); i++) {
      renderer.unhighlightNode(series, i);
   }

   // For all nodes in the series after the added one, increment the node number.
   for (int i=0; i<selectedNodes.size(); i++) {
      if (selectedNodes.get(i).series == series && selectedNodes.get(i).node >= node) {
         selectedNodes.get(i).node++;
      }
   }

   // For each selected node in the series after the added one, highlight it.
   for (int i=0; i<selectedNodes.size(); i++) {
      if (selectedNodes.get(i).series == series && selectedNodes.get(i).node > node) {
         renderer.highlightNode(series, selectedNodes.get(i).node);
      }
   }
}
 
Example 2
Source File: ScatterPlotPanel.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
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;
    }
}
 
Example 3
Source File: PseudoSpectrumDataSet.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
private void addDPIdentity(MZTolerance mzTolerance, AbstractMSMSDataPointIdentity ann) {
  for (int s = 0; s < getSeriesCount(); s++) {
    XYSeries series = getSeries(s);
    for (int i = 0; i < series.getItemCount(); i++) {
      XYDataItem dp = series.getDataItem(i);
      if (mzTolerance.checkWithinTolerance(dp.getXValue(), ann.getMZ())) {
        addAnnotation(dp, ann.getName());
      }
    }
  }
}
 
Example 4
Source File: HistogramChartFactory.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Performs Gaussian fit on XYSeries
 * 
 * @param series the data
 * @param gMin lower bound of Gaussian fit
 * @param gMax upper bound of Gaussian fit
 * @param sigDigits number of significant digits
 * @return double[] {normFactor, mean, sigma} as a result of
 *         GaussianCurveFitter.create().fit(obs.toList())
 */
public static double[] gaussianFit(XYSeries series, double gMin, double gMax) {
  // gaussian fit
  WeightedObservedPoints obs = new WeightedObservedPoints();

  for (int i = 0; i < series.getItemCount(); i++) {
    double x = series.getX(i).doubleValue();
    if (x >= gMin && x <= gMax)
      obs.add(x, series.getY(i).doubleValue());
  }

  return fitter.fit(obs.toList());
}
 
Example 5
Source File: HistogramChartFactory.java    From old-mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Performs Gaussian fit on XYSeries
 * 
 * @param series the data
 * @param gMin lower bound of Gaussian fit
 * @param gMax upper bound of Gaussian fit
 * @param sigDigits number of significant digits
 * @return double[] {normFactor, mean, sigma} as a result of
 *         GaussianCurveFitter.create().fit(obs.toList())
 */
public static double[] gaussianFit(XYSeries series, double gMin, double gMax) {
  // gaussian fit
  WeightedObservedPoints obs = new WeightedObservedPoints();

  for (int i = 0; i < series.getItemCount(); i++) {
    double x = series.getX(i).doubleValue();
    if (x >= gMin && x <= gMax)
      obs.add(x, series.getY(i).doubleValue());
  }

  return fitter.fit(obs.toList());
}
 
Example 6
Source File: PseudoSpectrumDataSet.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
private void addDPIdentity(MZTolerance mzTolerance, AbstractMSMSDataPointIdentity ann) {
  for (int s = 0; s < getSeriesCount(); s++) {
    XYSeries series = getSeries(s);
    for (int i = 0; i < series.getItemCount(); i++) {
      XYDataItem dp = series.getDataItem(i);
      if (mzTolerance.checkWithinTolerance(dp.getXValue(), ann.getMZ())) {
        addAnnotation(dp, ann.getName());
      }
    }
  }
}
 
Example 7
Source File: HistogramChartFactory.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Performs Gaussian fit on XYSeries
 * 
 * @param series the data
 * @param gMin lower bound of Gaussian fit
 * @param gMax upper bound of Gaussian fit
 * @param sigDigits number of significant digits
 * @return double[] {normFactor, mean, sigma} as a result of
 *         GaussianCurveFitter.create().fit(obs.toList())
 */
public static double[] gaussianFit(XYSeries series, double gMin, double gMax) {
  // gaussian fit
  WeightedObservedPoints obs = new WeightedObservedPoints();

  for (int i = 0; i < series.getItemCount(); i++) {
    double x = series.getX(i).doubleValue();
    if (x >= gMin && x <= gMax)
      obs.add(x, series.getY(i).doubleValue());
  }

  return fitter.fit(obs.toList());
}
 
Example 8
Source File: Plot.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
private boolean sameDomain(XYSeries series, XYSeries xYSeries) {
   int count = series.getItemCount();
   if (count!=xYSeries.getItemCount())
      return false;
   // same count, check first and last entry
   if (Math.abs(series.getX(0).doubleValue() - xYSeries.getX(0).doubleValue())>CURVE_MATCH_TOL) {
       return false;
    }
   if (Math.abs(series.getX(count-1).doubleValue()- xYSeries.getX(count-1).doubleValue())>CURVE_MATCH_TOL)
       return false;
   // We need more checking to probe intermediate X values.
   return true;
}
 
Example 9
Source File: FunctionPanel.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
protected int addNode(int series, int screenX, int screenY) {
   XYPlot xyPlot = getChart().getXYPlot();
   RectangleEdge xAxisLocation = xyPlot.getDomainAxisEdge();
   RectangleEdge yAxisLocation = xyPlot.getRangeAxisEdge();
   Rectangle2D dataArea = getScreenDataArea();
   double newNodeX = xyPlot.getDomainAxis().java2DToValue(screenX, dataArea, xAxisLocation);
   double newNodeY = xyPlot.getRangeAxis().java2DToValue(screenY, dataArea, yAxisLocation);

   // Notify all listeners about the change.
   Object[] listeners = this.functionPanelListeners.getListenerList();
   for (int i = listeners.length - 2; i >= 0; i -= 2) {
      if (listeners[i] == FunctionPanelListener.class) {
         ((FunctionPanelListener) listeners[i + 1]).addNode(series, newNodeX, newNodeY);
      }
   }

   // Now add the point to the series, first figuring out what its index will be.
   XYSeriesCollection seriesCollection = (XYSeriesCollection)xyPlot.getDataset();
   XYSeries dSeries = seriesCollection.getSeries(series);
   int index = dSeries.getItemCount();
   for (int i=0; i<dSeries.getItemCount(); i++) {
      if (dSeries.getDataItem(i).getX().doubleValue() > newNodeX) {
         index = i;
         break;
      }
   }
   dSeries.add(newNodeX, newNodeY);

   updateSelectedNodesAfterAddition(series, index);
   return index;
}
 
Example 10
Source File: FunctionPanel.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
public void updateSelectedNodesAfterDeletion(int series, int node) {
   XYSeriesCollection seriesCollection = (XYSeriesCollection)getChart().getXYPlot().getDataset();
   XYSeries dSeries = seriesCollection.getSeries(series);

   // Unhighlight all nodes in the series that are after the deleted one.
   for (int i=node; i<dSeries.getItemCount(); i++) {
      renderer.unhighlightNode(series, i);
   }

   // If the deleted node was selected, remove it from selectedNodes.
   // For all nodes in the series after the deleted one, decrement the node number.
   for (int i=selectedNodes.size()-1; i>=0; i--) {
      if (selectedNodes.get(i).series == series && selectedNodes.get(i).node >= node) {
         if (selectedNodes.get(i).node == node) {
            selectedNodes.remove(i);
         } else {
            selectedNodes.get(i).node--;
         }
      }
   }

   // For each selected node in the series after the deleted one, highlight it.
   for (int i=0; i<selectedNodes.size(); i++) {
      if (selectedNodes.get(i).series == series && selectedNodes.get(i).node >= node) {
         renderer.highlightNode(series, selectedNodes.get(i).node);
      }
   }
}
 
Example 11
Source File: XYChartExpression.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected TableXYDataset convertToTable( final XYSeriesCollection xyDataset ) {
  final ExtCategoryTableXYDataset tableXYDataset = new ExtCategoryTableXYDataset();
  final int count = xyDataset.getSeriesCount();
  for ( int i = 0; i < count; i++ ) {
    final XYSeries timeSeries = xyDataset.getSeries( i );
    final Comparable key = timeSeries.getKey();
    final int itemCount = timeSeries.getItemCount();
    for ( int ic = 0; ic < itemCount; ic++ ) {
      final XYDataItem seriesDataItem = timeSeries.getDataItem( ic );
      tableXYDataset.add( seriesDataItem.getX(), seriesDataItem.getY(), key, false );
    }
  }
  return tableXYDataset;
}
 
Example 12
Source File: GraphData.java    From iBioSim with Apache License 2.0 4 votes vote down vote up
public void exportDataFile(File file, int output) throws Exception {
	int count = curData.getSeries(0).getItemCount();
	for (int i = 1; i < curData.getSeriesCount(); i++) {
		if (curData.getSeries(i).getItemCount() != count) {				
			throw new Exception("Data series do not have the same number of points!");
		}
	}
	for (int j = 0; j < count; j++) {
		Number Xval = curData.getSeries(0).getDataItem(j).getX();
		for (int i = 1; i < curData.getSeriesCount(); i++) {
			if (!curData.getSeries(i).getDataItem(j).getX().equals(Xval)) {
				throw new Exception("Data series time points are not the same!");
			}
		}
	}
	FileOutputStream csvFile = new FileOutputStream(file);
	PrintWriter csvWriter = new PrintWriter(csvFile);
	if (output == 7) {
		csvWriter.print("((");
	}
	else if (output == 6) {
		csvWriter.print("#");
	}
	csvWriter.print("\"Time\"");
	count = curData.getSeries(0).getItemCount();
	int pos = 0;
	for (int i = 0; i < curData.getSeriesCount(); i++) {
		if (output == 6) {
			csvWriter.print(" ");
		}
		else {
			csvWriter.print(",");
		}
		csvWriter.print("\"" + curData.getSeriesKey(i) + "\"");
		if (curData.getSeries(i).getItemCount() > count) {
			count = curData.getSeries(i).getItemCount();
			pos = i;
		}
	}
	if (output == 7) {
		csvWriter.print(")");
	}
	else {
		csvWriter.println("");
	}
	for (int j = 0; j < count; j++) {
		if (output == 7) {
			csvWriter.print(",");
		}
		for (int i = 0; i < curData.getSeriesCount(); i++) {
			if (i == 0) {
				if (output == 7) {
					csvWriter.print("(");
				}
				csvWriter.print(curData.getSeries(pos).getDataItem(j).getX());
			}
			XYSeries data = curData.getSeries(i);
			if (j < data.getItemCount()) {
				XYDataItem item = data.getDataItem(j);
				if (output == 6) {
					csvWriter.print(" ");
				}
				else {
					csvWriter.print(",");
				}
				csvWriter.print(item.getY());
			}
			else {
				if (output == 6) {
					csvWriter.print(" ");
				}
				else {
					csvWriter.print(",");
				}
			}
		}
		if (output == 7) {
			csvWriter.print(")");
		}
		else {
			csvWriter.println("");
		}
	}
	if (output == 7) {
		csvWriter.println(")");
	}
	csvWriter.close();
	csvFile.close();
}