Class ChartScale

java.lang.Object
com.arbergashi.charts.util.ChartScale

public final class ChartScale extends Object
Utility for DPI scaling. Ensures that lines and fonts look correct on high-DPI (e.g., 4K / Retina) monitors.
Since:
2026-01-01
Version:
1.0.0
Author:
Arber Gashi
  • Method Details

    • setScaleFactor

      public static void setScaleFactor(float factor)
      Sets the global scale factor used by the chart framework.

      Framework note: This is a process-wide setting. Prefer setting it once during application startup (or call autoDetect(GraphicsConfiguration) once from the primary window). This method always overrides any previously auto-detected value.

    • autoDetect

      public static void autoDetect(GraphicsConfiguration gc)
      Auto-detects the scale factor from the given GraphicsConfiguration.

      Framework policy: This method initializes the scale factor only once. The first call with a non-null GraphicsConfiguration wins. Subsequent calls are ignored to avoid global scale thrash when windows move across monitors.

    • getScaleFactor

      public static float getScaleFactor()
      Returns the currently active global scale factor.
    • scale

      public static float scale(float value)
    • scale

      public static double scale(double value)
    • font

      public static float font(float size)
      Scales font sizes. Fonts often require slightly different scaling than geometric shapes.
    • uiFontSize

      public static float uiFontSize(Font baseFont, float sizeInDp)
      Scales a target font size in a UI-toolkit-aware way.

      Why: In modern Swing applications (e.g. FlatLaf), UIManager fonts are already HiDPI-aware and may already include the platform scale factor. If we then apply font(float) again, text becomes double-scaled.

      Policy: If the provided baseFont looks like a UI-managed font (i.e. its size already tracks the UI scale), we treat sizeInDp as the final point size. Otherwise we apply the framework scale factor.

      Parameters:
      baseFont - the font used as baseline; may be null
      sizeInDp - desired size in design units (dp)
      Returns:
      a size value suitable for Font.deriveFont(float)