<legend>
<legend> is a Graphical
component that renders a legend when nested inside a <graph>. Individual
legend entries are defined with the <label> component.
Attributes and Properties
Attributes for <legend>
Labels (1)
labelIsNameboolean. Default value: false. Whether to use this component's name as its rendered label.
Other (6)
applyStyleToLabelboolean. Default value: false. Whether to apply this component's selected style to its label.
boolean. Default value: false. Whether to draw an opaque box behind the legend so that graph contents passing behind it stay hidden.
boolean. Default value: false. Whether to render closed/filled swatches in the legend.
integer. Default value: 1. Z-order layer index used to stack graphical components (higher values render on top).
maskLabelboolean. Default value: false. Whether to give the label an opaque background so it stays legible when it overlaps an axis, grid line, or another object.
keyword. Position of the legend on the graph.
| Value | Description |
|---|---|
upperRight (default) | Place the legend in the upper-right corner. |
upperLeft | Place the legend in the upper-left corner. |
lowerRight | Place the legend in the lower-right corner. |
lowerLeft | Place the legend in the lower-left corner. |
Common to all components (9)
copyreference. Create an independent copy of another component by reference. Enter a references a $name.
disabledboolean. Default value: false. Whether this component is disabled and cannot be interacted with.
extendreference. Extend another component by reference, inheriting its children and attributes. Enter a reference as $name.
fixedboolean. Default value: false. Whether this component's value is fixed and cannot be modified.
fixLocationboolean. Default value: false. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).
hideboolean. Default value: false. Whether to hide this component from the rendered output.
isResponseboolean. Default value: false. Whether this component is treated as a response for the purposes of assessment.
nametext. The name used to reference this component from elsewhere in the document.
styleNumberinteger. Default value: 1. The style number used to select this component's visual styling from the available style definitions.
Properties for <legend name="l">
Labels (2)
$l.labellabel. The label rendered with this component.
$l.labelIsNameboolean. Whether to use this component's name as its rendered label.
Other (10)
$l.applyStyleToLabelboolean. Whether to apply this component's selected style to its label.
$l.boxedboolean. Whether to draw an opaque box behind the legend so that graph contents passing behind it stay hidden.
$l.disabledboolean. Whether this component is disabled and cannot be interacted with.
$l.displayClosedSwatchesboolean. Whether to render closed/filled swatches in the legend.
$l.fixedboolean. Whether this component's value is fixed and cannot be modified.
$l.fixLocationboolean. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).
$l.layerinteger. Z-order layer index used to stack graphical components (higher values render on top).
$l.maskLabelboolean. Whether to give the label an opaque background so it stays legible when it overlaps an axis, grid line, or another object.
$l.positiontext. Position of the legend on the graph.
Common to all components (4)
$l.doenetMLtext. The DoenetML source code that produced this component.
$l.hideboolean. Whether to hide this component from the rendered output.
$l.isResponseboolean. Whether this component is treated as a response for the purposes of assessment.
$l.styleNumberinteger. The style number used to select this component's visual styling from the available style definitions.
Examples
Example: Default <legend> within a <graph>
By default, <label> children are assigned to graphical objects with unique styleNumber
attributes in the order in which they are defined within the <graph>.
Example: <legend> with labels assigned by name
By default, <label> children are assigned to graphical objects with unique styleNumber
attributes in the order in which they are defined within the <graph>.
This default order can be altered in the following way: use the forObject attribute
within each <label> child, and as its input list the name of the component the
label is attached to (no need to include the $).
Attribute Examples
Attribute Example: position
The default position for the <legend> is in the upper-right corner of the graphing window.
To adjust this, use the position attribute. Valid text inputs for this attribute
are: upperright, upperleft, lowerright and lowerleft.
Attribute Example: boxed
By default a <legend> has no background of its own, so graph contents
passing behind it show through. The boxed attribute draws an opaque box behind
the legend instead. The box paints the graph’s background color unless the
legend’s <styleDefinition> names a backgroundColor:
A <legend>’s own styleNumber says how the legend itself is drawn — the
background of its box, and the color of its labels — while each swatch is drawn
from the style of the object it stands for. Labels are drawn in the style’s
textColor, which is black on light and white on dark unless a
<styleDefinition> or an active style palette says otherwise, so a box
painted a color of its own can be given label text that reads against it.
Swatches follow the document’s theme alongside the box and the labels: in dark mode a swatch takes the dark-mode color of the object it stands for, so it is drawn in the color that object is actually drawn in.
Attribute Example: layer
A <legend> is drawn on layer="1" unless told otherwise, which puts
it above everything on the default layer. Raise the layer to lift it above
graphical components that set a layer of their own — here the legend asks for
layer 3, above the rectangle’s layer 2, so the swatch stays visible.
The layer governs the legend’s swatches and its box. A legend’s labels are
drawn as text laid over the graph, so they stay in front of the graph’s contents
whatever layer the legend is given: lowering a legend’s layer will send its
swatches behind a curve but not its labels.
Attribute Example: displayClosedSwatches
When a graph contains filled shapes, the displayClosedSwatches attribute can be
used to alter the appearance of the symbols within the <legend> from that of the default line.