Class HistoCurve

java.lang.Object
edu.cnu.mdi.splot.pdata.ACurve
edu.cnu.mdi.splot.pdata.HistoCurve

public class HistoCurve extends ACurve
Histogram-backed curve that integrates 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) or addAll(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
  • Constructor Details

    • HistoCurve

      public HistoCurve(String name, HistoData histoData)
      Create a histogram-backed curve.
      Parameters:
      name - curve name (legend label)
      histoData - backing histogram data (non-null)
  • Method Details

    • getHistoData

      public HistoData getHistoData()
      Returns:
      the backing histogram data
    • length

      public int length()
      Length is defined as the number of bins.
      Specified by:
      length in class ACurve
      Returns:
      curve length
    • doFit

      public void doFit(boolean force)
      Perform a curve computation (fit or spline) depending on the CurveDrawingMethod.
      Specified by:
      doFit in class ACurve
      Parameters:
      force - true to force recomputation even if not dirty
    • xMin

      public double xMin()
      Specified by:
      xMin in class ACurve
      Returns:
      the minimum x value for this curve
    • xMax

      public double xMax()
      Specified by:
      xMax in class ACurve
      Returns:
      the maximum x value for this curve
    • yMin

      public double yMin()
      Specified by:
      yMin in class ACurve
      Returns:
      the minimum y value for this curve
    • yMax

      public double yMax()
      Specified by:
      yMax in class ACurve
      Returns:
      the maximum y value for this curve
    • 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 ACurve notification 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 ACurve notification 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. The ACurve notification contract is preserved: ACurve.markDataChanged() is invoked on the EDT only.

      Specified by:
      clearData in class ACurve
    • snapshot

      public Snapshot snapshot()
      Description copied from class: ACurve
      Obtain 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.

      Specified by:
      snapshot in class ACurve
      Returns:
      snapshot of plot-ready data