Class Axis

java.lang.Object
org.aesh.charts.axis.Axis

public class Axis extends Object
Renders a numeric axis with labels and tick marks.
  • Constructor Details

    • Axis

      public Axis()
  • Method Details

    • min

      public Axis min(double min)
    • max

      public Axis max(double max)
    • label

      public Axis label(String label)
    • scale

      public Axis scale(Scale scale)
    • tickCount

      public Axis tickCount(int tickCount)
    • format

      public Axis format(String pattern)
    • tickFormatter

      public Axis tickFormatter(Function<Double,String> formatter)
      Set a custom tick label formatter. Takes priority over format(String). Use this to map numeric tick values to arbitrary label strings (#589).
      Parameters:
      formatter - function that converts a tick value to a label string
      Returns:
      this axis for fluent chaining
    • min

      public double min()
    • max

      public double max()
    • label

      public String label()
    • scale

      public Scale scale()
    • autoRange

      public void autoRange(double dataMin, double dataMax)
      Auto-set min/max from data range, rounding to nice tick-aligned bounds. Uses a "nice number" algorithm that picks tick intervals from {1, 2, 2.5, 5, 10} * 10^n, then aligns min/max to those intervals. This produces tight, readable axis bounds like 0-20 or 0-25 instead of excessive padding like -1 to 30 (#585).
    • normalize

      public double normalize(double value)
      Map a data value to a normalized position (0.0 = min, 1.0 = max).
    • denormalize

      public double denormalize(double normalized)
      Map a normalized position (0.0-1.0) back to a data value.
    • tickValues

      public double[] tickValues()
      Generate tick values for this axis.
    • formatTick

      public String formatTick(double value)
      Format a tick value as a label string.
    • labelWidth

      public int labelWidth()
      Compute the width needed for Y-axis labels, tick mark, and optional vertical label text.
    • drawYAxis

      public void drawYAxis(Canvas canvas, int x, int yTop, int yBottom, ChartStyle style)
      Draw a left Y-axis on the canvas.
      Parameters:
      canvas - the canvas
      x - x position of the axis line
      yTop - top y position
      yBottom - bottom y position
      style - chart style
    • drawXAxis

      public void drawXAxis(Canvas canvas, int xLeft, int xRight, int y, ChartStyle style)
      Draw a bottom X-axis on the canvas.
      Parameters:
      canvas - the canvas
      xLeft - left x position
      xRight - right x position
      y - y position of the axis line
      style - chart style