java.lang.Object
org.rrd4j.graph.Axis
org.rrd4j.graph.ValueAxis
- All Implemented Interfaces:
RrdGraphConstants
Represents value axis (y-axis) in RRD graphs. Handles value-based grid lines, labels, and scaling with automatic tick placement. Supports linear, logarithmic, and MRTG-style axis formatting.
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classConfiguration for Y-axis labels and grid spacing.Nested classes/interfaces inherited from interface RrdGraphConstants
RrdGraphConstants.FontConstructor, RrdGraphConstants.FontTagModifier and TypeInterfaceDescriptionstatic classFont constructor, to use embedded fonts.static enumAllowed font tag names which can be used inRrdGraphDef.setFont(org.rrd4j.graph.RrdGraphConstants.FontTag, java.awt.Font)methodField Summary
FieldsModifier and TypeFieldDescriptionprivate final RrdGraphDefThe graph being drawn.private final ImageParametersWhere the axis is drawn.private final MapperMaps data values to pixels.private final ImageWorkerThe worker drawing the graph.private static final ValueAxis.YLabel[]Names of the axes that can be labelled.Fields inherited from interface RrdGraphConstants
BLIND_COLOR, COLOR_ARROW, COLOR_BACK, COLOR_CANVAS, COLOR_FONT, COLOR_FRAME, COLOR_GRID, COLOR_MGRID, COLOR_SHADEA, COLOR_SHADEB, COLOR_XAXIS, COLOR_YAXIS, DAY, DEFAULT_ARROW_COLOR, DEFAULT_BACK_COLOR, DEFAULT_BASE, DEFAULT_CANVAS_COLOR, DEFAULT_END, DEFAULT_FONT_COLOR, DEFAULT_FRAME_COLOR, DEFAULT_GRID_COLOR, DEFAULT_HEIGHT, DEFAULT_IMAGE_FORMAT, DEFAULT_IMAGE_QUALITY, DEFAULT_LARGE_FONT, DEFAULT_MGRID_COLOR, DEFAULT_SHADEA_COLOR, DEFAULT_SHADEB_COLOR, DEFAULT_SMALL_FONT, DEFAULT_START, DEFAULT_UNITS_LENGTH, DEFAULT_WIDTH, DEFAULT_XAXIS_COLOR, DEFAULT_YAXIS_COLOR, FIRST_DAY_OF_WEEK, FONTTAG_AXIS, FONTTAG_DEFAULT, FONTTAG_LEGEND, FONTTAG_TITLE, FONTTAG_UNIT, FONTTAG_WATERMARK, FRIDAY, GATOR_FONT, GRID_STROKE, HH_MM, HOUR, IN_MEMORY_IMAGE, LEGEND_BOX, LEGEND_BOX_SPACE, LEGEND_INTERSPACING, LEGEND_LEADING, LEGEND_LEADING_SMALL, MINUTE, MONDAY, MONTH, PADDING_BOTTOM, PADDING_LEFT, PADDING_LEGEND, PADDING_PLOT, PADDING_RIGHT, PADDING_TITLE, PADDING_TOP, PADDING_VLABEL, PROPERTYFONTBOLD, PROPERTYFONTBOLDURL, PROPERTYFONTPLAIN, PROPERTYFONTPLAINURL, PROPERTYFONTSPROPERTIES, PROPERTYFONTSURL, SATURDAY, SECOND, SERIES_DOT, SUNDAY, THURSDAY, TICK_STROKE, TUESDAY, WEDNESDAY, WEEK, YEARModifier and TypeFieldDescriptionstatic final ColorAn transparent colorstatic final intIndex of the arrow color.static final intIndex of the background color.static final intIndex of the canvas color.static final intIndex of the font color.static final intIndex of the frame color.static final intIndex of the minor grid color.static final intIndex of the major grid color.static final intIndex of the top-left graph shade color.static final intIndex of the bottom-right graph shade color.static final intIndex of the x-axis color.static final intIndex of the yaxis color.static final intConstant to represent daystatic final ColorDefault arrow colorstatic final ColorDefault graph background colorstatic final doubleDefault value basestatic final ColorDefault graph canvas colorstatic final StringDefault graph ending timestatic final ColorDefault font colorstatic final ColorDefault frame colorstatic final ColorDefault minor grid colorstatic final intDefault graph heightstatic final StringDefault image formatstatic final floatDefault image quality, used only for jpeg graphsstatic final FontDefault graph large fontstatic final ColorDefault major grid colorstatic final ColorDefault top-left graph shade colorstatic final ColorDefault bottom-right graph shade colorstatic final FontDefault graph small fontstatic final StringDefault graph starting timestatic final intDefault units lengthstatic final intDefault graph widthstatic final ColorDefault x-axis colorstatic final ColorDefault x-axis colorstatic final intDefault first day of the week (obtained from the default locale)static final RrdGraphConstants.FontTagAxis font tagstatic final RrdGraphConstants.FontTagDefault font tagstatic final RrdGraphConstants.FontTagLegend font tagstatic final RrdGraphConstants.FontTagTitle font tagstatic final RrdGraphConstants.FontTagUnit font tagstatic final RrdGraphConstants.FontTagWatermark font tagstatic final intConstant to represent Fridaystatic final FontFont for the Gatorstatic final StrokeStroke used to draw gridstatic final StringHH:mm time formatstatic final intConstant to represent hourstatic final StringConstant to represent in-memory image namestatic final doubleUsed internallystatic final doubleUsed internallystatic final intUsed internallystatic final doubleUsed internallystatic final doubleUsed internallystatic final intConstant to represent minutestatic final intConstant to represent Mondaystatic final intConstant to represent monthstatic final intUsed internallystatic final intUsed internallystatic final doubleUsed internallystatic final intUsed internallystatic final intUsed internallystatic final intUsed internallystatic final intUsed internallystatic final intUsed internallystatic final StringThe name of the bold font, used to define theRrdGraphConstants.DEFAULT_LARGE_FONT.static final StringA URL to the bold font, used to define theRrdGraphConstants.DEFAULT_LARGE_FONT.static final StringThe name of the plain font, used to define theRrdGraphConstants.DEFAULT_SMALL_FONTand theRrdGraphConstants.GATOR_FONT.static final StringA URL to the plain font, used to define theRrdGraphConstants.DEFAULT_SMALL_FONTand theRrdGraphConstants.GATOR_FONT.static final StringThe file that contains font configuration searched in the class path.static final StringA possible URL to a configuration file.static final intConstant to represent Saturdaystatic final intConstant to represent secondstatic final floatInk length of one dot in a series line, in device pixels.static final intConstant to represent Sundaystatic final intConstant to represent Thursdaystatic final StrokeStroke used to draw ticksstatic final intConstant to represent Tuesdaystatic final intConstant to represent Wednesdaystatic final intConstant to represent weekstatic final intConstant to represent yearConstructor Summary
ConstructorsConstructorDescriptionValueAxis(RrdGraphGenerator generator) Create a value axis for the given generator's graph.ValueAxis(RrdGraph rrdGraph, ImageWorker worker) Used for testsMethod Summary
Modifier and TypeMethodDescription(package private) booleandraw()True if axis labels were drawn.private voiddrawGridLines(int sgrid, int egrid, double gridstep, int x0, int x1, Paint gridColor, Paint mGridColor, int labfact) Draws all grid lines for the value axis.private voiddrawLabels(int sgrid, int egrid, double gridstep, int x0, double scaledstep, boolean fractional, int labfact, Font font, Paint fontColor, int labelOffset) Draws all labels for the value axis at major grid positions.private intfindLabelFactor(ValueAxis.YLabel thisYLabel) Find the smallest labelFactor acceptable (can fit labels) for the given YLab definition Returns the label factor if one is ok, otherwise returns -1 if none are acceptableprivate ValueAxis.YLabelfindYLabel(int desiredMinimumLabelCount) Finds an acceptable YLabel object for the current graph If the graph covers positive and negative on the y-axis, then desiredMinimumLabelCount is checked as well, to ensure the chosen YLabel definition will result in the required number of labelsprivate intgetPixelsPerGridline(ValueAxis.YLabel thisYLabel) Finds the number of pixels per gridline that the given YLabel definition will result inprivate doubleThe axis range in scaled units.private static booleanisFractional(double scaledstep, int labfact) Returns true if some or all labels have fractional part (other than zero).
Field Details
ylabels
Names of the axes that can be labelled.im
Where the axis is drawn.worker
The worker drawing the graph.gdef
The graph being drawn.mapper
Maps data values to pixels.
Constructor Details
ValueAxis
ValueAxis(RrdGraph rrdGraph, ImageWorker worker) Used for tests- Parameters:
rrdGraph- the graph whose image and definition set up this axisworker- the image worker painting the graph
ValueAxis
ValueAxis(RrdGraphGenerator generator) Create a value axis for the given generator's graph.- Parameters:
generator- the generator whose definition and image parameters to use
Method Details
draw
drawGridLines
private void drawGridLines(int sgrid, int egrid, double gridstep, int x0, int x1, Paint gridColor, Paint mGridColor, int labfact) Draws all grid lines for the value axis. Minor grid lines use the grid color; major grid lines use the mgrid color. Separated from label drawing to produce consecutive SVG elements with identical stroke/paint, enabling tighter SVG grouping.- Parameters:
sgrid- index of the first grid line to consider, one below the minimum valueegrid- index of the last grid line to consider, one above the maximum valuegridstep- distance in graph values between adjacent grid linesx0- left pixel of the linex1- right pixel of the linegridColor- paint used for the minor grid linesmGridColor- paint used for the major grid lineslabfact- every labfact-th grid line counts as major, so 1 makes all of them major
drawLabels
private void drawLabels(int sgrid, int egrid, double gridstep, int x0, double scaledstep, boolean fractional, int labfact, Font font, Paint fontColor, int labelOffset) Draws all labels for the value axis at major grid positions.- Parameters:
sgrid- index of the first grid position to consider, one below the minimum valueegrid- index of the last grid position to consider, one above the maximum valuegridstep- distance in graph values between adjacent grid lines, used to find the pixel row of each positionx0- left pixel of the plot, the label is drawn to end this far in from itscaledstep- gridstep divided by the magnitude factor, the value printed per labelfractional- true to print one decimal place in the label, false to print whole numberslabfact- only positions divisible by this get a labelfont- font used to draw and measure the label textfontColor- paint used for the label textlabelOffset- pixels added to the grid line's row to place the label's baseline
findYLabel
Finds an acceptable YLabel object for the current graph If the graph covers positive and negative on the y-axis, then desiredMinimumLabelCount is checked as well, to ensure the chosen YLabel definition will result in the required number of labelsIf none of the built-in definitions is acceptable, one is generated from the range.
- Parameters:
desiredMinimumLabelCount- the label count the axis must exceed, only checked when the graph spans both positive and negative values- Returns:
- the first definition with more than five pixels per gridline and enough labels, or a generated power-of-ten definition when none of the built-in ones qualifies
findLabelFactor
Find the smallest labelFactor acceptable (can fit labels) for the given YLab definition Returns the label factor if one is ok, otherwise returns -1 if none are acceptable- Parameters:
thisYLabel- the definition whose four label factors are tried in order- Returns:
- the first label factor that leaves at least two lines of text between grid lines, or -1 when none of the four fits
getPixelsPerGridline
Finds the number of pixels per gridline that the given YLabel definition will result in- Parameters:
thisYLabel- the definition whose grid step is measured against the graph height- Returns:
- the whole pixels between two grid lines, rounded down, zero if the grid is finer than one pixel
getScaledRange
private double getScaledRange()The axis range in scaled units.- Returns:
- maxval minus minval, divided by the magnitude factor
isFractional
private static boolean isFractional(double scaledstep, int labfact) Returns true if some or all labels have fractional part (other than zero).- Parameters:
scaledstep- the label step in scaled units, never fractional when it is 1 or morelabfact- the number of grid steps between two printed labels- Returns:
- true when scaledstep times labfact is not a whole number, so the labels need a decimal place