java.lang.Object
org.rrd4j.graph.Axis
org.rrd4j.graph.TimeAxis
All Implemented Interfaces:
RrdGraphConstants

class TimeAxisextends Axis
Represents the time axis (x-axis) in RRD graphs. Handles time-based grid lines, labels, and tick marks with configurable formatting. Automatically selects appropriate time intervals based on graph time range and pixel density.
  • Field Details

    • tickSettings

      private static final TimeAxisSetting[] tickSettings
      Tick spacing and labels for each time span.
    • im

      private final ImageParameters im
      The image being drawn.
    • worker

      private final ImageWorker worker
      Where the axis is drawn.
    • gdef

      private final RrdGraphDef gdef
      The graph definition being drawn.
    • mapper

      private final Mapper mapper
      Maps between time and pixel positions.
    • tickSetting

      private TimeAxisSetting tickSetting
      Tick setting
    • secPerPix

      private final double secPerPix
      Seconds each horizontal pixel covers.
    • calendar

      private final Calendar calendar
      Calendar used to break times into fields.
  • Constructor Details

    • TimeAxis

      TimeAxis(RrdGraph rrdGraph, ImageWorker worker)
      Used for tests
      Parameters:
      rrdGraph - the graph whose image and definition set up this axis
      worker - the image worker painting the graph
    • TimeAxis

      TimeAxis(RrdGraphGenerator generator)
      Sets up this axis from an in-progress generator, reusing the image parameters, worker, graph definition and mapper the generator has already built.
      Parameters:
      generator - the graph generator that is painting the graph this axis belongs to
  • Method Details

    • draw

      boolean draw()
      Paints ticks, grids and labels along the time axis, returning false if no tick settings could be chosen.
      Specified by:
      draw in class Axis
      Returns:
      true if the axis was successfully drawn, false otherwise
    • collectMajorGridX

      private Set<Integer> collectMajorGridX()
      Walks the major unit positions and returns the x coordinates they land on.

      Collected before anything is drawn so the minor pass can leave them alone. Keyed on the mapped x rather than on the timestamp because the major unit can be a month or a year, which has no fixed length in seconds to test a position against.

      Returns:
      the x coordinates claimed by a major gridline, never null
    • drawMinorTicks

      private void drawMinorTicks()
      Draw minor ticks
    • drawMajorTicks

      private void drawMajorTicks()
      Draw major ticks
    • drawMinorGrids

      private void drawMinorGrids(Set<Integer> majorX)
      Draw minor grids, skipping any position a major gridline already claimed.
      Parameters:
      majorX - x coordinates owned by the major grid, drawn by drawMajorGrids()
    • drawMajorGrids

      private void drawMajorGrids()
      Draw major grids
    • drawLabels

      private void drawLabels()
      Draw labels
    • findNextTime

      private void findNextTime(TimeUnit timeUnit, int timeUnitCount)
      Find next time
      Parameters:
      timeUnit - the calendar unit to advance
      timeUnitCount - the number of units to advance
    • getTimeShift

      private int getTimeShift()
      Chooses how far labels are shifted for readability.
      Returns:
      the shift, in pixels
    • adjustStartingTime

      private void adjustStartingTime(TimeUnit timeUnit, int timeUnitCount)
      Adjust starting time
      Parameters:
      timeUnit - the calendar unit to align to
      timeUnitCount - the tick spacing in those units
    • chooseTickSettings

      private void chooseTickSettings()
      Choose tick settings