styleSet method
Sets the style property with the specified name to the specified value on the selected elements and returns this selection.
selection.styleSet("color", "red".u22);
If the value is a constant, then all elements are given the same style
property value; otherwise, if the value is a function, it is evaluated
for each selected element, in order, being passed the current datum (d),
the current index (i), and the current group (nodes), with thisArg
as the current DOM element (nodes[i]). The function’s return value
is then used to set each element’s style property. A null value will
remove the style property. An optional priority may also be specified,
either as null or the string important
(without the exclamation point).
Caution
Unlike many SVG attributes, CSS styles typically have associated units.
For example, 3px
is a valid stroke-width property value, while 3
is
not. Some browsers implicitly assign the px
(pixel) unit to numeric
values, but not all browsers do: IE, for example, throws an “invalid
arguments” error!
Implementation
Selection styleSet(String name, Union2<EachCallback<String?>, String>? value,
[String priority = ""]) {
return each(
value == null
? styleRemove(name)
: value.split(
(callback) => styleFunction(name, callback, priority),
(value) => styleConstant(name, value, priority),
),
);
}