Class PlotData

java.lang.Object
edu.cnu.mdi.splot.pdata.PlotData
All Implemented Interfaces:
CurveChangeListener, EventListener

public class PlotData extends Object implements CurveChangeListener
A lightweight, UI-agnostic container for the data backing a plot.

PlotData owns one or more ACurve instances (including histogram-backed curves such as HistoCurve, and ordinary XY curves such as Curve). Views typically register a single DataChangeListener on the PlotData and repaint when notified.

Notifications

There are two kinds of changes:
  • Structural changes to the model (curves added) — fired by PlotData.
  • Data changes within a curve (points appended, histogram filled, etc.) — fired by the curve, and forwarded by PlotData so the view can listen in one place.

Threading

PlotData is not synchronized. If curves are updated from a background sampler (e.g. StripChartCurve), the view should use its existing snapshot/copy strategy when rendering.

Thread-safety

PlotData is not thread-safe. All structural mutations (addCurve(edu.cnu.mdi.splot.pdata.ACurve)) and all listener notifications MUST be called on the Swing EDT. Background producers should call only the thread-safe methods on the individual ACurve subclasses (e.g. Curve.add(double, double), Curve.enqueue(double, double)) — never mutate PlotData directly from off-EDT threads.
Author:
heddle
  • Constructor Details

    • PlotData

      public PlotData(HistoData... histos) throws PlotDataException
      Create plot data from one or more 1D histogram data objects. Each HistoData is wrapped in a HistoCurve and added to this model.
      Parameters:
      histos - one or more histogram data objects (must be non-null and contain no nulls)
      Throws:
      PlotDataException - if there is a problem creating the data set
    • PlotData

      public PlotData(Histo2DData histo2D) throws PlotDataException
      Create plot data for a 2D histogram.
      Parameters:
      histo2D - the 2D histogram backing data (non-null)
      Throws:
      PlotDataException - if the histogram data is null
    • PlotData

      public PlotData(StripChartCurve stripData) throws PlotDataException
      Create plot data for a strip chart (time series / streamed XY).
      Parameters:
      stripData - the strip chart backing data (non-null)
      Throws:
      PlotDataException - if the strip data does not provide a curve
    • PlotData

      public PlotData(PlotDataType type, String[] curveNames, int[] fitOrders) throws PlotDataException
      Create plot data with specified data set type and column names.
      Parameters:
      type - the data set type (non-null)
      curveNames - a curve is created for each curve name. Must be non-null and contain at least one name. The names should not be null.
      fitOrders - optional fit orders for each curve (may be null). If non-null, the length must match the number of curve names. This fit orders are assigned to each curve via ACurve.setFitOrder(int). They are only relevant for MultiGaussian (no. of Gaussians) and Polynomial (polynomial degree) fits.
      Throws:
      PlotDataException - if there is a problem creating the data set
  • Method Details

    • emptyData

      public static PlotData emptyData()
      Create empty plot data with one default curve.
      Returns:
      empty plot data
    • getType

      public PlotDataType getType()
      Returns:
      the plot data type.
    • getHisto2DData

      public Histo2DData getHisto2DData()
      Get the 2D histogram data, if applicable. There are no curves for 2D histograms so the data is cached here.
      Returns:
      the 2D histogram data, or null if not applicable.
    • isHistoData

      public boolean isHistoData()
      Convenience method to determine if this is histogram plot data.
      Returns:
      true if histogram plot data
    • isHisto2DData

      public boolean isHisto2DData()
      Convenience method to determine if this is 2D histogram plot data.
      Returns:
      true if 2D histogram plot data
    • isXYData

      public boolean isXYData()
      Determine whether this model contains ordinary XY data, with or without y-error values.
      Returns:
      true for PlotDataType.XYXY or PlotDataType.XYEXYE
    • isStripData

      public boolean isStripData()
      Determine if this is strip chart plot data.
      Returns:
      true if strip chart plot data
    • getCurves

      public List<ACurve> getCurves()
      Returns:
      an unmodifiable view of the curves.
    • getVisibleCurves

      public List<ACurve> getVisibleCurves()
      Returns:
      a list of visible curves.
    • size

      public int size()
      Returns:
      curve count.
    • getCurve

      public ACurve getCurve(int index)
      Convenience: get a curve by index.
    • getCurve

      public ACurve getCurve(String name)
      Convenience: get a curve by name.
      Parameters:
      name - the curve name
      Returns:
      the curve with the given name, or null if not found
    • getFirstCurve

      public ACurve getFirstCurve()
      Convenience: get the first curve. Often there is only one.
      Returns:
      the first curve, or null if there are no curves
    • isHistogramData

      public boolean isHistogramData()
      Determine if this is histogram plot data.
      Returns:
      true if histogram plot data
    • addCurve

      public boolean addCurve(ACurve curve)
      Add a curve to this plot model.
      Parameters:
      curve - the curve to add (non-null)
      Returns:
      true if added
    • curveChanged

      public void curveChanged(ACurve curve, CurveChangeType type)
      Curve-level notification (forwarded to DataChangeListeners).
      Specified by:
      curveChanged in interface CurveChangeListener
      Parameters:
      curve - the curve that changed
      type - the change type
    • notifyListeners

      public void notifyListeners(ACurve curve, CurveChangeType type)
      Notify DataChangeListeners that the plot model changed.
    • addDataChangeListener

      public void addDataChangeListener(DataChangeListener listener)
      Add a plot-data change listener.
    • removeDataChangeListener

      public void removeDataChangeListener(DataChangeListener listener)
      Remove a plot-data change listener.
    • xMin

      public double xMin()
      Returns:
      the minimum x value over all curves.
    • xMax

      public double xMax()
      Returns:
      the maximum x value over all curves.
    • yMin

      public double yMin()
      Returns:
      the minimum y value over all curves.
    • yMax

      public double yMax()
      Returns:
      the maximum y value over all curves.