java.lang.Object
org.rrd4j.graph.RrdGraphMeta

public final class RrdGraphMetaextends Object
The plot geometry and series behind a rendered graph, in a form a script can invert: given a cursor position in image pixels it yields the time and the value at that point.

A graph is served as an <img>, which makes the SVG an isolated document - script does not run inside it and the parent page cannot read its DOM. The numbers a tooltip needs therefore have to travel separately from the picture, which is what this class is for.

Units

Time is epoch seconds, matching ImageParameters.start and ImageParameters.end. Values are in the axis' own display unit, the same one ValueAxis prints before appending a K/M/G suffix: both the axis bounds and every series value are divided by ImageParameters.magfact, so the pair stays consistent whichever branch set the bounds and a client can invert linearly without knowing the factor.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private List<String>
    The CSS colour per series, parallel to series, or null where the plot element was painted with something that has no single colour.
    private long
    The end time of the graph.
    private List<double[]>
    The data series of the graph.
    private long
    The start time of the graph.
    private int
    The x origin of the graph.
    private int
    The width of the graph.
    private double
    The highest value of the y axis.
    private double
    The lowest value of the y axis.
    private int
    The y origin of the graph.
    private int
    The height of the graph.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Package-private: instances are created by the renderer.
  • Method Summary

    Modifier and Type
    Method
    Description
    private static String
    hexOf(Paint paint)
    The CSS colour of a plot element, for a readout swatch to match the graph's own legend.
    boolean
    Whether there is enough here to invert a cursor position: a plot area, a non-degenerate time span, a non-degenerate value range and at least one series.
    (package private) void
    Populates this metadata from a finished render.
    private static String
    round(double v)
    Rounds for transport: three decimals is finer than any axis label.
    Renders the metadata as compact JSON for a client-side overlay.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • xOrigin

      private int xOrigin
      The x origin of the graph.
    • yOrigin

      private int yOrigin
      The y origin of the graph.
    • xSize

      private int xSize
      The width of the graph.
    • ySize

      private int ySize
      The height of the graph.
    • start

      private long start
      The start time of the graph.
    • end

      private long end
      The end time of the graph.
    • yMin

      private double yMin
      The lowest value of the y axis.
    • yMax

      private double yMax
      The highest value of the y axis.
    • series

      private List<double[]> series
      The data series of the graph.
    • colors

      private List<String> colors
      The CSS colour per series, parallel to series, or null where the plot element was painted with something that has no single colour.
  • Constructor Details

    • RrdGraphMeta

      RrdGraphMeta()
      Package-private: instances are created by the renderer.
  • Method Details

    • populate

      void populate(ImageParameters im, List<PlotElement> plotElements)
      Populates this metadata from a finished render.
      Parameters:
      im - the render's image parameters, holding the plot rect and axis bounds
      plotElements - the definition's plot elements, holding the series values
    • hexOf

      private static String hexOf(Paint paint)
      The CSS colour of a plot element, for a readout swatch to match the graph's own legend.

      Taken from the element that drew the line, so the swatch cannot drift from the legend when a theme changes. A fill may be a gradient or a texture rather than a flat colour, and those have no single swatch equivalent, so they yield null and the caller falls back to the stylesheet's own colour.

      Parameters:
      paint - the element's paint, may be null
      Returns:
      a #rrggbb string, with alpha as #rrggbbaa when translucent, or null
    • isInvertible

      public boolean isInvertible()
      Whether there is enough here to invert a cursor position: a plot area, a non-degenerate time span, a non-degenerate value range and at least one series. A flat or empty graph produces a zero-height range, and dividing by it would yield infinities.
      Returns:
      true when the metadata is usable
    • toJson

      public String toJson()
      Renders the metadata as compact JSON for a client-side overlay.

      Values are rounded to a fixed number of decimals: the client only ever displays them, and full double precision would triple the payload for no visible gain. Non-finite samples become null so the payload stays valid JSON - a NaN in a series is a gap, not a value.

      Returns:
      the JSON document, never null
    • round

      private static String round(double v)
      Rounds for transport: three decimals is finer than any axis label.
      Parameters:
      v - the value to round
      Returns:
      v rounded to three decimals, as a string