textSet method

Selection textSet([
  1. Union2<EachCallback<String?>, String>? value
])

Sets the text content to the specified value on all selected elements, replacing any existing child elements.

selection.textSet("Hello, world!".u22);

If the value is a constant, then all elements are given the same text content; 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 text content. A null value will clear the content.

Implementation

Selection textSet([Union2<EachCallback<String?>, String>? value]) {
  return each(
    value?.split(
          (callback) => textFunction(callback),
          (value) => textConstant(value),
        ) ??
        textRemove(),
  );
}