Class HistoDrawingUtils

java.lang.Object
edu.cnu.mdi.splot.pdata.HistoDrawingUtils

public final class HistoDrawingUtils extends Object
Stateless utility class for rendering-related histogram helpers.

This class holds the two static methods that were previously embedded in HistoData but depend on the plot package — creating a downward dependency from the data model into the view layer. Moving them here removes that dependency from HistoData itself while keeping the functionality in a single, discoverable place.

Usage


 // Build the screen polygon for hit-testing or filled drawing
 Polygon poly = HistoDrawingUtils.buildScreenPolygon(canvas, histoData);

 // Get the mouse-position status string
 String status = HistoDrawingUtils.statusString(canvas, histoData, mousePoint, worldPoint);
 
Author:
heddle (original), refactored for extraction
See Also:
  • Method Details

    • buildScreenPolygon

      public static Polygon buildScreenPolygon(PlotCanvas canvas, HistoData histo)
      Builds the screen-space Polygon that outlines the histogram bars.

      The polygon traces the top of every bar and the baseline, so it is suitable for both hit-testing (Polygon.contains(java.awt.Point)) and filled rendering. Bins whose corners cannot be projected onto the screen (e.g. because transforms are not yet initialised) are silently skipped.

      Parameters:
      canvas - the plot canvas that owns the coordinate transforms (non-null)
      histo - the histogram data to outline (non-null)
      Returns:
      a Polygon in screen (component) coordinates; may be empty if the canvas has no valid transforms
    • statusString

      public static String statusString(PlotCanvas canvas, HistoData histo, Point mousePoint, Point2D.Double wp)
      Builds the status string shown in the feedback pane when the mouse is over a histogram.

      Returns the bin range and count under the cursor, formatted using the canvas's current decimal and exponent settings. Returns an empty string when the mouse is outside the histogram polygon.

      Parameters:
      canvas - the plot canvas (provides coordinate transforms and formatting parameters) (non-null)
      histo - the histogram data being queried (non-null)
      mousePoint - current mouse position in screen (component) coordinates (non-null)
      wp - current mouse position in data coordinates (non-null)
      Returns:
      a formatted status string, or "" if the cursor is outside the histogram