java.lang.Object
org.rrd4j.graph.Axis
org.rrd4j.graph.TimeAxis
- All Implemented Interfaces:
RrdGraphConstants
Represents the time axis (x-axis) in RRD graphs. Handles time-based grid lines, labels, and tick marks with configurable formatting. Automatically selects appropriate time intervals based on graph time range and pixel density.
Nested Class Summary
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 CalendarCalendar used to break times into fields.private final RrdGraphDefThe graph definition being drawn.private final ImageParametersThe image being drawn.private final MapperMaps between time and pixel positions.private final doubleSeconds each horizontal pixel covers.private TimeAxisSettingTick settingprivate static final TimeAxisSetting[]Tick spacing and labels for each time span.private final ImageWorkerWhere the axis is drawn.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
ConstructorsConstructorDescriptionTimeAxis(RrdGraphGenerator generator) Sets up this axis from an in-progress generator, reusing the image parameters, worker, graph definition and mapper the generator has already built.TimeAxis(RrdGraph rrdGraph, ImageWorker worker) Used for testsMethod Summary
Private MethodsModifier and TypeMethodDescriptionprivate voidadjustStartingTime(TimeUnit timeUnit, int timeUnitCount) Adjust starting timeprivate voidChoose tick settingsWalks the major unit positions and returns the x coordinates they land on.(package private) booleandraw()Paints ticks, grids and labels along the time axis, returning false if no tick settings could be chosen.private voidDraw labelsprivate voidDraw major gridsprivate voidDraw major ticksprivate voiddrawMinorGrids(Set<Integer> majorX) Draw minor grids, skipping any position a major gridline already claimed.private voidDraw minor ticksprivate voidfindNextTime(TimeUnit timeUnit, int timeUnitCount) Find next timeprivate intChooses how far labels are shifted for readability.
Field Details
tickSettings
Tick spacing and labels for each time span.im
The image being drawn.worker
Where the axis is drawn.gdef
The graph definition being drawn.mapper
Maps between time and pixel positions.tickSetting
Tick settingsecPerPix
private final double secPerPixSeconds each horizontal pixel covers.calendar
Calendar used to break times into fields.
Constructor Details
TimeAxis
TimeAxis(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
TimeAxis
TimeAxis(RrdGraphGenerator generator) Sets up this axis from an in-progress generator, reusing the image parameters, worker, graph definition and mapper the generator has already built.- Parameters:
generator- the graph generator that is painting the graph this axis belongs to
Method Details
draw
collectMajorGridX
Walks the major unit positions and returns the x coordinates they land on.Collected before anything is drawn so the minor pass can leave them alone. Keyed on the mapped x rather than on the timestamp because the major unit can be a month or a year, which has no fixed length in seconds to test a position against.
- Returns:
- the x coordinates claimed by a major gridline, never null
drawMinorTicks
private void drawMinorTicks()Draw minor ticksdrawMajorTicks
private void drawMajorTicks()Draw major ticksdrawMinorGrids
Draw minor grids, skipping any position a major gridline already claimed.- Parameters:
majorX- x coordinates owned by the major grid, drawn bydrawMajorGrids()
drawMajorGrids
private void drawMajorGrids()Draw major gridsdrawLabels
private void drawLabels()Draw labelsfindNextTime
Find next time- Parameters:
timeUnit- the calendar unit to advancetimeUnitCount- the number of units to advance
getTimeShift
private int getTimeShift()Chooses how far labels are shifted for readability.- Returns:
- the shift, in pixels
adjustStartingTime
Adjust starting time- Parameters:
timeUnit- the calendar unit to align totimeUnitCount- the tick spacing in those units
chooseTickSettings
private void chooseTickSettings()Choose tick settings