classedSet method
Assigns or unassigns the specified CSS class names on the selected
elements by setting the class
attribute or modifying the classList
property and returns this selection.
selection.classedSet("foo", true.u22);
The specified names is a string of space-separated class names. For
example, to assign the classes foo
and bar
to the selected elements:
selection.classedSet("foo bar", true.u22);
If the value is truthy, then all elements are assigned the specified classes; otherwise, the classes are unassigned.
selection.classedSet(
"foo",
(Element thisArg, JSAny? d, int t, List<Element?> nodes) {
return Random().nextDouble() > 0.5;
}.u21,
);
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 assign or unassign classes on each element.
Implementation
Selection classedSet(String names, Union2<EachCallback<bool>, bool> value) {
var names0 = classArray(names);
return each(
value?.split(
(callback) => classedFunction(names0, callback),
(value) => (value ? classedTrue : classedFalse)(names0),
) ??
classedFalse(names0),
);
}