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

class ValueAxisextends Axis
Represents value axis (y-axis) in RRD graphs. Handles value-based grid lines, labels, and scaling with automatic tick placement. Supports linear, logarithmic, and MRTG-style axis formatting.
  • Field Details

    • ylabels

      private static final ValueAxis.YLabel[] ylabels
      Names of the axes that can be labelled.
    • im

      private final ImageParameters im
      Where the axis is drawn.
    • worker

      private final ImageWorker worker
      The worker drawing the graph.
    • gdef

      private final RrdGraphDef gdef
      The graph being drawn.
    • mapper

      private final Mapper mapper
      Maps data values to pixels.
  • Constructor Details

    • ValueAxis

      ValueAxis(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
    • ValueAxis

      ValueAxis(RrdGraphGenerator generator)
      Create a value axis for the given generator's graph.
      Parameters:
      generator - the generator whose definition and image parameters to use
  • Method Details

    • draw

      boolean draw()
      True if axis labels were drawn.
      Specified by:
      draw in class Axis
      Returns:
      true if labels were drawn, false for a NaN range
    • drawGridLines

      private void drawGridLines(int sgrid, int egrid, double gridstep, int x0, int x1, Paint gridColor, Paint mGridColor, int labfact)
      Draws all grid lines for the value axis. Minor grid lines use the grid color; major grid lines use the mgrid color. Separated from label drawing to produce consecutive SVG elements with identical stroke/paint, enabling tighter SVG grouping.
      Parameters:
      sgrid - index of the first grid line to consider, one below the minimum value
      egrid - index of the last grid line to consider, one above the maximum value
      gridstep - distance in graph values between adjacent grid lines
      x0 - left pixel of the line
      x1 - right pixel of the line
      gridColor - paint used for the minor grid lines
      mGridColor - paint used for the major grid lines
      labfact - every labfact-th grid line counts as major, so 1 makes all of them major
    • drawLabels

      private void drawLabels(int sgrid, int egrid, double gridstep, int x0, double scaledstep, boolean fractional, int labfact, Font font, Paint fontColor, int labelOffset)
      Draws all labels for the value axis at major grid positions.
      Parameters:
      sgrid - index of the first grid position to consider, one below the minimum value
      egrid - index of the last grid position to consider, one above the maximum value
      gridstep - distance in graph values between adjacent grid lines, used to find the pixel row of each position
      x0 - left pixel of the plot, the label is drawn to end this far in from it
      scaledstep - gridstep divided by the magnitude factor, the value printed per label
      fractional - true to print one decimal place in the label, false to print whole numbers
      labfact - only positions divisible by this get a label
      font - font used to draw and measure the label text
      fontColor - paint used for the label text
      labelOffset - pixels added to the grid line's row to place the label's baseline
    • findYLabel

      private ValueAxis.YLabel findYLabel(int desiredMinimumLabelCount)
      Finds an acceptable YLabel object for the current graph If the graph covers positive and negative on the y-axis, then desiredMinimumLabelCount is checked as well, to ensure the chosen YLabel definition will result in the required number of labels

      If none of the built-in definitions is acceptable, one is generated from the range.

      Parameters:
      desiredMinimumLabelCount - the label count the axis must exceed, only checked when the graph spans both positive and negative values
      Returns:
      the first definition with more than five pixels per gridline and enough labels, or a generated power-of-ten definition when none of the built-in ones qualifies
    • findLabelFactor

      private int findLabelFactor(ValueAxis.YLabel thisYLabel)
      Find the smallest labelFactor acceptable (can fit labels) for the given YLab definition Returns the label factor if one is ok, otherwise returns -1 if none are acceptable
      Parameters:
      thisYLabel - the definition whose four label factors are tried in order
      Returns:
      the first label factor that leaves at least two lines of text between grid lines, or -1 when none of the four fits
    • getPixelsPerGridline

      private int getPixelsPerGridline(ValueAxis.YLabel thisYLabel)
      Finds the number of pixels per gridline that the given YLabel definition will result in
      Parameters:
      thisYLabel - the definition whose grid step is measured against the graph height
      Returns:
      the whole pixels between two grid lines, rounded down, zero if the grid is finer than one pixel
    • getScaledRange

      private double getScaledRange()
      The axis range in scaled units.
      Returns:
      maxval minus minval, divided by the magnitude factor
    • isFractional

      private static boolean isFractional(double scaledstep, int labfact)
      Returns true if some or all labels have fractional part (other than zero).
      Parameters:
      scaledstep - the label step in scaled units, never fractional when it is 1 or more
      labfact - the number of grid steps between two printed labels
      Returns:
      true when scaledstep times labfact is not a whole number, so the labels need a decimal place