Package smile.plot.vega
Class Legend
java.lang.Object
smile.plot.vega.Legend
Similar to axes, legends visualize scales. However, whereas axes aid
interpretation of scales with positional ranges, legends aid
interpretation of scales with ranges such as colors, shapes and sizes.
By default, Vega-Lite automatically creates legends with default properties
for color, opacity, size, and shape channels when they encode data fields.
User can set the legend property of a mark property channel's field
definition to an object to customize legend properties or set legend to
null to remove the legend.
Besides legend property of a field definition, the configuration object
(config) also provides legend config for setting default legend properties
for all legends.
-
Method Summary
Modifier and TypeMethodDescriptionaria
(boolean flag) Sets if ARIA attributes should be included (SVG output only).clipHeight
(double height) Sets the height in pixels to clip symbol legend entries and limit their size.columnPadding
(double padding) Sets the horizontal padding in pixels between symbol legend entries.columns
(int columns) Sets the number of columns in which to arrange symbol legend entries.cornerRadius
(double radius) Sets the corner radius for the full legend.description
(String description) Sets the text description of this legend for ARIA accessibility (SVG output only).Sets the direction of the legend, one of "vertical" or "horizontal".Sets the background fill color for the full legend.Sets the text format.formatType
(String formatType) Sets the format type for labels.gradientLength
(double length) Sets the length in pixels of the primary axis of a color gradient.gradientOpacity
(double opacity) Sets the opacity of the color gradient.gradientStrokeColor
(String color) Sets the color of the gradient stroke.gradientStrokeWidth
(double width) Sets the width of the gradient stroke.gradientThickness
(double thickness) Sets the thickness in pixels of the color gradient.Sets the alignment to apply to symbol legends rows and columns.labelAlign
(String alignment) Sets the alignment of the legend label.labelBaseline
(String baseline) Sets the position of the baseline of legend label.labelColor
(String color) Sets the color of the legend label.Sets the Vega expression for customizing labels.Sets the font of the legend 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 legend labels.labelFontWeight
(String weight) Sets the font weight of legend labels.labelLimit
(int limit) Sets the maximum allowed pixel width of legend labels.labelOffset
(int offset) Sets the position offset in pixels to apply to labels.labelOverlap
(boolean flag) Sets the strategy to use for resolving overlap of legend labels.labelOverlap
(String strategy) Sets the strategy to use for resolving overlap of legend labels.offset
(double offset) Sets the offset, in pixels, by which to displace the legend from the edge of the enclosing group or data rectangle.Sets the orientation of the legend.padding
(double padding) Sets the padding between the border and content of the legend group.rowPadding
(double padding) Sets the vertical padding in pixels between symbol legend entries.strokeColor
(String color) Sets the border stroke color for the full legend.symbolLimit
(int limit) Sets the maximum number of allowed entries for a symbol legend.tickCount
(int count) Sets the desired number of tick values for quantitative legends.Sets the desired number of tick values for quantitative legends.Sets a descriptive title.Returns the specification in pretty print.toString()
Sets the type of the legend.Sets the explicitly set the visible legend values.x
(double x) Sets the custom x-position for legend with orient "none".y
(double y) Sets the custom y-position for legend with orient "none".zindex
(int zindex) Sets a non-negative integer indicating the z-index of the legend.
-
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 legend from the ARIA accessibility tree.- Returns:
- this object.
-
cornerRadius
Sets the corner radius for the full legend.- Parameters:
radius
- the corner radius for the full legend.- Returns:
- this object.
-
description
Sets the text description of this legend 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 legend for ARIA accessibility.- Returns:
- this object.
-
direction
Sets the direction of the legend, one of "vertical" or "horizontal".- Parameters:
direction
- "vertical" or "horizontal".- Returns:
- this object.
-
fillColor
Sets the background fill color for the full legend.- Parameters:
color
- the background fill color.- Returns:
- this object.
-
x
Sets the custom x-position for legend with orient "none".- Parameters:
x
- the custom x-position for legend with orient "none".- Returns:
- this object.
-
y
Sets the custom y-position for legend with orient "none".- Parameters:
y
- the custom y-position for legend with orient "none".- Returns:
- this object.
-
offset
Sets the offset, in pixels, by which to displace the legend from the edge of the enclosing group or data rectangle.- Parameters:
offset
- the offset in pixels.- Returns:
- this object.
-
orient
Sets the orientation of the legend.- Parameters:
orient
- "top", "bottom", "left" or "right".- Returns:
- this object.
-
padding
Sets the padding between the border and content of the legend group.- Parameters:
padding
- the padding between the border and content of the legend group.- Returns:
- this object.
-
strokeColor
Sets the border stroke color for the full legend.- Parameters:
color
- the border stroke color.- Returns:
- this object.
-
type
Sets the type of the legend. Use "symbol" to create a discrete legend and "gradient" for a continuous color gradient.- Parameters:
type
- "symbol" or "gradient".- Returns:
- this object.
-
tickCount
Sets the desired number of tick values for quantitative legends.- Parameters:
count
- the desired number of tick values.- Returns:
- this object.
-
tickCount
Sets the desired number of tick values for quantitative legends.- Parameters:
expr
- the expression of desired number of tick values.- Returns:
- this object.
-
values
Sets the explicitly set the visible legend values.- Parameters:
values
- the visible legend values.- Returns:
- this object.
-
zindex
Sets a non-negative integer indicating the z-index of the legend. 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 legend.- Returns:
- this object.
-
gradientLength
Sets the length in pixels of the primary axis of a color gradient. This value corresponds to the height of a vertical gradient or the width of a horizontal gradient.- Parameters:
length
- the length in pixels.- Returns:
- this object.
-
gradientOpacity
Sets the opacity of the color gradient.- Parameters:
opacity
- a value between [0, 1].- Returns:
- this object.
-
gradientStrokeColor
Sets the color of the gradient stroke.- Parameters:
color
- the color of the gradient stroke.- Returns:
- this object.
-
gradientStrokeWidth
Sets the width of the gradient stroke.- Parameters:
width
- the width in pixels.- Returns:
- this object.
-
gradientThickness
Sets the thickness in pixels of the color gradient. This value corresponds to the width of a vertical gradient or the height of a horizontal gradient.- Parameters:
thickness
- the thickness in pixels.- 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.
-
labelAlign
Sets the alignment of the legend label.- Parameters:
alignment
- "left", "center", or "right".- Returns:
- this object.
-
labelBaseline
Sets the position of the baseline of legend label.- Parameters:
baseline
- "top", "middle", "bottom", or "alphabetic".- Returns:
- this object.
-
labelColor
Sets the color of the legend label.- Parameters:
color
- the color of the legend 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 legend's backing datum object.- Parameters:
expr
- the Vega expression.- Returns:
- this object.
-
labelFont
Sets the font of the legend label.- Parameters:
font
- the font of the legend 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 legend labels.- Parameters:
weight
- the font weight of legend labels.- Returns:
- this object.
-
labelFontWeight
Sets the font weight of legend labels.- Parameters:
weight
- the font weight of legend labels.- Returns:
- this object.
-
labelLimit
Sets the maximum allowed pixel width of legend labels.- Parameters:
limit
- the maximum allowed pixel width of legend labels.- Returns:
- this object.
-
labelOffset
Sets the position offset in pixels to apply to labels.- Parameters:
offset
- the position offset in pixels to apply to labels.- Returns:
- this object.
-
labelOverlap
Sets the strategy to use for resolving overlap of legend 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 legend 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.
-
clipHeight
Sets the height in pixels to clip symbol legend entries and limit their size.- Parameters:
height
- the height in pixels.- Returns:
- this object.
-
columnPadding
Sets the horizontal padding in pixels between symbol legend entries.- Parameters:
padding
- the horizontal padding in pixels.- Returns:
- this object.
-
rowPadding
Sets the vertical padding in pixels between symbol legend entries.- Parameters:
padding
- the vertical padding in pixels.- Returns:
- this object.
-
columns
Sets the number of columns in which to arrange symbol legend entries. A value of 0 or lower indicates a single row with one column per entry.- Parameters:
columns
- the number of columns.- Returns:
- this object.
-
gridAlign
Sets the alignment to apply to symbol legends rows and columns.- Parameters:
alignment
- "all", "each", or "none".- Returns:
- this object.
-
symbolLimit
Sets the maximum number of allowed entries for a symbol legend. Additional entries will be dropped.- Parameters:
limit
- the maximum number of allowed entries.- Returns:
- this object.
-