Package smile.plot.vega
Class Axis
java.lang.Object
smile.plot.vega.Axis
Axes provide axis lines, ticks, and labels to convey how a positional range
represents a data range. Simply put, axes visualize scales.
By default, Vega-Lite automatically creates axes with default properties
for x and y channels when they encode data fields. User can set the axis
property of x- or y-field definition to an object to customize axis
properties or set axis to null to remove the axis.
Besides axis property of a field definition, the configuration object
(config) also provides axis config for setting default axis properties
for all axes.
-
Method Summary
Modifier and TypeMethodDescriptionaria
(boolean flag) Sets if ARIA attributes should be included (SVG output only).bandPosition
(double position) For band scales, sets the interpolation fraction where axis ticks should be positioned.description
(String description) Sets the text description of this axis for ARIA accessibility (SVG output only).domain
(boolean flag) Sets if the domain (the axis baseline) should be included as part of the axis.Sets the stroke cap for the domain line's ending style.domainColor
(String color) Sets the color of axis domain line.domainDash
(double stroke, double space) Sets the alternating [stroke, space] lengths for dashed domain lines.domainDashOffset
(double offset) Sets the pixel offset at which to start drawing with the domain dash array.domainOpacity
(double opacity) Sets the opacity of the axis domain line.domainWidth
(double width) Sets the stroke width of axis domain line.Sets the text format.formatType
(String formatType) Sets the format type for labels.grid
(boolean flag) Sets if gridlines should be included as part of the axis.Sets the stroke cap for gridlines' ending style.Sets the color of gridlines.gridDash
(double stroke, double space) Sets the alternating [stroke, space] lengths for dashed gridlines.gridOpacity
(double opacity) Sets the stroke opacity of grid.gridWidth
(double width) Sets the grid width.labelAlign
(String strategy) Sets the horizontal text alignment of axis tick labels.labelAngle
(double angle) Sets the rotation angle of the axis labels.labelBaseline
(String baseline) Sets the vertical text baseline of axis tick labels.labelBound
(boolean flag) Sets if labels should be hidden if they exceed the axis range.labelBound
(double tolerance) Sets the pixel tolerance of label bounding box.labelColor
(String color) Sets the color of the tick label.Sets the Vega expression for customizing labels.labelFlush
(boolean flag) Sets if the first and last axis labels should be aligned flush with the scale range.labelFlush
(double adjustment) Sets the number of pixels by which to offset the first and last labels.labelFlushOffset
(double offset) Sets the number of pixels by which to offset flush-adjusted labels.Sets the font of the tick label.labelFontSize
(double size) Sets the font size of the label in pixels.labelFontStyle
(String style) Sets the font style of the title.labelFontWeight
(int weight) Sets the font weight of axis tick labels.labelFontWeight
(String weight) Sets the font weight of axis tick labels.labelLimit
(int limit) Sets the maximum allowed pixel width of axis tick labels.labelLineHeight
(int height) Sets the line height in pixels for multi-line label text.labelLineHeight
(String height) Sets the line height for multi-line label text.labelOffset
(int offset) Sets the position offset in pixels to apply to labels, in addition to tickOffset.labelOpacity
(double opacity) Sets the opacity of the labels.labelOverlap
(boolean flag) Sets the strategy to use for resolving overlap of axis labels.labelOverlap
(String strategy) Sets the strategy to use for resolving overlap of axis labels.labelPadding
(double padding) Sets the padding in pixels between labels and ticks.labels
(boolean flag) Sets if labels should be included as part of the axis.labelSeparation
(double separation) Sets the minimum separation that must be between label bounding boxes for them to be considered non-overlapping (default 0).maxExtent
(int extent) Sets the maximum extent in pixels that axis ticks and labels should use.minExtent
(int extent) Sets the minimum extent in pixels that axis ticks and labels should use.offset
(double offset) Sets the offset, in pixels, by which to displace the axis from the edge of the enclosing group or data rectangle.Sets the orientation of the axis.position
(double position) Sets the anchor position of the axis in pixels.Sets the custom styles to apply to the axis.For band scales, sets if ticks and grid lines should be placed at the "center" of a band or at the band "extent"s to indicate intervals.Sets the stroke cap for tick lines' ending style.Sets the color of the axis's tick.tickCount
(int count) Sets a desired number of ticks, for axes visualizing quantitative scales.ticks
(boolean flag) Sets whether the axis should include ticks.Sets a descriptive title.Returns the specification in pretty print.toString()
translate
(double translate) Sets the coordinate space translation offset for axis layout.zindex
(int zindex) Sets a non-negative integer indicating the z-index of the axis.
-
Method Details
-
toString
-
toPrettyString
Returns the specification in pretty print.- Returns:
- the specification in pretty print.
-
title
Sets a descriptive title.- Parameters:
title
- a descriptive title.- Returns:
- this object.
-
aria
Sets if ARIA attributes should be included (SVG output only).- Parameters:
flag
- A flag indicating if ARIA attributes should be included (SVG output only). If false, the "aria-hidden" attribute will be set on the output SVG group, removing the axis from the ARIA accessibility tree.- Returns:
- this object.
-
bandPosition
For band scales, sets the interpolation fraction where axis ticks should be positioned.- Parameters:
position
- An interpolation fraction indicating where, for band scales, axis ticks should be positioned. A value of 0 places ticks at the left edge of their bands. A value of 0.5 places ticks in the middle of their bands.- Returns:
- this object.
-
description
Sets the text description of this axis for ARIA accessibility (SVG output only). If the aria property is true, for SVG output the "aria-label" attribute will be set to this description. If the description is unspecified it will be automatically generated.- Parameters:
description
- the text description of this axis for ARIA accessibility.- Returns:
- this object.
-
maxExtent
Sets the maximum extent in pixels that axis ticks and labels should use. This determines a maximum offset value for axis titles.- Parameters:
extent
- the maximum extent in pixels that axis ticks and labels should use.- Returns:
- this object.
-
minExtent
Sets the minimum extent in pixels that axis ticks and labels should use. This determines a minimum offset value for axis titles.- Parameters:
extent
- the minimum extent in pixels that axis ticks and labels should use.- Returns:
- this object.
-
orient
Sets the orientation of the axis.- Parameters:
orient
- "top", "bottom", "left" or "right".- Returns:
- this object.
-
offset
Sets the offset, in pixels, by which to displace the axis from the edge of the enclosing group or data rectangle.- Parameters:
offset
- the offset in pixels.- Returns:
- this object.
-
position
Sets the anchor position of the axis in pixels.- Parameters:
position
- the anchor position of the axis in pixels.- Returns:
- this object.
-
translate
Sets the coordinate space translation offset for axis layout. By default, axes are translated by a 0.5 pixel offset for both the x and y coordinates in order to align stroked lines with the pixel grid. However, for vector graphics output these pixel-specific adjustments may be undesirable, in which case translate can be changed (for example, to zero).- Parameters:
translate
- the coordinate space translation offset for axis layout.- Returns:
- this object.
-
zindex
Sets a non-negative integer indicating the z-index of the axis. If zindex is 0, axes should be drawn behind all chart elements. To put them in front, set zindex to 1 or more.- Parameters:
zindex
- a non-negative integer indicating the z-index of the axis.- Returns:
- this object.
-
style
Sets the custom styles to apply to the axis.- Parameters:
style
- A string or array of strings indicating the name of custom styles to apply to the axis. A style is a named collection of axis property defaults defined within the style configuration. If style is an array, later styles will override earlier styles.- Returns:
- this object.
-
domain
Sets if the domain (the axis baseline) should be included as part of the axis.- Parameters:
flag
- A flag indicating if the domain (the axis baseline) should be included as part of the axis.- Returns:
- this object.
-
domainCap
Sets the stroke cap for the domain line's ending style.- Parameters:
cap
- "butt", "round" or "square".- Returns:
- this object.
-
domainColor
Sets the color of axis domain line.- Parameters:
color
- the color of axis domain line.- Returns:
- this object.
-
domainOpacity
Sets the opacity of the axis domain line.- Parameters:
opacity
- a value between [0, 1].- Returns:
- this object.
-
domainWidth
Sets the stroke width of axis domain line.- Parameters:
width
- the stroke width of axis domain line.- Returns:
- this object.
-
domainDash
Sets the alternating [stroke, space] lengths for dashed domain lines.- Parameters:
stroke
- the stroke length.space
- the space length.- Returns:
- this object.
-
domainDashOffset
Sets the pixel offset at which to start drawing with the domain dash array.- Parameters:
offset
- the pixel offset at which to start drawing with the domain dash array.- Returns:
- this object.
-
format
Sets the text format. When used with the default "number" and "time" format type, the text formatting pattern for labels of guides (axes, legends, headers) and text marks. If the format type is "number" (e.g., for quantitative fields), this is D3's number format pattern. If the format type is "time" (e.g., for temporal fields), this is D3's time format pattern.- Parameters:
format
- the text formatting pattern.- Returns:
- this object.
-
formatType
Sets the format type for labels.- Parameters:
formatType
- "number", "time", or a registered custom format type.- Returns:
- this object.
-
labels
Sets if labels should be included as part of the axis.- Parameters:
flag
- A flag indicating if labels should be included as part of the axis.- Returns:
- this object.
-
labelAlign
Sets the horizontal text alignment of axis tick labels.- Parameters:
strategy
- the horizontal text alignment of axis tick labels.- Returns:
- this object.
-
labelAngle
Sets the rotation angle of the axis labels.- Parameters:
angle
- the rotation angle of the axis labels.- Returns:
- this object.
-
labelBaseline
Sets the vertical text baseline of axis tick labels.- Parameters:
baseline
- "alphabetic", "top", "middle", "bottom", "line-top", or "line-bottom".- Returns:
- this object.
-
labelBound
Sets if labels should be hidden if they exceed the axis range.- Parameters:
flag
- If false (the default) no bounds overlap analysis is performed. If true, labels will be hidden if they exceed the axis range by more than 1 pixel.- Returns:
- this object.
-
labelBound
Sets the pixel tolerance of label bounding box.- Parameters:
tolerance
- the pixel tolerance: the maximum amount by which a label bounding box may exceed the axis range.- Returns:
- this object.
-
labelColor
Sets the color of the tick label.- Parameters:
color
- the color of the tick label.- Returns:
- this object.
-
labelExpr
Sets the Vega expression for customizing labels. The label text and value can be assessed via the label and value properties of the axis's backing datum object.- Parameters:
expr
- the Vega expression.- Returns:
- this object.
-
labelFlush
Sets if the first and last axis labels should be aligned flush with the scale range. Flush alignment for a horizontal axis will left-align the first label and right-align the last label. For vertical axes, bottom and top text baselines are applied instead.- Parameters:
flag
- A flag if the first and last axis labels should be aligned flush with the scale range.- Returns:
- this object.
-
labelFlush
Sets the number of pixels by which to offset the first and last labels. The additional adjustment can sometimes help the labels better visually group with corresponding axis ticks.- Parameters:
adjustment
- the number of pixels by which to offset the first and last labels.- Returns:
- this object.
-
labelFlushOffset
Sets the number of pixels by which to offset flush-adjusted labels. Offsets can help the labels better visually group with corresponding axis ticks.- Parameters:
offset
- the number of pixels by which to offset flush-adjusted labels.- Returns:
- this object.
-
labelFont
Sets the font of the tick label.- Parameters:
font
- the font of the tick label.- Returns:
- this object.
-
labelFontSize
Sets the font size of the label in pixels.- Parameters:
size
- the font size in pixels.- Returns:
- this object.
-
labelFontStyle
Sets the font style of the title.- Parameters:
style
- the font style of the title.- Returns:
- this object.
-
labelFontWeight
Sets the font weight of axis tick labels.- Parameters:
weight
- the font weight of axis tick labels.- Returns:
- this object.
-
labelFontWeight
Sets the font weight of axis tick labels.- Parameters:
weight
- the font weight of axis tick labels.- Returns:
- this object.
-
labelLimit
Sets the maximum allowed pixel width of axis tick labels.- Parameters:
limit
- the maximum allowed pixel width of axis tick labels.- Returns:
- this object.
-
labelLineHeight
Sets the line height in pixels for multi-line label text.- Parameters:
height
- the line height in pixels for multi-line label text.- Returns:
- this object.
-
labelLineHeight
Sets the line height for multi-line label text.- Parameters:
height
- "line-top" or "line-bottom".- Returns:
- this object.
-
labelOffset
Sets the position offset in pixels to apply to labels, in addition to tickOffset.- Parameters:
offset
- the position offset in pixels to apply to labels.- Returns:
- this object.
-
labelOpacity
Sets the opacity of the labels.- Parameters:
opacity
- a value between [0, 1].- Returns:
- this object.
-
labelOverlap
Sets the strategy to use for resolving overlap of axis labels. If false (the default), no overlap reduction is attempted. If set to true, a strategy of removing every other label is used (this works well for standard linear axes).- Parameters:
flag
- a value between [0, 1].- Returns:
- this object.
-
labelOverlap
Sets the strategy to use for resolving overlap of axis labels. If set to "parity", a strategy of removing every other label is used (this works well for standard linear axes). If set to "greedy", a linear scan of the labels is performed, removing any labels that overlaps with the last visible label (this often works better for log-scaled axes).- Parameters:
strategy
- "parity" or "greedy".- Returns:
- this object.
-
labelPadding
Sets the padding in pixels between labels and ticks.- Parameters:
padding
- the padding in pixels between labels and ticks.- Returns:
- this object.
-
labelSeparation
Sets the minimum separation that must be between label bounding boxes for them to be considered non-overlapping (default 0). This property is ignored if labelOverlap resolution is not enabled.- Parameters:
separation
- the separation between label bounding boxes.- Returns:
- this object.
-
grid
Sets if gridlines should be included as part of the axis.- Parameters:
flag
- A flag indicating if gridlines should be included as part of the axis.- Returns:
- this object.
-
gridCap
Sets the stroke cap for gridlines' ending style.- Parameters:
cap
- "butt", "round" or "square".- Returns:
- this object.
-
gridColor
Sets the color of gridlines.- Parameters:
color
- the color of gridlines.- Returns:
- this object.
-
gridOpacity
Sets the stroke opacity of grid.- Parameters:
opacity
- a value between [0, 1].- Returns:
- this object.
-
gridWidth
Sets the grid width.- Parameters:
width
- the grid width in pixels.- Returns:
- this object.
-
gridDash
Sets the alternating [stroke, space] lengths for dashed gridlines.- Parameters:
stroke
- the stroke length.space
- the space length.- Returns:
- this object.
-
ticks
Sets whether the axis should include ticks.- Parameters:
flag
- A flag indicating if the axis should include ticks.- Returns:
- this object.
-
tickBand
For band scales, sets if ticks and grid lines should be placed at the "center" of a band or at the band "extent"s to indicate intervals.- Parameters:
band
- "center" or "extent".- Returns:
- this object.
-
tickCap
Sets the stroke cap for tick lines' ending style.- Parameters:
cap
- "butt", "round" or "square".- Returns:
- this object.
-
tickColor
Sets the color of the axis's tick.- Parameters:
color
- the color of the axis's tick.- Returns:
- this object.
-
tickCount
Sets a desired number of ticks, for axes visualizing quantitative scales.- Parameters:
count
- A desired number of ticks, for axes visualizing quantitative scales.- Returns:
- this object.
-