Package edu.cnu.mdi.splot.pdata
Class PlotData
java.lang.Object
edu.cnu.mdi.splot.pdata.PlotData
- All Implemented Interfaces:
CurveChangeListener,EventListener
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
PlotDataso 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 Summary
ConstructorsConstructorDescriptionPlotData(Histo2DData histo2D) Create plot data for a 2D histogram.Create plot data from one or more 1D histogram data objects.PlotData(PlotDataType type, String[] curveNames, int[] fitOrders) Create plot data with specified data set type and column names.PlotData(StripChartCurve stripData) Create plot data for a strip chart (time series / streamed XY). -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdd a curve to this plot model.voidaddDataChangeListener(DataChangeListener listener) Add a plot-data change listener.voidcurveChanged(ACurve curve, CurveChangeType type) Curve-level notification (forwarded toDataChangeListeners).static PlotDataCreate empty plot data with one default curve.getCurve(int index) Convenience: get a curve by index.Convenience: get a curve by name.Convenience: get the first curve.Get the 2D histogram data, if applicable.getType()booleanConvenience method to determine if this is 2D histogram plot data.booleanConvenience method to determine if this is histogram plot data.booleanDetermine if this is histogram plot data.booleanDetermine if this is strip chart plot data.booleanisXYData()Determine whether this model contains ordinary XY data, with or without y-error values.voidnotifyListeners(ACurve curve, CurveChangeType type) NotifyDataChangeListeners that the plot model changed.voidremoveDataChangeListener(DataChangeListener listener) Remove a plot-data change listener.intsize()doublexMax()doublexMin()doubleyMax()doubleyMin()
-
Constructor Details
-
PlotData
Create plot data from one or more 1D histogram data objects. EachHistoDatais wrapped in aHistoCurveand 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
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
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
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 viaACurve.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
Create empty plot data with one default curve.- Returns:
- empty plot data
-
getType
- Returns:
- the plot data type.
-
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:
trueforPlotDataType.XYXYorPlotDataType.XYEXYE
-
isStripData
public boolean isStripData()Determine if this is strip chart plot data.- Returns:
- true if strip chart plot data
-
getCurves
- Returns:
- an unmodifiable view of the curves.
-
getVisibleCurves
- Returns:
- a list of visible curves.
-
size
public int size()- Returns:
- curve count.
-
getCurve
Convenience: get a curve by index. -
getCurve
Convenience: get a curve by name.- Parameters:
name- the curve name- Returns:
- the curve with the given name, or null if not found
-
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
Add a curve to this plot model.- Parameters:
curve- the curve to add (non-null)- Returns:
trueif added
-
curveChanged
Curve-level notification (forwarded toDataChangeListeners).- Specified by:
curveChangedin interfaceCurveChangeListener- Parameters:
curve- the curve that changedtype- the change type
-
notifyListeners
NotifyDataChangeListeners that the plot model changed. -
addDataChangeListener
Add a plot-data change listener. -
removeDataChangeListener
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.
-