java.lang.Object
net.i2p.router.web.helpers.RingRenderer
Reusable SVG ring chart generator for health-ring dashboards. Produces inline SVG markup compatible with the ring CSS in shared.css.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA section of a multi-section ring with a proportion and color class.Field Summary
Modifier and TypeFieldDescriptionprivate static final AtomicIntegerCounts the clip paths so each ring gets a unique id.(package private) static final doubleIn 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.(package private) static final doubleIn 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.static final StringRing mode colouring the arc by how recently the peer was seen.static final StringMode: anomaly — color by deviation from the router's own baseline, not an absolute cap.static final StringMode: health (green/yellow/red), activity (blue/cyan).static final StringRing mode colouring the arc by the peer's transport latency.static final StringMode: neutral (green/yellow/cyan, never red — for uptime, metrics that aren't inherently bad).static final StringMode: dual-arc ratio (green + red arcs showing a proportion).static final StringPlot type: mini bars at the bottom of the ring.static final StringPlot type: line chart clipped to the inner circle area.private static final doubleCircumference of that centre line, for the dash pattern.private static final intRadius of the ring band's centre line, in pixels.private static final intDiameter of the ring gauge, in pixels.private static final intWidth of the ring band, in pixels.Constructor Summary
ConstructorsConstructorDescriptionEveryrenderRing(double, String, String)entry point and every arc and colour constant is static, so an instance carries nothing.Method Summary
Modifier and TypeMethodDescriptionprivate static voidappendBarPlot(StringBuilder buf, double[] history, String cls) Append sparkline bar chart to the SVG buffer.private static voidappendLinePlot(StringBuilder buf, double[] history, String cls) Appends one sparkline plot to the markup.private static voidAppends the SVG defs shared by the line plots.private static StringHTML-escape a string.(package private) static StringgetColorClass(double score, boolean collecting, String mode) Determine the CSS color class based on score, collecting state, and mode.static StringrenderRing(double score, String label, String value) Render a single SVG ring chart.static StringrenderRing(double score, String label, String value, String mode) Render a single SVG ring chart with a specified color mode.static StringrenderRing(double score, String label, String value, String mode, double[] history) Render a single SVG ring chart with sparkline history.static StringrenderRing(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.static StringrenderRing(double score, String label, String value, String mode, double[] history, String plotType, String forcedColor) Render a ring with an explicit color class override.static StringrenderRing(RingRenderer.RingSection[] sections, String value, String label) Render a multi-section ring SVG with proportional colored arcs.static StringrenderRingCell(double score, String label, String value, String[] details) Render a ring cell (ring + optional tooltip) for use inside a grid.static StringrenderRingCell(double score, String label, String value, String[] details, String mode) Render a ring cell with a specified color mode.static StringrenderRingCell(double score, String label, String value, String[] details, String mode, double[] history) Render a ring cell with sparkline history bars.static StringrenderRingCell(double score, String label, String value, String[] details, String mode, double[] history, String forcedColor) Render a ring cell with an explicit color class override.static StringrenderRingCell(RingRenderer.RingSection[] sections, String value, String label, String[] details) Render a multi-section ring cell.
Field Details
RING_SIZE
private static final int RING_SIZEDiameter of the ring gauge, in pixels.- See Also:
RING_STROKE
private static final int RING_STROKEWidth of the ring band, in pixels.- See Also:
RING_RADIUS
private static final int RING_RADIUSRadius of the ring band's centre line, in pixels.- See Also:
RING_CIRCUM
private static final double RING_CIRCUMCircumference of that centre line, for the dash pattern.- See Also:
MODE_HEALTH
Mode: health (green/yellow/red), activity (blue/cyan).- See Also:
MODE_ACTIVITY
Ring mode colouring the arc by how recently the peer was seen.- See Also:
MODE_LATENCY
Ring mode colouring the arc by the peer's transport latency.- See Also:
MODE_RATIO
Mode: dual-arc ratio (green + red arcs showing a proportion).- See Also:
MODE_NEUTRAL
Mode: neutral (green/yellow/cyan, never red — for uptime, metrics that aren't inherently bad).- See Also:
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_BANDIn 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_BANDIn 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
Plot type: mini bars at the bottom of the ring.- See Also:
PLOT_LINE
Plot type: line chart clipped to the inner circle area.- See Also:
_clipId
Counts the clip paths so each ring gets a unique id.
Constructor Details
RingRenderer
public RingRenderer()EveryrenderRing(double, String, String)entry point and every arc and colour constant is static, so an instance carries nothing.
Method Details
renderRing
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 percentagevalue- value string displayed in the center (e.g. "93%", "12", "1.2s")- Returns:
- inline SVG markup
renderRing
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 percentagevalue- value string displayed in the centermode- 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 percentagevalue- value string displayed in the centermode- color mode, one of the MODE_* constantshistory- 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 percentagevalue- value string displayed in the centermode- color mode, one of the MODE_* constantshistory- recent data points for sparkline, or null to omitplotType- 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. WhenforcedColoris 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 percentagevalue- value string displayed in the centermode- color mode, one of the MODE_* constantshistory- recent data points for sparkline, or null to omitplotType- 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
Appends the SVG defs shared by the line plots.- Parameters:
buf- where the markup is written
appendLinePlot
Appends one sparkline plot to the markup.- Parameters:
buf- where the markup is writtenhistory- the values to plotcls- the CSS colour class applied to the plot
appendBarPlot
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 tohistory- histogram values; NaN entries are skipped and fewer than two valid values render nothingcls- CSS class for the bar rects
renderRingCell
Render a ring cell (ring + optional tooltip) for use inside a grid.- Parameters:
score- 0.0–1.0 fill levellabel- short labelvalue- value string in the centerdetails- 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 levellabel- short labelvalue- value string in the centerdetails- tooltip lines, or null/empty for no tooltipmode- 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 levellabel- short labelvalue- value string in the centerdetails- tooltip lines, or null/empty for no tooltipmode- color mode, one of the MODE_* constantshistory- 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. WhenforcedColoris 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 levellabel- short labelvalue- value string in the centerdetails- tooltip lines, or null/empty for no tooltipmode- color mode, one of the MODE_* constantshistory- recent data points for sparkline, or null to omitforcedColor- explicit CSS class ("green"/"yellow"/"red"/"gray"), or null- Returns:
- HTML for the ring-cell div
renderRing
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-escapedlabel- label below the center textdetails- tooltip lines, or null/empty to omit- Returns:
- HTML for the ring-cell div
getColorClass
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 gatheredmode- 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