Class Curve

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

public class Curve extends ACurve
A standard XY curve consisting of X, Y, and an optional Y-error column (E).

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
  • Constructor Details

    • Curve

      public Curve(String name, DataColumn xData, DataColumn yData, DataColumn eData) throws PlotDataException
      Create a standard XY curve.
      Parameters:
      name - the curve name
      xData - 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: ACurve
      Get curve length (number of points or effective points in the data columns).
      Specified by:
      length in class ACurve
      Returns:
      curve length
    • xData

      public DataColumn xData()
      Returns:
      the x data column (backing storage; do not mutate externally)
    • yData

      public DataColumn yData()
      Returns:
      the y data column (backing storage; do not mutate externally)
    • eData

      public DataColumn eData()
      Returns:
      the optional y-error data column (may be null)
    • doFit

      public void doFit(boolean force)
      Description copied from class: ACurve
      Perform a curve fit (or compute derived artifacts like splines), depending on the configured curve drawing method.
      Specified by:
      doFit in class ACurve
      Parameters:
      force - true to force a refit even if not dirty
    • 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 values
      y - array of y values
      ey - 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.

      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
    • 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
    • getPendingCount

      public long getPendingCount()
    • drainPendingOnEDT

      public int drainPendingOnEDT(int max)
      Drain up to max pending 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

      public void startPendingDrainTimer(int periodMs, int maxPerTick, IntConsumer drainedCallback)
    • 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

      public Point2D.Double getCentroid()
      Get the centroid of the curve data points.
      Returns:
      the centroid as a Point2D.Double