Class XYPlotBuilder

java.lang.Object
edu.cnu.mdi.splot.plot.XYPlotBuilder

public final class XYPlotBuilder extends Object
Fluent construction of ordinary MDI XY plots.

The builder is deliberately a convenience layer, not a second plotting model. build() creates the same PlotData, Curve, PlotCanvas, and PlotPanel objects that an application would create directly. The resulting panel can therefore be placed in a PlotDeck, and callers retain access to every existing sPlot API.

Input arrays are defensively copied when a series is registered. A builder may be reused; each build creates a fresh plot model and fresh curves. Series style customizers receive the native ACurve, while plot customizers receive the native PlotParameters. This keeps uncommon or future MDI options accessible without continually expanding the builder.

Threading

Build plots on Swing's event-dispatch thread when they will immediately become part of a visible UI. The returned curves retain their normal thread-safe data-appending behavior.

  • Constructor Details

    • XYPlotBuilder

      public XYPlotBuilder(String title)
      Creates an empty XY plot definition.
      Parameters:
      title - plot title; must not be null
  • Method Details

    • axes

      public XYPlotBuilder axes(String xLabel, String yLabel)
      Sets both axis labels.
      Parameters:
      xLabel - horizontal-axis label
      yLabel - vertical-axis label
      Returns:
      this builder
    • decorations

      public XYPlotBuilder decorations(int decorations)
      Sets the PlotPanel decoration level.
      Parameters:
      decorations - one of PlotPanel.STANDARD, PlotPanel.BARE, or PlotPanel.VERYBARE
      Returns:
      this builder
      Throws:
      IllegalArgumentException - for an unknown value
    • series

      public XYPlotBuilder series(String name, double[] x, double[] y)
      Adds an uncustomized XY series.
      Parameters:
      name - legend name
      x - x coordinates
      y - y coordinates
      Returns:
      this builder
    • series

      public XYPlotBuilder series(String name, double[] x, double[] y, Consumer<ACurve> customizer)
      Adds an XY series with a native MDI curve customizer.

      The customizer runs during each build after the copied data have been installed and before the canvas is returned. Typical customizations set line color, symbol, width, or drawing method.

      Parameters:
      name - legend name
      x - x coordinates
      y - y coordinates
      customizer - curve style/drawing customizer
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if array lengths differ
    • configure

      public XYPlotBuilder configure(Consumer<PlotParameters> customizer)
      Adds a native plot-parameter customization applied during each build. Multiple customizers run in registration order.
      Parameters:
      customizer - parameter customizer
      Returns:
      this builder
    • build

      public PlotPanel build()
      Creates a fresh native MDI plot panel.
      Returns:
      configured plot panel
      Throws:
      IllegalStateException - if no series was registered or native plot construction unexpectedly fails