java.lang.Object
net.i2p.router.web.helpers.RingRenderer

public class RingRendererextends Object
Reusable SVG ring chart generator for health-ring dashboards. Produces inline SVG markup compatible with the ring CSS in shared.css.
  • Field Details

    • RING_SIZE

      private static final int RING_SIZE
      Diameter of the ring gauge, in pixels.
      See Also:
    • RING_STROKE

      private static final int RING_STROKE
      Width of the ring band, in pixels.
      See Also:
    • RING_RADIUS

      private static final int RING_RADIUS
      Radius of the ring band's centre line, in pixels.
      See Also:
    • RING_CIRCUM

      private static final double RING_CIRCUM
      Circumference of that centre line, for the dash pattern.
      See Also:
    • MODE_HEALTH

      public static final String MODE_HEALTH
      Mode: health (green/yellow/red), activity (blue/cyan).
      See Also:
    • MODE_ACTIVITY

      public static final String MODE_ACTIVITY
      Ring mode colouring the arc by how recently the peer was seen.
      See Also:
    • MODE_LATENCY

      public static final String MODE_LATENCY
      Ring mode colouring the arc by the peer's transport latency.
      See Also:
    • MODE_RATIO

      public static final String MODE_RATIO
      Mode: dual-arc ratio (green + red arcs showing a proportion).
      See Also:
    • MODE_NEUTRAL

      public static final String MODE_NEUTRAL
      Mode: neutral (green/yellow/cyan, never red — for uptime, metrics that aren't inherently bad).
      See Also:
    • MODE_ANOMALY

      public static final String MODE_ANOMALY
      Mode: anomaly — color by deviation from the router's own baseline, not an absolute cap.
      See Also:
    • ANOMALY_GREEN_BAND

      static final double ANOMALY_GREEN_BAND
      In anomaly mode, a stat above its baseline stays green while it is at most this much higher than the baseline (a quarter), measured as (current - baseline) / baseline.
      See Also:
    • ANOMALY_YELLOW_BAND

      static final double ANOMALY_YELLOW_BAND
      In anomaly mode, a stat above its baseline stays yellow while it is at most this much higher than the baseline (three quarters); beyond that it is red.
      See Also:
    • PLOT_BARS

      public static final String PLOT_BARS
      Plot type: mini bars at the bottom of the ring.
      See Also:
    • PLOT_LINE

      public static final String PLOT_LINE
      Plot type: line chart clipped to the inner circle area.
      See Also:
    • _clipId

      private static final AtomicInteger _clipId
      Counts the clip paths so each ring gets a unique id.
  • Constructor Details

  • Method Details

    • renderRing

      public static String renderRing(double score, String label, String value)
      Render a single SVG ring chart.
      Parameters:
      score - 0.0–1.0 fill level, or < 0 for "collecting" (gray)
      label - short label displayed below the percentage
      value - value string displayed in the center (e.g. "93%", "12", "1.2s")
      Returns:
      inline SVG markup
    • renderRing

      public static String renderRing(double score, String label, String value, String mode)
      Render a single SVG ring chart with a specified color mode.
      Parameters:
      score - 0.0–1.0 fill level, or < 0 for "collecting" (gray)
      label - short label displayed below the percentage
      value - value string displayed in the center
      mode - color mode, one of the MODE_* constants
      Returns:
      inline SVG markup
    • renderRing

      public static String renderRing(double score, String label, String value, String mode, double[] history)
      Render a single SVG ring chart with sparkline history.
      Parameters:
      score - 0.0–1.0 fill level, or < 0 for "collecting" (gray)
      label - short label displayed below the percentage
      value - value string displayed in the center
      mode - color mode, one of the MODE_* constants
      history - recent data points for sparkline, or null to omit
      Returns:
      inline SVG markup
    • renderRing

      public static String renderRing(double score, String label, String value, String mode, double[] history, String plotType)
      Render a single SVG ring chart with sparkline history and configurable plot type.
      Parameters:
      score - 0.0–1.0 fill level, or < 0 for "collecting" (gray)
      label - short label displayed below the percentage
      value - value string displayed in the center
      mode - color mode, one of the MODE_* constants
      history - recent data points for sparkline, or null to omit
      plotType - PLOT_BARS or PLOT_LINE (defaults to PLOT_LINE when null)
      Returns:
      inline SVG markup
    • renderRing

      public static String renderRing(double score, String label, String value, String mode, double[] history, String plotType, String forcedColor)
      Render a ring with an explicit color class override. When forcedColor is non-null it is used for the arc/text/plot color instead of the score-derived class (used by MODE_ANOMALY, where color reflects deviation from baseline rather than the raw fill level).
      Parameters:
      score - 0.0–1.0 fill level, or < 0 for "collecting" (gray)
      label - short label displayed below the percentage
      value - value string displayed in the center
      mode - color mode, one of the MODE_* constants
      history - recent data points for sparkline, or null to omit
      plotType - PLOT_BARS or PLOT_LINE (defaults to PLOT_LINE when null)
      forcedColor - explicit CSS class ("green"/"yellow"/"red"/"gray"), or null
      Returns:
      inline SVG markup
    • appendLinePlotDefs

      private static void appendLinePlotDefs(StringBuilder buf)
      Appends the SVG defs shared by the line plots.
      Parameters:
      buf - where the markup is written
    • appendLinePlot

      private static void appendLinePlot(StringBuilder buf, double[] history, String cls)
      Appends one sparkline plot to the markup.
      Parameters:
      buf - where the markup is written
      history - the values to plot
      cls - the CSS colour class applied to the plot
    • appendBarPlot

      private static void appendBarPlot(StringBuilder buf, double[] history, String cls)
      Append sparkline bar chart to the SVG buffer. Histogram bars rendered at the bottom of the ring area.
      Parameters:
      buf - the SVG buffer to append the bars to
      history - histogram values; NaN entries are skipped and fewer than two valid values render nothing
      cls - CSS class for the bar rects
    • renderRingCell

      public static String renderRingCell(double score, String label, String value, String[] details)
      Render a ring cell (ring + optional tooltip) for use inside a grid.
      Parameters:
      score - 0.0–1.0 fill level
      label - short label
      value - value string in the center
      details - tooltip lines, or null/empty for no tooltip
      Returns:
      HTML for the ring-cell div
    • renderRingCell

      public static String renderRingCell(double score, String label, String value, String[] details, String mode)
      Render a ring cell with a specified color mode.
      Parameters:
      score - 0.0–1.0 fill level
      label - short label
      value - value string in the center
      details - tooltip lines, or null/empty for no tooltip
      mode - color mode, one of the MODE_* constants
      Returns:
      HTML for the ring-cell div
    • renderRingCell

      public static String renderRingCell(double score, String label, String value, String[] details, String mode, double[] history)
      Render a ring cell with sparkline history bars.
      Parameters:
      score - 0.0–1.0 fill level
      label - short label
      value - value string in the center
      details - tooltip lines, or null/empty for no tooltip
      mode - color mode, one of the MODE_* constants
      history - recent data points for sparkline, or null to omit
      Returns:
      HTML for the ring-cell div
    • renderRingCell

      public static String renderRingCell(double score, String label, String value, String[] details, String mode, double[] history, String forcedColor)
      Render a ring cell with an explicit color class override. When forcedColor is non-null it is used for the arc/text/plot color instead of the score-derived class (used by MODE_ANOMALY).
      Parameters:
      score - 0.0–1.0 fill level
      label - short label
      value - value string in the center
      details - tooltip lines, or null/empty for no tooltip
      mode - color mode, one of the MODE_* constants
      history - recent data points for sparkline, or null to omit
      forcedColor - explicit CSS class ("green"/"yellow"/"red"/"gray"), or null
      Returns:
      HTML for the ring-cell div
    • renderRing

      public static String renderRing(RingRenderer.RingSection[] sections, String value, String label)
      Render a multi-section ring SVG with proportional colored arcs.
      Parameters:
      sections - array of sections (values normalized to sum 1.0)
      value - center text (e.g. "70%")
      label - label below the center text
      Returns:
      inline SVG markup
    • renderRingCell

      public static String renderRingCell(RingRenderer.RingSection[] sections, String value, String label, String[] details)
      Render a multi-section ring cell.
      Parameters:
      sections - array of sections (values normalized to sum 1.0)
      value - the text drawn in the center of the ring, HTML-escaped
      label - label below the center text
      details - tooltip lines, or null/empty to omit
      Returns:
      HTML for the ring-cell div
    • getColorClass

      static String getColorClass(double score, boolean collecting, String mode)
      Determine the CSS color class based on score, collecting state, and mode.
      Parameters:
      score - 0.0–1.0 (never negative here)
      collecting - true if data is still being gathered
      mode - selects the colour ramp: MODE_ACTIVITY blue/cyan/gray, MODE_NEUTRAL green/yellow/cyan, MODE_ANOMALY and the default modes green/yellow/red, by descending score
      Returns:
      CSS class name
    • esc

      private static String esc(String s)
      HTML-escape a string.
      Parameters:
      s - the text to escape, may be null
      Returns:
      the text with &, <, >, quotes and apostrophes escaped, or "" for null input