Class HistoCurve
HistoData into the
ACurve fitting and drawing framework.
Thread-safety
The ACurve contract requires that notifications (e.g.
ACurve.markDataChanged()) occur on the Swing Event Dispatch Thread (EDT).
This class preserves that contract while allowing histogram filling from any
thread:
- If
add(double)oraddAll(double[])are called on the EDT, they apply immediately and notify once. - If called off the EDT, values are enqueued and a coalesced EDT drain is scheduled. The drain applies many samples in bulk and notifies once.
clearData()follows the same pattern: on the EDT it clears immediately, off the EDT it discards any pending samples and defers the clear to the EDT.
- Author:
- heddle
-
Nested Class Summary
Nested classes/interfaces inherited from class edu.cnu.mdi.splot.pdata.ACurve
ACurve.PendingQueue<T> -
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionHistoCurve(String name, HistoData histoData) Create a histogram-backed curve. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(double x) Add a value to the histogram.voidaddAll(double[] x) Add multiple values to the histogram.voidClear histogram contents and statistics.voiddoFit(boolean force) Perform a curve computation (fit or spline) depending on theCurveDrawingMethod.intdrainPendingOnEDT(int max) Drain pending enqueued values on the EDT and apply them to the histogram.intlength()Length is defined as the number of bins.snapshot()Obtain a consistent snapshot of the current data, suitable for plotting without locking.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
-
HistoCurve
Create a histogram-backed curve.- Parameters:
name- curve name (legend label)histoData- backing histogram data (non-null)
-
-
Method Details
-
getHistoData
- Returns:
- the backing histogram data
-
length
public int length()Length is defined as the number of bins. -
doFit
public void doFit(boolean force) Perform a curve computation (fit or spline) depending on theCurveDrawingMethod. -
xMin
public double xMin() -
xMax
public double xMax() -
yMin
public double yMin() -
yMax
public double yMax() -
add
public void add(double x) Add a value to the histogram.Safe from any thread. Off-EDT calls enqueue and schedule a coalesced EDT drain. The
ACurvenotification contract is preserved:ACurve.markDataChanged()is invoked on the EDT only.- Parameters:
x- the value to add
-
addAll
public void addAll(double[] x) Add multiple values to the histogram.Safe from any thread. Off-EDT calls enqueue and schedule a coalesced EDT drain. The
ACurvenotification contract is preserved:ACurve.markDataChanged()is invoked on the EDT only.- Parameters:
x- the values to add (non-null)
-
drainPendingOnEDT
public int drainPendingOnEDT(int max) Drain pending enqueued values on the EDT and apply them to the histogram.This method is EDT-only because it ultimately fires
ACurve.markDataChanged().- Parameters:
max- maximum number of values to apply in this drain pass- Returns:
- number of drained values
-
clearData
public void clearData()Clear histogram contents and statistics.Safe from any thread, honoring the
ACurve.clearData()contract. If called off the EDT, any not-yet-applied pending samples are discarded and the clear is deferred to (and coalesced with other scheduled drains on) the EDT. TheACurvenotification contract is preserved:ACurve.markDataChanged()is invoked on the EDT only. -
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.
-