Field Summary
FieldsModifier and TypeFieldDescription(package private) static final floatWidth the axis container lines are drawn with, chosen so the SVG post-processor tags themclass="axis".private final DataProcessorThe processor that reads source data and applies consolidation.(package private) final RrdGraphDefThe graph definition this generator renders.(package private) final ImageParametersThe dimensions and text layout of the rendered image.(package private) final RrdGraphInfoMetadata about the graph, such as its value range and time bounds.(package private) MapperThe rule set that maps data sources to graph lines and areas.private static final double[]Axis bounds chosen when the data gives no good one.private final StringCache key identifying this definition's settings.private static final char[]Unit symbols, ordered by magnitude.private static final intIndex of the base unit in the symbol table.(package private) final ImageWorkerThe worker that runs and caches the rendering.Constructor Summary
ConstructorsConstructorDescriptionRrdGraphGenerator(RrdGraphDef gdef, ImageWorker worker, DataProcessor dproc) Create a generator for one graph definition.Method Summary
Modifier and TypeMethodDescriptionprivate voidCalculate plot valuesprivate voidCollect info(package private) static intcountPlottedSeries(List<PlotElement> plotElements) Counts the independently plotted series in a graph, which decides whether the lines are drawn solid or dotted.(package private) voidCreate graphprivate voidCreate image workerprivate voiddrawAxis()Draw axisprivate voidDraw backgroundprivate voiddrawData()Draw dataprivate voiddrawGrid()Draw gridprivate voidDraw legendprivate voidDraw overlayprivate voidDraw rules and spansprivate voiddrawText()Draw textprivate voidExpand value rangeprivate voidFetch dataprivate voidFind min max valuesprivate voidgator()Draws the vertical graph signature along the left edge.private doublegetBox()Chooses a round grid spacing for the axis.(package private) doubleSpace around the legend box.(package private) doubleReturn the font char width(package private) doublegetFontHeight(RrdGraphConstants.FontTag fonttag) Return the font height(package private) doubleReturn the inter-legend space(package private) doubleThe vertical advance applied between legend rows.(package private) doubleLine spacing for small legend text.private voidIdentify si unitprivate voidInitialize limitsprivate booleanLazy checkprivate voidPlace legendsprivate voidRemove out of range rulesprivate voidRemove out of range spansprivate voidResolve text elementsprivate voidSave imageprivate PaintvalueShadePaint(Color[] stops) Build the vertical gradient that shades a series line by its value.private double[]xtr(long[] timestamps) Converts timestamps to pixel coordinates, duplicating each step.private double[]xtrDistinct(long[] timestamps) Converts timestamps to pixel x with one point per sample.private double[]ytr(double[] values) Converts values to pixel coordinates, duplicating each step.private double[]ytrDistinct(double[] values) Converts values to pixel y with one point per sample.
Field Details
AXIS_STROKE_WIDTH
static final float AXIS_STROKE_WIDTHWidth the axis container lines are drawn with, chosen so the SVG post-processor tags themclass="axis". Not the width the user sees: the theme's.axisrule sets that.- See Also:
SENSIBLE_VALUES
private static final double[] SENSIBLE_VALUESAxis bounds chosen when the data gives no good one.SYMBOLS_CENTER
private static final int SYMBOLS_CENTERIndex of the base unit in the symbol table.- See Also:
SYMBOLS
private static final char[] SYMBOLSUnit symbols, ordered by magnitude.gdef
The graph definition this generator renders.worker
The worker that runs and caches the rendering.dproc
The processor that reads source data and applies consolidation.mapper
Mapper mapperThe rule set that maps data sources to graph lines and areas.info
Metadata about the graph, such as its value range and time bounds.signature
Cache key identifying this definition's settings.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 plotworker- the worker that runs and caches the renderingdproc- the processor supplying consolidated data
Method Details
createGraph
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 infosaveImage
Save image- Throws:
IOException- if the image file cannot be written
drawOverlay
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
Counts the independently plotted series in a graph, which decides whether the lines are drawn solid or dotted.Counts
LineandAreatogether. 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.Stackstays 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 spansdrawText
private void drawText()Draw textdrawGrid
private void drawGrid()Draw gridvalueShadePaint
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 datadrawAxis
private void drawAxis()Draw axisdrawBackground
Draw background- Throws:
IOException- if a background or canvas image file cannot be read
createImageWorker
private void createImageWorker()Create image workerplaceLegends
private void placeLegends()Place legendsinitializeLimits
private void initializeLimits()Initialize limitsremoveOutOfRangeRules
private void removeOutOfRangeRules()Remove out of range rulesremoveOutOfRangeSpans
private void removeOutOfRangeSpans()Remove out of range spansexpandValueRange
private void expandValueRange()Expand value rangeidentifySiUnit
private void identifySiUnit()Identify si unitfindMinMaxValues
private void findMinMaxValues()Find min max valuescalculatePlotValues
private void calculatePlotValues()Calculate plot valuesresolveTextElements
private void resolveTextElements()Resolve text elementsfetchData
Fetch data- Throws:
IOException- if a source's RRD file cannot be read
lazyCheck
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 legendgetFontHeight
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
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[]); seextrDistinct(long[])for why the doubled form exists and why the smoothed renderer must not use it. Gaps stay NaN soPathIteratorstill splits the series where the data does.- Parameters:
values- sample values, possibly containing NaN- Returns:
- one pixel y per value