Class Curve
Thread-safety model
Curve supports two distinct modes of use:
1) Thread-safe mutation via add(...) / addAll(...)
Methods such as add(double, double) and
addAll(double[], double[]) may be called from any thread.
They preserve the ACurve contract that notifications occur on the
Swing EDT:
- If called on the EDT, they apply immediately and fire a DATA change event.
- If called off the EDT, they enqueue points and schedule a coalesced EDT drain pass. The drain applies a batch and then fires a single consolidated DATA change event.
2) Streaming / DAQ mode via enqueue(...) +
drainPendingOnEDT(...)
Background producer threads may call enqueue(double, double) /
enqueue(double, double, double) and the UI (EDT) drains periodically
using drainPendingOnEDT(int) (often via
startPendingDrainTimer(int, int)).
- Author:
- heddle
-
Nested Class Summary
Nested classes/interfaces inherited from class edu.cnu.mdi.splot.pdata.ACurve
ACurve.PendingQueue<T> -
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionCurve(String name, DataColumn xData, DataColumn yData, DataColumn eData) Create a standard XY curve. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(double x, double y) Append a point and fire a DATA change event.voidadd(double x, double y, double ey) Append a point with Y error and fire a DATA change event.voidaddAll(double[] x, double[] y) Append many points and fire a single DATA change event.voidaddAll(double[] x, double[] y, double[] ey) Append many points with Y errors and fire a single DATA change event.voidClear all data from this curve and fire a DATA change event.voidClear all pending (not-yet-applied) points from the staging queue.voiddoFit(boolean force) Perform a curve fit (or compute derived artifacts like splines), depending on the configured curve drawing method.intdrainPendingOnEDT(int max) Drain up tomaxpending points on the EDT, applying them to the curve's data columns and firing a single DATA change event.eData()Get the centroid of the curve data points.longintlength()Get curve length (number of points or effective points in the data columns).snapshot()Obtain a consistent snapshot of the current data, suitable for plotting without locking.voidstartPendingDrainTimer(int periodMs, int maxPerTick) voidstartPendingDrainTimer(int periodMs, int maxPerTick, IntConsumer drainedCallback) voidStop the pending drain timer if it's running.xData()doublexMax()doublexMin()yData()doubleyMax()doubleyMin()Methods inherited from class edu.cnu.mdi.splot.pdata.ACurve
addCurveChangeListener, beginUpdate, createFitterForCurrentMethod, dataChanged, endUpdate, fireCurveChanged, fitResult, fitWithOptionalWeights, getCubicSpline, getCurveDrawingMethod, getFitOrder, getFitSummary, getFitValueGetter, getStyle, initStyle, isDirty, isHistogram, isStripChart, isVisible, isXYCurve, markDataChanged, markFitChanged, markStyleChanged, name, removeCurveChangeListener, requireEdt, scheduleDrainOnce, setCubicSpline, setCurveDrawingMethod, setDirty, setFitOrder, setFitResult, setName, setStyle, setVisible, styleChanged, toString
-
Constructor Details
-
Curve
public Curve(String name, DataColumn xData, DataColumn yData, DataColumn eData) throws PlotDataException Create a standard XY curve.- Parameters:
name- the curve namexData- the x data column (non-null)yData- the y data column (non-null)eData- the optional y-error column (may be null)- Throws:
PlotDataException- if the data columns have inconsistent lengths
-
-
Method Details
-
length
public int length()Description copied from class:ACurveGet curve length (number of points or effective points in the data columns). -
xData
- Returns:
- the x data column (backing storage; do not mutate externally)
-
yData
- Returns:
- the y data column (backing storage; do not mutate externally)
-
eData
- Returns:
- the optional y-error data column (may be null)
-
doFit
public void doFit(boolean force) Description copied from class:ACurvePerform a curve fit (or compute derived artifacts like splines), depending on the configured curve drawing method. -
add
public void add(double x, double y) Append a point and fire a DATA change event.Safe to call from any thread. Off-EDT calls enqueue and schedule a coalesced EDT drain.
-
add
public void add(double x, double y, double ey) Append a point with Y error and fire a DATA change event.Safe to call from any thread. Off-EDT calls enqueue and schedule a coalesced EDT drain.
- Throws:
IllegalStateException- if this curve has no error column (eData is null)
-
addAll
public void addAll(double[] x, double[] y) Append many points and fire a single DATA change event.Safe to call from any thread. Off-EDT calls enqueue and schedule a coalesced EDT drain.
-
addAll
public void addAll(double[] x, double[] y, double[] ey) Append many points with Y errors and fire a single DATA change event.Safe to call from any thread. Off-EDT calls enqueue and schedule a coalesced EDT drain.
- Parameters:
x- array of x valuesy- array of y valuesey- array of y error values (must be same length as x and y- Throws:
IllegalStateException- if this curve has no error column (eData is null)
-
clearData
public void clearData()Clear all data from this curve and fire a DATA change event.Thread-safe: may be called from any thread. If called off the EDT, the clear is performed later on the EDT and coalesced with other scheduled drains.
Note: this also clears any queued (not-yet-applied) points so the curve truly becomes empty.
-
snapshot
Description copied from class:ACurveObtain a consistent snapshot of the current data, suitable for plotting without locking.Subclasses should return copies of their internal primitive arrays (or equivalent immutable state), typically while synchronizing on
ACurve.lock. -
xMin
public double xMin() -
xMax
public double xMax() -
yMin
public double yMin() -
yMax
public double yMax() -
getPendingCount
public long getPendingCount() -
drainPendingOnEDT
public int drainPendingOnEDT(int max) Drain up tomaxpending points on the EDT, applying them to the curve's data columns and firing a single DATA change event.- Parameters:
max- the maximum number of pending points to apply in this pass (must be positive)- Returns:
- the number of points actually drained and applied
-
startPendingDrainTimer
public void startPendingDrainTimer(int periodMs, int maxPerTick) -
startPendingDrainTimer
-
stopPendingDrainTimer
public void stopPendingDrainTimer()Stop the pending drain timer if it's running. Safe to call from any thread. -
clearPending
public void clearPending()Clear all pending (not-yet-applied) points from the staging queue. Safe to call from any thread. -
getCentroid
Get the centroid of the curve data points.- Returns:
- the centroid as a Point2D.Double
-