Class Histogram2D

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable

public class Histogram2D extends JComponent
A lightweight pseudo-3D renderer for a Histo2DData 2D histogram.

This component draws each histogram bin as a 3D-looking pillar (top + side faces) using pure Java2D (no JOGL). A painter's algorithm (depth sort) is used to render bins from far-to-near so occlusion looks correct.

Interaction:

  • Left-drag: rotate (about X and Y)
  • Mouse wheel: zoom
  • Move mouse: hover highlight (top face hit-test)

Performance notes:

  • No per-bar allocations during painting (no new int[] per bin).
  • Depth array and index array are primitive and reused.
  • Depth-sort is recomputed only when rotation/zoom/size changes (not on mouse move).
  • Trigonometric values are cached per frame.

Drop-in behavior

This is intended as a drop-in replacement for the prototype BackedHistogram2D you shared: same package/class name, same constructor signature and same mouse gestures. Each frame uses Histo2DData.snapshotBins() so concurrent fills cannot produce a partially updated rendering.
See Also:
  • Constructor Details

    • Histogram2D

      public Histogram2D(Histo2DData data, ScientificColorMap colorMap)
      Create a pseudo-3D histogram view for the given data.
      Parameters:
      data - histogram data (must not be null)
      colorMap - colormap used to color pillars by bin content (must not be null)
  • Method Details

    • setData

      public void setData(Histo2DData data)
      Set the backing data.

      This is optional but handy if you reuse the component for new histograms.

      Parameters:
      data - new data (must not be null)
    • setColorMap

      public void setColorMap(ScientificColorMap colorMap)
      Set the colormap.
      Parameters:
      colorMap - new colormap (must not be null)
    • setLogZ

      public void setLogZ(boolean logZ)
      Enable or disable log-Z mapping for pillar height and color.

      When enabled, each bin value z is mapped to log10(1 + max(z,0)). This compresses dynamic range while keeping empty bins at 0.

      Parameters:
      logZ - true to enable log-Z mapping; false for linear mapping
    • isLogZ

      public boolean isLogZ()
      Returns:
      true if log-Z mapping is enabled
    • getHoveredI

      public int getHoveredI()
      Returns:
      last hovered x-bin index, or -1 if none
    • getHoveredJ

      public int getHoveredJ()
      Returns:
      last hovered y-bin index, or -1 if none
    • paintComponent

      protected void paintComponent(Graphics g)
      Overrides:
      paintComponent in class JComponent