Class StripChartCurve
This class periodically samples a provided Evaluator and appends (t,
y) points into bounded X and Y columns. When capacity is reached, the oldest
samples are dropped ("scrolls off the left").
Threading
Sampling runs on a background scheduler thread. To preserve the
ACurve contract that notifications occur on the Swing Event Dispatch
Thread (EDT), this class uses a lock-free staging queue:
- The background sampler thread computes samples and enqueues them.
- An EDT drain pass applies samples in bounded batches under
ACurve.lock. - A single consolidated
ACurve.markDataChanged()is fired per batch (EDT-only).
The optional setOnSample(Runnable) callback, if provided, is invoked
on the EDT after each drain pass. This is a convenient place to call
repaint() safely.
-
Nested Class Summary
Nested classes/interfaces inherited from class edu.cnu.mdi.splot.pdata.ACurve
ACurve.PendingQueue<T> -
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionStripChartCurve(String name, int capacity, Evaluator accumulator, long intervalMs) Create strip-chart data. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(double tms, double y) Add an explicit sample (t, y) to this strip chart.voidClear all retained samples.voiddoFit(boolean force) Perform a curve computation (fit or spline) on the strip chart's current data, depending on the configuredCurveDrawingMethod.intlongA short label you can use in axis titles ("Time (s)", etc.).booleanintlength()Get curve length (number of points or effective points in the data columns).voidsetCapacity(int capacity) Set the capacity (max samples retained).voidsetIntervalMs(long intervalMs) Set the sampling interval.voidsetOnSample(Runnable onSample) Set a callback to be invoked after each drain pass on the EDT.voidsetTimeUnit(TimeUnit unit) Set the display unit for the time axis.voidshutdown()Permanently shut down this StripChartCurve (cannot be restarted).snapshot()Obtain a consistent snapshot of the current data, suitable for plotting without locking.voidstart()Start sampling.voidstop()Stop sampling.doublexMax()doublexMin()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
-
StripChartCurve
Create strip-chart data.- Parameters:
name- series namecapacity- max number of retained samples (>= 2)accumulator- value source; called asaccumulator.value(tMs)(non-null)intervalMs- update interval in milliseconds (> 0)
-
-
Method Details
-
getCapacity
public int getCapacity()- Returns:
- current capacity (max samples retained).
-
setCapacity
public void setCapacity(int capacity) Set the capacity (max samples retained). If the current size exceeds the new capacity, oldest samples are dropped immediately.If called off the EDT, this method schedules the capacity enforcement on the EDT to keep column mutation and notifications Swing-correct.
- Parameters:
capacity- must be >= 2
-
getIntervalMs
public long getIntervalMs()- Returns:
- sampling interval in milliseconds.
-
getTimeUnit
- Returns:
- the current display unit for time on the x-axis.
-
setTimeUnit
Set the display unit for the time axis.Internal storage remains milliseconds; snapshot/min/max are scaled. This triggers a data change notification so axes/ticks update.
- Parameters:
unit- non-null
-
getTimeUnitShortLabel
A short label you can use in axis titles ("Time (s)", etc.). -
setIntervalMs
public void setIntervalMs(long intervalMs) Set the sampling interval. If currently running, restarts the schedule.- Parameters:
intervalMs- must be > 0
-
setOnSample
Set a callback to be invoked after each drain pass on the EDT.This is a convenient place to call
repaint()without additionalSwingUtilities.invokeLater(...).- Parameters:
onSample- may be null
-
isRunning
public boolean isRunning()- Returns:
- true if actively sampling.
-
start
public void start()Start sampling. Safe to call multiple times; subsequent calls do nothing if already running. -
stop
public void stop()Stop sampling. Safe to call multiple times.This cancels the scheduled task but keeps the scheduler alive so you can
start()again. -
shutdown
public void shutdown()Permanently shut down this StripChartCurve (cannot be restarted). Use when the owning plot is being disposed. -
clearData
public void clearData()Clear all retained samples.Thread-safe: if called off-EDT, schedules the clear on the EDT. Pending queued samples are also discarded so the curve becomes truly empty.
-
snapshot
Obtain a consistent snapshot of the current data, suitable for plotting without locking. -
add
public void add(double tms, double y) Add an explicit sample (t, y) to this strip chart.Thread-safe: may be called from any thread. Off-EDT calls enqueue and schedule a coalesced EDT drain. Notifications remain EDT-only per
ACurve.- Parameters:
tms- time value (typically ms since start)y- sample value
-
doFit
public void doFit(boolean force) Perform a curve computation (fit or spline) on the strip chart's current data, depending on the configuredCurveDrawingMethod.Same dispatch as
Curve.doFit(boolean):CUBICSPLINEbuilds aCubicSpline, the parametric methods (POLYNOMIAL,ERF,ERFC,GAUSSIAN,GAUSSIANS,EXPONENTIAL_DECAY,POWER_LAW,LORENTZIAN) run the correspondingIFitter, andNONE/CONNECT/STAIRSrequire no computed artifact. Must be called on the EDT. -
length
public int length()Description copied from class:ACurveGet curve length (number of points or effective points in the data columns). -
xMin
public double xMin() -
xMax
public double xMax() -
yMin
public double yMin() -
yMax
public double yMax()
-