Class GridCalculator

java.lang.Object
pl.polsl.rtsa.controller.GridCalculator

public final class GridCalculator extends Object
Utility for calculating grid line positions for plot axes. Uses the 1–2–5 sequence so tick labels are always human-readable
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    Computed grid information.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    calculate(double min, double max, int targetDivisions)
    Calculate grid lines for a given visible range.
    static String
    formatFrequency(double hz, double step)
    Format a frequency value with the most readable unit (Hz, kHz).
    static String
    formatTime(double seconds, double step)
    Format a time value with the most readable unit (s, ms, µs).
    static String
    formatValue(double value, double step)
    Format a numeric value with precision appropriate for the grid step.
    static double
    niceNumber(double value)
    Round to the nearest number in the 1–2–5 decade sequence.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • GridCalculator

      private GridCalculator()
  • Method Details

    • calculate

      public static GridCalculator.GridInfo calculate(double min, double max, int targetDivisions)
      Calculate grid lines for a given visible range.
      Parameters:
      min - visible minimum value
      max - visible maximum value
      targetDivisions - desired number of divisions
      Returns:
      grid info with start position, step, and count of grid lines
    • niceNumber

      public static double niceNumber(double value)
      Round to the nearest number in the 1–2–5 decade sequence.
    • formatValue

      public static String formatValue(double value, double step)
      Format a numeric value with precision appropriate for the grid step. Avoids displaying "-0.0" for values very close to zero.
    • formatTime

      public static String formatTime(double seconds, double step)
      Format a time value with the most readable unit (s, ms, µs).
    • formatFrequency

      public static String formatFrequency(double hz, double step)
      Format a frequency value with the most readable unit (Hz, kHz).