java.lang.Object
org.rrd4j.graph.RrdGraphGenerator

class RrdGraphGeneratorextends Object
Core graph generation engine for RRD graphs. Orchestrates entire graph creation process from data processing to image rendering. Handles data fetching, scaling, layout, and all rendering operations.
  • Field Details

    • AXIS_STROKE_WIDTH

      static final float AXIS_STROKE_WIDTH
      Width the axis container lines are drawn with, chosen so the SVG post-processor tags them class="axis". Not the width the user sees: the theme's .axis rule sets that.
      See Also:
    • SENSIBLE_VALUES

      private static final double[] SENSIBLE_VALUES
      Axis bounds chosen when the data gives no good one.
    • SYMBOLS_CENTER

      private static final int SYMBOLS_CENTER
      Index of the base unit in the symbol table.
      See Also:
    • SYMBOLS

      private static final char[] SYMBOLS
      Unit symbols, ordered by magnitude.
    • gdef

      final RrdGraphDef gdef
      The graph definition this generator renders.
    • worker

      final ImageWorker worker
      The worker that runs and caches the rendering.
    • dproc

      private final DataProcessor dproc
      The processor that reads source data and applies consolidation.
    • mapper

      Mapper mapper
      The rule set that maps data sources to graph lines and areas.
    • info

      final RrdGraphInfo info
      Metadata about the graph, such as its value range and time bounds.
    • signature

      private final String signature
      Cache key identifying this definition's settings.
    • im

      final ImageParameters im
      The dimensions and text layout of the rendered image.
  • Constructor Details

    • RrdGraphGenerator

      RrdGraphGenerator(RrdGraphDef gdef, ImageWorker worker, DataProcessor dproc)
      Create a generator for one graph definition.
      Parameters:
      gdef - the definition describing what to plot
      worker - the worker that runs and caches the rendering
      dproc - the processor supplying consolidated data
  • Method Details

    • createGraph

      void createGraph() throws IOException
      Create graph
      Throws:
      IOException - if the source RRD cannot be read while fetching data or the rendered image cannot be written out
    • collectInfo

      private void collectInfo()
      Collect info
    • saveImage

      private void saveImage() throws IOException
      Save image
      Throws:
      IOException - if the image file cannot be written
    • drawOverlay

      private void drawOverlay() throws IOException
      Draw overlay
      Throws:
      IOException - if the overlay image file cannot be read
    • gator

      private void gator()
      Draws the vertical graph signature along the left edge.
    • countPlottedSeries

      static int countPlottedSeries(List<PlotElement> plotElements)
      Counts the independently plotted series in a graph, which decides whether the lines are drawn solid or dotted.

      Counts Line and Area together. An area counts because it is drawn with an outline, so a graph made of a filled total plus a subset line has two lines on it and the subset must be dotted to match. Stack stays excluded: a stack is one quantity split into bands, not several series.

      Parameters:
      plotElements - the graph's plot elements, may be null
      Returns:
      number of plotted series, zero for an empty or null list
    • drawRulesAndSpans

      private void drawRulesAndSpans()
      Draw rules and spans
    • drawText

      private void drawText()
      Draw text
    • drawGrid

      private void drawGrid()
      Draw grid
    • valueShadePaint

      private Paint valueShadePaint(Color[] stops)
      Build the vertical gradient that shades a series line by its value.

      The gradient runs from the bottom of the plot area to the top, which is what makes it read by value rather than by position: a point's height above the baseline is its magnitude, so the paint at that height is the colour for that magnitude. Three or more stops need LinearGradientPaint, the only one of the two gradient types that holds an arbitrary number; either way the stops are spread evenly over the span.

      Parameters:
      stops - bottom-to-top colour stops, or null for a flat line
      Returns:
      the gradient paint, or null when no shading was asked for
    • drawData

      private void drawData()
      Draw data
    • drawAxis

      private void drawAxis()
      Draw axis
    • drawBackground

      private void drawBackground() throws IOException
      Draw background
      Throws:
      IOException - if a background or canvas image file cannot be read
    • createImageWorker

      private void createImageWorker()
      Create image worker
    • placeLegends

      private void placeLegends()
      Place legends
    • initializeLimits

      private void initializeLimits()
      Initialize limits
    • removeOutOfRangeRules

      private void removeOutOfRangeRules()
      Remove out of range rules
    • removeOutOfRangeSpans

      private void removeOutOfRangeSpans()
      Remove out of range spans
    • expandValueRange

      private void expandValueRange()
      Expand value range
    • identifySiUnit

      private void identifySiUnit()
      Identify si unit
    • findMinMaxValues

      private void findMinMaxValues()
      Find min max values
    • calculatePlotValues

      private void calculatePlotValues()
      Calculate plot values
    • resolveTextElements

      private void resolveTextElements()
      Resolve text elements
    • fetchData

      private void fetchData() throws IOException
      Fetch data
      Throws:
      IOException - if a source's RRD file cannot be read
    • lazyCheck

      private boolean lazyCheck() throws IOException
      Lazy check
      Returns:
      true if the existing image is fresh enough that the graph need not be redrawn
      Throws:
      IOException - if the image file's last-modified time cannot be read
    • drawLegend

      private void drawLegend()
      Draw legend
    • getFontHeight

      double getFontHeight(RrdGraphConstants.FontTag fonttag)
      Return the font height
      Parameters:
      fonttag - the text element whose configured font is measured
      Returns:
      the height in pixels of a line of that element's font
    • getFontCharWidth

      double getFontCharWidth(RrdGraphConstants.FontTag fonttag)
      Return the font char width
      Parameters:
      fonttag - the text element whose configured font is measured
      Returns:
      the width in pixels of one average character of that font
    • getInterlegendSpace

      double getInterlegendSpace()
      Return the inter-legend space
      Returns:
      the blank gap in pixels left between inter-legend rows
    • getLeading

      double getLeading()
      The vertical advance applied between legend rows.
      Returns:
      the line advance in pixels applied between legend rows
    • getSmallLeading

      double getSmallLeading()
      Line spacing for small legend text.
      Returns:
      the legend font height times the small leading factor
    • getBoxSpace

      double getBoxSpace()
      Space around the legend box.
      Returns:
      the legend font height times the box space factor, rounded up
    • getBox

      private double getBox()
      Chooses a round grid spacing for the axis.
      Returns:
      the spacing between grid lines
    • xtr

      private double[] xtr(long[] timestamps)
      Converts timestamps to pixel coordinates, duplicating each step.
      Parameters:
      timestamps - the sample timestamps to map, at least one
      Returns:
      the pixel x of each timestamp, each repeated so the polyline steps
    • xtrDistinct

      private double[] xtrDistinct(long[] timestamps)
      Converts timestamps to pixel x with one point per sample.

      xtr(long[]) deliberately writes each sample's x twice so that the polyline is forced into a staircase: a horizontal run to each sample, then a vertical jump to the next. That is what gives the plots their stepped look, but it also means every value change lands on a zero-width edge, leaving no horizontal room for a curve to cross. The smoothed renderer needs the undoubled positions so a transition spans the pixels between samples.

      Parameters:
      timestamps - sample timestamps, one per data point and not pre-doubled
      Returns:
      one pixel x per timestamp
    • ytr

      private double[] ytr(double[] values)
      Converts values to pixel coordinates, duplicating each step.
      Parameters:
      values - the sample values to map, NaN marks a gap, at least one
      Returns:
      the pixel y of each value, each repeated so the polyline steps
    • ytrDistinct

      private double[] ytrDistinct(double[] values)
      Converts values to pixel y with one point per sample.

      The undoubled counterpart of ytr(double[]); see xtrDistinct(long[]) for why the doubled form exists and why the smoothed renderer must not use it. Gaps stay NaN so PathIterator still splits the series where the data does.

      Parameters:
      values - sample values, possibly containing NaN
      Returns:
      one pixel y per value