Interface Selection<GElement, Datum, PElement, PDatum>

A D3 Selection of elements.

The first generic "GElement" refers to the type of the selected element(s). The second generic "Datum" refers to the type of the datum of a selected element(s). The third generic "PElement" refers to the type of the parent element(s) in the D3 selection. The fourth generic "PDatum" refers to the type of the datum of the parent element(s).

interface Selection {
    [iterator](): Iterator<GElement, any, undefined>;
    append<K>(type): Selection<ElementTagNameMap[K], Datum, PElement, PDatum>;
    append<ChildElement>(type): Selection<ChildElement, Datum, PElement, PDatum>;
    append<ChildElement>(type): Selection<ChildElement, Datum, PElement, PDatum>;
    attr(name): string;
    attr(name, value): Selection<GElement, Datum, PElement, PDatum>;
    call<Args>(func, ...args): Selection<GElement, Datum, PElement, PDatum>;
    classed(names): boolean;
    classed(names, value): Selection<GElement, Datum, PElement, PDatum>;
    classed(names, value): Selection<GElement, Datum, PElement, PDatum>;
    clone(deep?): Selection<GElement, Datum, PElement, PDatum>;
    data(): Datum[];
    data<NewDatum>(data, key?): Selection<GElement, NewDatum, PElement, PDatum>;
    datum(): Datum;
    datum(value): Selection<GElement, undefined, PElement, PDatum>;
    datum<NewDatum>(value): Selection<GElement, NewDatum, PElement, PDatum>;
    datum<NewDatum>(value): Selection<GElement, NewDatum, PElement, PDatum>;
    dispatch(type, parameters?): Selection<GElement, Datum, PElement, PDatum>;
    dispatch(type, parameters?): Selection<GElement, Datum, PElement, PDatum>;
    each(func): Selection<GElement, Datum, PElement, PDatum>;
    empty(): boolean;
    enter(): Selection<EnterElement, Datum, PElement, PDatum>;
    exit<OldDatum>(): Selection<GElement, OldDatum, PElement, PDatum>;
    filter(selector): Selection<GElement, Datum, PElement, PDatum>;
    filter<FilteredElement>(selector): Selection<FilteredElement, Datum, PElement, PDatum>;
    filter(selector): Selection<GElement, Datum, PElement, PDatum>;
    filter<FilteredElement>(selector): Selection<FilteredElement, Datum, PElement, PDatum>;
    html(): string;
    html(value): Selection<GElement, Datum, PElement, PDatum>;
    insert<K>(type, before?): Selection<ElementTagNameMap[K], Datum, PElement, PDatum>;
    insert<ChildElement>(type, before?): Selection<ChildElement, Datum, PElement, PDatum>;
    interrupt(name?): Selection<GElement, Datum, PElement, PDatum>;
    join<K, OldDatum>(enter, update?, exit?): Selection<GElement | ElementTagNameMap[K], Datum, PElement, PDatum>;
    join<ChildElement, OldDatum>(enter, update?, exit?): Selection<GElement | ChildElement, Datum, PElement, PDatum>;
    lower(): Selection<GElement, Datum, PElement, PDatum>;
    merge(other): Selection<GElement, Datum, PElement, PDatum>;
    node(): GElement;
    nodes(): GElement[];
    on(typenames): ((this, event, d) => void);
    on(typenames, listener): Selection<GElement, Datum, PElement, PDatum>;
    on(typenames, listener, options?): Selection<GElement, Datum, PElement, PDatum>;
    order(): Selection<GElement, Datum, PElement, PDatum>;
    property(name): any;
    property<T>(name): T;
    property(name, value): Selection<GElement, Datum, PElement, PDatum>;
    property(name, value): Selection<GElement, Datum, PElement, PDatum>;
    property<T>(name, value): Selection<GElement, Datum, PElement, PDatum>;
    property<T>(name, value): Selection<GElement, Datum, PElement, PDatum>;
    raise(): Selection<GElement, Datum, PElement, PDatum>;
    remove(): Selection<GElement, Datum, PElement, PDatum>;
    select<DescElement>(selector): Selection<DescElement, Datum, PElement, PDatum>;
    select<DescElement>(selector): Selection<null, undefined, PElement, PDatum>;
    select<DescElement>(selector): Selection<DescElement, Datum, PElement, PDatum>;
    selectAll(selector?): Selection<null, undefined, GElement, Datum>;
    selectAll<DescElement, OldDatum>(selector): Selection<DescElement, OldDatum, GElement, Datum>;
    selectAll<DescElement, OldDatum>(selector): Selection<DescElement, OldDatum, GElement, Datum>;
    selectChild<DescElement>(selector?): Selection<DescElement, Datum, PElement, PDatum>;
    selectChild<ResultElement, ChildElement>(selector): Selection<ResultElement, Datum, PElement, PDatum>;
    selectChildren<DescElement, OldDatum>(selector?): Selection<DescElement, OldDatum, GElement, Datum>;
    selectChildren<ResultElement, ResultDatum, ChildElement>(selector): Selection<ResultElement, ResultDatum, GElement, Datum>;
    selection(): Selection<GElement, Datum, PElement, PDatum>;
    size(): number;
    sort(comparator?): Selection<GElement, Datum, PElement, PDatum>;
    style(name): string;
    style(name, value): Selection<GElement, Datum, PElement, PDatum>;
    style(name, value, priority?): Selection<GElement, Datum, PElement, PDatum>;
    style(name, value, priority?): Selection<GElement, Datum, PElement, PDatum>;
    text(): string;
    text(value): Selection<GElement, Datum, PElement, PDatum>;
    transition(name?): Transition<GElement, Datum, PElement, PDatum>;
    transition(transition): Transition<GElement, Datum, PElement, PDatum>;
}

Type Parameters

Methods

  • Returns an iterator over the selected (non-null) elements.

    Returns Iterator<GElement, any, undefined>

  • Appends a new element of this type (tag name) as the last child of each selected element, or before the next following sibling in the update selection if this is an enter selection. The latter behavior for enter selections allows you to insert elements into the DOM in an order consistent with the new bound data; however, note that selection.order may still be required if updating elements change order (i.e., if the order of new data is inconsistent with old data).

    This method returns a new selection containing the appended elements. Each new element inherits the data of the current elements, if any.

    Type Parameters

    • K extends "symbol" | "filter" | "g" | "animate" | "animateMotion" | "animateTransform" | "circle" | "clipPath" | "defs" | "desc" | "ellipse" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "foreignObject" | "image" | "line" | "linearGradient" | "marker" | "mask" | "metadata" | "mpath" | "path" | "pattern" | "polygon" | "polyline" | "radialGradient" | "rect" | "set" | "stop" | "svg" | "switch" | "text" | "textPath" | "tspan" | "use" | "view" | keyof HTMLElementTagNameMap

    Parameters

    • type: K

      A string representing the tag name.

    Returns Selection<ElementTagNameMap[K], Datum, PElement, PDatum>

  • Appends a new element of this type (tag name) as the last child of each selected element, or before the next following sibling in the update selection if this is an enter selection. The latter behavior for enter selections allows you to insert elements into the DOM in an order consistent with the new bound data; however, note that selection.order may still be required if updating elements change order (i.e., if the order of new data is inconsistent with old data).

    This method returns a new selection containing the appended elements. Each new element inherits the data of the current elements, if any.

    The generic refers to the type of the child element to be appended.

    Type Parameters

    Parameters

    • type: string

      A string representing the tag name. The specified name may have a namespace prefix, such as svg:text to specify a text attribute in the SVG namespace. If no namespace is specified, the namespace will be inherited from the parent element; or, if the name is one of the known prefixes, the corresponding namespace will be used (for example, svg implies svg:svg)

    Returns Selection<ChildElement, Datum, PElement, PDatum>

  • Appends a new element of the type provided by the element creator function as the last child of each selected element, or before the next following sibling in the update selection if this is an enter selection. The latter behavior for enter selections allows you to insert elements into the DOM in an order consistent with the new bound data; however, note that selection.order may still be required if updating elements change order (i.e., if the order of new data is inconsistent with old data).

    This method returns a new selection containing the appended elements. Each new element inherits the data of the current elements, if any.

    The generic refers to the type of the child element to be appended.

    Type Parameters

    Parameters

    • type: ValueFn<GElement, Datum, ChildElement>

      A creator function which is evaluated for each selected element, in order, being passed the current datum (d), the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]). This function should return an element to be appended. (The function typically creates a new element, but it may instead return an existing element.)

    Returns Selection<ChildElement, Datum, PElement, PDatum>

  • Return the current value of the specified attribute for the first (non-null) element in the selection. This is generally useful only if you know that the selection contains exactly one element.

    Parameters

    • name: string

      Name of the attribute

    Returns string

  • Sets the attribute with the specified name to the specified value on the selected elements and returns this selection. If the value is a constant, all elements are given the same attribute 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 this as the current DOM element (nodes[i]). The function’s return value is then used to set each element’s attribute. A null value will remove the specified attribute.

    Parameters

    • name: string
    • value: string | number | boolean | readonly (string | number)[] | ValueFn<GElement, Datum, string | number | boolean | readonly (string | number)[]>

    Returns Selection<GElement, Datum, PElement, PDatum>

  • Invoke the specified function exactly once, passing in this selection along with any optional arguments. Returns this selection.

    Type Parameters

    • Args extends any[]

    Parameters

    • func: ((selection, ...args) => void)

      A function which is passed this selection as the first argument along with any optional arguments.

        • (selection, ...args): void
        • Parameters

          • selection: Selection<GElement, Datum, PElement, PDatum>
          • Rest ...args: Args

          Returns void

    • Rest ...args: Args

      List of optional arguments to be passed to the callback function.

    Returns Selection<GElement, Datum, PElement, PDatum>

  • Returns true if and only if the first (non-null) selected element has the specified classes. This is generally useful only if you know the selection contains exactly one element.

    Parameters

    • names: string

      A string of space-separated class names.

    Returns boolean

  • 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. If the constant value is truthy, then all elements are assigned the specified classes; otherwise, the classes are unassigned.

    Parameters

    • names: string

      A string of space-separated class names.

    • value: boolean

      A boolean flag (true = assign / false = unassign)

    Returns Selection<GElement, Datum, PElement, PDatum>

  • 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. The assign/unassign status for the individual selected elements is determined by the boolean return value of the value function.

    Parameters

    • names: string

      A string of space-separated class names.

    • value: ValueFn<GElement, Datum, boolean>

      A value function which is evaluated for each selected element, in order, being passed the current datum (d), the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]). The function’s return value is then used to assign or unassign classes on each element.

    Returns Selection<GElement, Datum, PElement, PDatum>

  • Inserts clones of the selected elements immediately following the selected elements and returns a selection of the newly added clones. If deep is true, the descendant nodes of the selected elements will be cloned as well. Otherwise, only the elements themselves will be cloned.

    Parameters

    • Optional deep: boolean

      Perform deep cloning if this flag is set to true.

    Returns Selection<GElement, Datum, PElement, PDatum>

  • Returns the array of data for the selected elements.

    Returns Datum[]

  • Joins the specified array of data with the selected elements, returning a new selection that represents the update selection: the elements successfully bound to data. Also defines the enter and exit selections on the returned selection, which can be used to add or remove elements to correspond to the new data.

    The data is specified for each group in the selection. If the selection has multiple groups (such as d3.selectAll followed by selection.selectAll), then data should typically be specified as a function.

    If a key function is not specified, then the first datum in data is assigned to the first selected element, the second datum to the second selected element, and so on. A key function may be specified to control which datum is assigned to which element, replacing the default join-by-index, by computing a string identifier for each datum and element.

    The update and enter selections are returned in data order, while the exit selection preserves the selection order prior to the join. If a key function is specified, the order of elements in the selection may not match their order in the document; use selection.order or selection.sort as needed.

    This method cannot be used to clear bound data; use selection.datum instead.

    For details see: https://github.com/d3/d3-selection#joining-data

    The generic refers to the type of the new datum to be used for the selected elements.

    Type Parameters

    • NewDatum

    Parameters

    • data: NewDatum[] | Iterable<NewDatum> | ValueFn<PElement, PDatum, NewDatum[] | Iterable<NewDatum>>

      The specified data is an array or iterable of arbitrary values (e.g., numbers or objects) or a value function which will be evaluated for each group in order, being passed the group’s parent datum (d, which may be undefined), the group index (i), and the selection’s parent nodes (nodes), with this as the group’s parent element. The function returns an array or iterable of values for each group.

    • Optional key: ValueFn<GElement | PElement, Datum | NewDatum, KeyType>

      An optional key function which is evaluated for each selected element, in order, being passed the current datum (d), the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]); the returned string is the element’s key. The key function is then also evaluated for each new datum in data, being passed the current datum (d), the current index (i), and the group’s new data, with this as the group’s parent DOM element (nodes[i]); the returned string is the datum’s key. The datum for a given key is assigned to the element with the matching key. If multiple elements have the same key, the duplicate elements are put into the exit selection; if multiple data have the same key, the duplicate data are put into the enter selection.

    Returns Selection<GElement, NewDatum, PElement, PDatum>

  • Returns the bound datum for the first (non-null) element in the selection. This is generally useful only if you know the selection contains exactly one element.

    Returns Datum

  • Delete the bound data for each element in the selection.

    Parameters

    • value: null

    Returns Selection<GElement, undefined, PElement, PDatum>

  • Sets the element’s bound data using the specified value function on all selected elements. Unlike selection.data, this method does not compute a join and does not affect indexes or the enter and exit selections.

    The generic refers to the type of the new datum to be used for the selected elements.

    Type Parameters

    • NewDatum

    Parameters

    • value: ValueFn<GElement, Datum, NewDatum>

      A value function which is evaluated for each selected element, in order, being passed the current datum (d), the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]). The function is then used to set each element’s new data. A null value will delete the bound data.

    Returns Selection<GElement, NewDatum, PElement, PDatum>

  • Sets the element’s bound data to the specified value on all selected elements. Unlike selection.data, this method does not compute a join and does not affect indexes or the enter and exit selections.

    The generic refers to the type of the new datum to be used for the selected elements.

    Type Parameters

    • NewDatum

    Parameters

    • value: NewDatum

      A value object to be used as the datum for each element.

    Returns Selection<GElement, NewDatum, PElement, PDatum>

  • Dispatches a custom event of the specified type to each selected element, in order. An optional parameters map may be specified to set additional properties of the event.

    Parameters

    • type: string

      Name of event to dispatch

    • Optional parameters: CustomEventParameters

      An optional value map with custom event parameters

    Returns Selection<GElement, Datum, PElement, PDatum>

  • Dispatches a custom event of the specified type to each selected element, in order. An optional value function returning a parameters map for each element in the selection may be specified to set additional properties of the event.

    Parameters

    • type: string

      Name of event to dispatch

    • Optional parameters: ValueFn<GElement, Datum, CustomEventParameters>

      A value function which is evaluated for each selected element, in order, being passed the current datum (d), the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]). It must return the parameters map for the current element.

    Returns Selection<GElement, Datum, PElement, PDatum>

  • Invoke the specified function for each selected element, passing in the current datum (d), the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]). This method can be used to invoke arbitrary code for each selected element, and is useful for creating a context to access parent and child data simultaneously.

    Parameters

    • func: ValueFn<GElement, Datum, void>

      A function which is invoked for each selected element, being passed the current datum (d), the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]).

    Returns Selection<GElement, Datum, PElement, PDatum>

  • Return true if this selection contains no (non-null) elements.

    Returns boolean

  • Return the enter selection: placeholder nodes for each datum that had no corresponding DOM element in the selection. (The enter selection is empty for selections not returned by selection.data.)

    Returns Selection<EnterElement, Datum, PElement, PDatum>

  • Returns the exit selection: existing DOM elements in the selection for which no new datum was found. (The exit selection is empty for selections not returned by selection.data.)

    IMPORTANT: The generic refers to the type of the old datum associated with the exit selection elements. Ensure you set the generic to the correct type, if you need to access the data on the exit selection in follow-up steps, e.g. to set styles as part of an exit transition before removing them.

    Type Parameters

    • OldDatum

    Returns Selection<GElement, OldDatum, PElement, PDatum>

  • Filters the selection, returning a new selection that contains only the elements for which the specified filter is true.

    The returned filtered selection preserves the parents of this selection, but like array.filter, it does not preserve indexes as some elements may be removed; use selection.select to preserve the index, if needed.

    Parameters

    • selector: string

      A CSS selector string to match when filtering.

    Returns Selection<GElement, Datum, PElement, PDatum>

  • Filters the selection, returning a new selection that contains only the elements for which the specified filter is true.

    The returned filtered selection preserves the parents of this selection, but like array.filter, it does not preserve indexes as some elements may be removed; use selection.select to preserve the index, if needed.

    The generic refers to the type of element which will be selected after applying the filter, i.e. if the element types contained in a pre-filter selection are narrowed to a subset as part of the filtering.

    Type Parameters

    Parameters

    • selector: string

      A CSS selector string to match when filtering.

    Returns Selection<FilteredElement, Datum, PElement, PDatum>

  • Filter the selection, returning a new selection that contains only the elements for which the specified filter is true.

    The returned filtered selection preserves the parents of this selection, but like array.filter, it does not preserve indexes as some elements may be removed; use selection.select to preserve the index, if needed.

    Parameters

    • selector: ValueFn<GElement, Datum, boolean>

      A value function which is evaluated for each selected element, in order, being passed the current datum (d), the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]). This function should return true for an element to be included, and false otherwise.

    Returns Selection<GElement, Datum, PElement, PDatum>

  • Filter the selection, returning a new selection that contains only the elements for which the specified filter is true.

    The returned filtered selection preserves the parents of this selection, but like array.filter, it does not preserve indexes as some elements may be removed; use selection.select to preserve the index, if needed.

    Type Parameters

    Parameters

    • selector: ValueFn<GElement, Datum, boolean>

      A value function which is evaluated for each selected element, in order, being passed the current datum (d), the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]). This function should return true for an element to be included, and false otherwise.

    Returns Selection<FilteredElement, Datum, PElement, PDatum>

  • Returns a string representation of the inner HTML for the first (non-null) element in the selection. This is generally useful only if you know the selection contains exactly one element.

    Returns string

  • Sets the inner HTML to the specified value on all selected elements, replacing any existing child elements. If the value is a constant, then all elements are given the same inner HTML; 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 this as the current DOM element (nodes[i]). The function’s return value is then used to set each element’s inner HTML. A null value will clear the content.

    Parameters

    • value: string | ValueFn<GElement, Datum, string>

    Returns Selection<GElement, Datum, PElement, PDatum>

  • Inserts a new element of the specified type (tag name) before the first element matching the specified before selector for each selected element. For example, a before selector :first-child will prepend nodes before the first child. If before is not specified, it defaults to null. (To append elements in an order consistent with bound data, use selection.append.)

    This method returns a new selection containing the appended elements. Each new element inherits the data of the current elements, if any.

    The generic refers to the type of the child element to be appended.

    Type Parameters

    • K extends "symbol" | "filter" | "g" | "animate" | "animateMotion" | "animateTransform" | "circle" | "clipPath" | "defs" | "desc" | "ellipse" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "foreignObject" | "image" | "line" | "linearGradient" | "marker" | "mask" | "metadata" | "mpath" | "path" | "pattern" | "polygon" | "polyline" | "radialGradient" | "rect" | "set" | "stop" | "svg" | "switch" | "text" | "textPath" | "tspan" | "use" | "view" | keyof HTMLElementTagNameMap

    Parameters

    • type: K

      A string representing the tag name for the element type to be inserted.

    • Optional before: string | ValueFn<GElement, Datum, BaseType>

      One of:

      • A CSS selector string for the element before which the insertion should occur.
      • A child selector function which is evaluated for each selected element, in order, being passed the current datum (d), the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]). This function should return the child element before which the element should be inserted.

    Returns Selection<ElementTagNameMap[K], Datum, PElement, PDatum>

  • Inserts a new element of the specified type (tag name) before the first element matching the specified before selector for each selected element. For example, a before selector :first-child will prepend nodes before the first child. If before is not specified, it defaults to null. (To append elements in an order consistent with bound data, use selection.append.)

    This method returns a new selection containing the appended elements. Each new element inherits the data of the current elements, if any.

    The generic refers to the type of the child element to be appended.

    Type Parameters

    Parameters

    • type: string | ValueFn<GElement, Datum, ChildElement>

      One of:

      • A string representing the tag name for the element type to be inserted. The specified name may have a namespace prefix, such as svg:text to specify a text attribute in the SVG namespace. If no namespace is specified, the namespace will be inherited from the parent element; or, if the name is one of the known prefixes, the corresponding namespace will be used (for example, svg implies svg:svg)
      • A creator function which is evaluated for each selected element, in order, being passed the current datum (d), the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]). This function should return an element to be inserted. (The function typically creates a new element, but it may instead return an existing element.)
    • Optional before: string | ValueFn<GElement, Datum, BaseType>

      One of:

      • A CSS selector string for the element before which the insertion should occur.
      • A child selector function which is evaluated for each selected element, in order, being passed the current datum (d), the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]). This function should return the child element before which the element should be inserted.

    Returns Selection<ChildElement, Datum, PElement, PDatum>

  • Interrupts the active transition of the specified name on the selected elements, and cancels any pending transitions with the specified name, if any. If a name is not specified, null is used.

    IMPORTANT: Interrupting a transition on an element has no effect on any transitions on any descendant elements. For example, an axis transition consists of multiple independent, synchronized transitions on the descendants of the axis G element (the tick lines, the tick labels, the domain path, etc.). To interrupt the axis transition, you must therefore interrupt the descendants.

    Parameters

    • Optional name: string

      Name of the transition.

    Returns Selection<GElement, Datum, PElement, PDatum>

  • Appends, removes and reorders elements as necessary to match the data that was previously bound by selection.data, returning the merged enter and update selection. This method is a convenient alternative to the more explicit selection.enter, selection.exit, selection.append and selection.remove.

    The "matching" logic is determined by the key function passed to selection.data.

    Type Parameters

    • K extends "symbol" | "filter" | "g" | "animate" | "animateMotion" | "animateTransform" | "circle" | "clipPath" | "defs" | "desc" | "ellipse" | "feBlend" | "feColorMatrix" | "feComponentTransfer" | "feComposite" | "feConvolveMatrix" | "feDiffuseLighting" | "feDisplacementMap" | "feDistantLight" | "feDropShadow" | "feFlood" | "feFuncA" | "feFuncB" | "feFuncG" | "feFuncR" | "feGaussianBlur" | "feImage" | "feMerge" | "feMergeNode" | "feMorphology" | "feOffset" | "fePointLight" | "feSpecularLighting" | "feSpotLight" | "feTile" | "feTurbulence" | "foreignObject" | "image" | "line" | "linearGradient" | "marker" | "mask" | "metadata" | "mpath" | "path" | "pattern" | "polygon" | "polyline" | "radialGradient" | "rect" | "set" | "stop" | "svg" | "switch" | "text" | "textPath" | "tspan" | "use" | "view" | keyof HTMLElementTagNameMap

    • OldDatum = Datum

    Parameters

    • enter: K
    • Optional update: ((elem) => Selection<GElement, Datum, PElement, PDatum> | TransitionLike<GElement, Datum>)
    • Optional exit: ((elem) => void)
        • (elem): void
        • Parameters

          • elem: Selection<GElement, OldDatum, PElement, PDatum>

          Returns void

    Returns Selection<GElement | ElementTagNameMap[K], Datum, PElement, PDatum>

  • Appends, removes and reorders elements as necessary to match the data that was previously bound by selection.data, returning the merged enter and update selection. This method is a convenient alternative to the more explicit selection.enter, selection.exit, selection.append and selection.remove.

    The "matching" logic is determined by the key function passed to selection.data.

    Type Parameters

    • ChildElement extends BaseType

    • OldDatum = Datum

    Parameters

    • enter: string | ((elem) => TransitionLike<GElement, Datum> | Selection<ChildElement, Datum, PElement, PDatum>)
    • Optional update: ((elem) => Selection<GElement, Datum, PElement, PDatum> | TransitionLike<GElement, Datum>)
    • Optional exit: ((elem) => void)
        • (elem): void
        • Parameters

          • elem: Selection<GElement, OldDatum, PElement, PDatum>

          Returns void

    Returns Selection<GElement | ChildElement, Datum, PElement, PDatum>

  • Re-insert each selected element, in order, as the first child of its parent.

    Returns Selection<GElement, Datum, PElement, PDatum>

  • Returns a new selection merging this selection with the specified other selection or transition. The returned selection has the same number of groups and the same parents as this selection. Any missing (null) elements in this selection are filled with the corresponding element, if present (not null), from the specified selection. (If the other selection has additional groups or parents, they are ignored.)

    This method is commonly used to merge the enter and update selections after a data-join. After modifying the entering and updating elements separately, you can merge the two selections and perform operations on both without duplicate code.

    This method is not intended for concatenating arbitrary selections, however: if both this selection and the specified other selection have (non-null) elements at the same index, this selection’s element is returned in the merge and the other selection’s element is ignored.

    Parameters

    Returns Selection<GElement, Datum, PElement, PDatum>

  • Return the first (non-null) element in this selection. If the selection is empty, returns null.

    Returns GElement

  • Return an array of all (non-null) elements in this selection.

    Returns GElement[]

  • Return the currently-assigned listener for the specified event typename on the first (non-null) selected element, if any, If multiple typenames are specified, the first matching listener is returned.

    Parameters

    • typenames: string

      The typenames is a string event type, such as click, mouseover, or submit; any DOM event type supported by your browser may be used. The type may be optionally followed by a period (.) and a name; the optional name allows multiple callbacks to be registered to receive events of the same type, such as click.foo and click.bar. To specify multiple typenames, separate typenames with spaces, such as "input change"" or "click.foo click.bar".

    Returns ((this, event, d) => void)

      • (this, event, d): void
      • Parameters

        • this: GElement
        • event: any
        • d: Datum

        Returns void

  • Remove a listener for the specified event type names. To remove all listeners for a given name, pass null as the listener and ".foo" as the typename, where foo is the name; to remove all listeners with no name, specify "." as the typename.

    Parameters

    • typenames: string

      The typenames is a string event type, such as click, mouseover, or submit; any DOM event type supported by your browser may be used. The type may be optionally followed by a period (.) and a name; the optional name allows multiple callbacks to be registered to receive events of the same type, such as click.foo and click.bar. To specify multiple typenames, separate typenames with spaces, such as "input change"" or "click.foo click.bar".

    • listener: null

      null to indicate removal of listener

    Returns Selection<GElement, Datum, PElement, PDatum>

  • Add an event listener for the specified event type names. If an event listener was previously registered for the same typename on a selected element, the old listener is removed before the new listener is added.

    When a specified event is dispatched on a selected node, the specified listener will be evaluated for each selected element.

    Parameters

    • typenames: string

      The typenames is a string event type, such as click, mouseover, or submit; any DOM event type supported by your browser may be used. The type may be optionally followed by a period (.) and a name; the optional name allows multiple callbacks to be registered to receive events of the same type, such as click.foo and click.bar. To specify multiple typenames, separate typenames with spaces, such as "input change"" or "click.foo click.bar".

    • listener: ((this, event, d) => void)

      A listener function which will be evaluated for each selected element, being passed the current event (event) and the current datum (d), with this as the current DOM element (event.currentTarget). Listeners always see the latest datum for their element. Note: while you can use event.pageX and event.pageY directly, it is often convenient to transform the event position to the local coordinate system of that element that received the event using d3.pointer.

        • (this, event, d): void
        • Parameters

          • this: GElement
          • event: any
          • d: Datum

          Returns void

    • Optional options: any

      An optional options object may specify characteristics about the event listener, such as wehether it is captures or passive; see element.addEventListener.

    Returns Selection<GElement, Datum, PElement, PDatum>

  • Re-insert elements into the document such that the document order of each group matches the selection order. This is equivalent to calling selection.sort if the data is already sorted, but much faster.

    Returns Selection<GElement, Datum, PElement, PDatum>

  • Return the current value of the specified property for the first (non-null) element in the selection. This is generally useful only if you know that the selection contains exactly one element.

    Parameters

    • name: string

      Name of the property

    Returns any

  • Look up a local variable on the first node of this selection. Note that this is not equivalent to local.get(selection.node()) in that it will not look up locals set on the parent node(s).

    Type Parameters

    • T

    Parameters

    • name: Local<T>

      The d3.local variable to look up.

    Returns T

  • Sets the property with the specified name to the specified value on selected elements. If the value is a constant, then all elements are given the same 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 this as the current DOM element (nodes[i]). The function’s return value is then used to set each element’s property. A null value will delete the specified property.

    Parameters

    • name: string
    • value: ValueFn<GElement, Datum, any>

    Returns Selection<GElement, Datum, PElement, PDatum>

  • Sets the value of the property with the specified name for the selected elements and returns this selection. All elements are given the same property value.

    Parameters

    • name: string

      Name of the property

    • value: any

      Constant value for the property

    Returns Selection<GElement, Datum, PElement, PDatum>

  • Store a value in a d3.local variable. This is equivalent to selection.each(function (d, i, g) { name.set(this, value.call(this, d, i, g)); }) but more concise.

    Type Parameters

    • T

    Parameters

    • name: Local<T>

      A d3.local variable

    • value: ValueFn<GElement, Datum, T>

      A callback that returns the value to store

    Returns Selection<GElement, Datum, PElement, PDatum>

  • Store a value in a d3.local variable for each node in the selection. This is equivalent to selection.each(function () { name.set(this, value); }) but more concise.

    Type Parameters

    • T

    Parameters

    • name: Local<T>

      A d3.local variable

    • value: T

      A callback that returns the value to store

    Returns Selection<GElement, Datum, PElement, PDatum>

  • Re-insert each selected element, in order, as the last child of its parent.

    Returns Selection<GElement, Datum, PElement, PDatum>

  • Removes the selected elements from the document. Returns this selection (the removed elements) which are now detached from the DOM.

    Returns Selection<GElement, Datum, PElement, PDatum>

  • For each selected element, select the first descendant element that matches the specified selector string. If no element matches the specified selector for the current element, the element at the current index will be null in the returned selection. If multiple elements match the selector, only the first matching element in document order is selected. Selection.select does not affect grouping: it preserves the existing group structure and indexes, and propagates data (if any) to selected children.

    If the current element has associated data, this data is propagated to the corresponding selected element.

    The generic represents the type of the descendant element to be selected.

    Type Parameters

    Parameters

    • selector: string

      CSS selector string

    Returns Selection<DescElement, Datum, PElement, PDatum>

  • Create an empty sub-selection. Selection.select does not affect grouping: it preserves the existing group structure and indexes.

    Type Parameters

    Parameters

    • selector: null

    Returns Selection<null, undefined, PElement, PDatum>

  • For each selected element, select the descendant element returned by the selector function. If no element is returned by the selector function for the current element, the element at the current index will be null in the returned selection. Selection.select does not affect grouping: it preserves the existing group structure and indexes, and propagates data (if any) to selected children.

    If the current element has associated data, this data is propagated to the corresponding selected element.

    The generic represents the type of the descendant element to be selected.

    Type Parameters

    Parameters

    • selector: ValueFn<GElement, Datum, DescElement>

      A selector function, which is evaluated for each selected element, in order, being passed the current datum (d), the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]). It must return an element, or null if there is no matching element.

    Returns Selection<DescElement, Datum, PElement, PDatum>

  • Create an empty sub-selection. Selection.selectAll does affect grouping: The elements in the returned selection are grouped by their corresponding parent node in this selection, the group at the current index will be empty.

    Parameters

    • Optional selector: null

    Returns Selection<null, undefined, GElement, Datum>

  • For each selected element, selects the descendant elements that match the specified selector string. The elements in the returned selection are grouped by their corresponding parent node in this selection. If no element matches the specified selector for the current element, the group at the current index will be empty. Selection.selectAll does affect grouping: each selected descendant is grouped by the parent element in the originating selection.

    The selected elements do not inherit data from this selection; use selection.data to propagate data to children.

    The first generic "DescElement" refers to the type of descendant element to be selected. The second generic "OldDatum" refers to the type of the datum, of a selected element. This is useful when re-selecting elements with a previously set, know datum type.

    Type Parameters

    Parameters

    • selector: string

      CSS selector string

    Returns Selection<DescElement, OldDatum, GElement, Datum>

  • For each selected element, selects the descendant elements returned by the selector function. The elements in the returned selection are grouped by their corresponding parent node in this selection. If no element matches the specified selector for the current element, the group at the current index will be empty. Selection.selectAll does affect grouping: each selected descendant is grouped by the parent element in the originating selection.

    The selected elements do not inherit data from this selection; use selection.data to propagate data to children.

    The first generic "DescElement" refers to the type of descendant element to be selected. The second generic "OldDatum" refers to the type of the datum, of a selected element. This is useful when re-selecting elements with a previously set, know datum type.

    Type Parameters

    Parameters

    • selector: ValueFn<GElement, Datum, DescElement[] | ArrayLike<DescElement> | Iterable<DescElement>>

      A selector function which is evaluated for each selected element, in order, being passed the current datum (d), the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]). It must return an array of elements (or an iterable, or a pseudo-array, such as a NodeList), or the empty array if there are no matching elements.

    Returns Selection<DescElement, OldDatum, GElement, Datum>

  • Returns a new selection with the (first) child of each element of the current selection matching the selector. Selects the first child that matches (if any).

    The generic represents the type of the descendant element to be selected.

    Type Parameters

    Parameters

    • Optional selector: string

      CSS selector string

    Returns Selection<DescElement, Datum, PElement, PDatum>

  • Returns a new selection with the (first) child of each element of the current selection matching the selector.

    The first generic represents the type of the descendant element to be selected. The second generic represents the type of any of the child elements.

    Type Parameters

    Parameters

    • selector: ((child, i, children) => boolean)

      A selector function, which is evaluated for each of the children nodes, in order, being passed the child (child), the child’s index (i), and the list of children (children); the method selects the first child for which the selector return truthy, if any.

        • (child, i, children): boolean
        • Parameters

          • child: ChildElement
          • i: number
          • children: ChildElement[]

          Returns boolean

    Returns Selection<ResultElement, Datum, PElement, PDatum>

  • Returns a new selection with the children of each element of the current selection matching the selector. Selects the children that match (if any)

    The first generic represents the type of the descendant element to be selected. The second generic refers to the type of the datum of the element to be selected.

    Type Parameters

    Parameters

    • Optional selector: string

      CSS selector string

    Returns Selection<DescElement, OldDatum, GElement, Datum>

  • Returns a new selection with the children of each element of the current selection matching the selector.

    The first generic represents the type of the descendant element to be selected. The second generic refers to the type of the datum of the element to be selected. The third generic represents the type of any of the child elements.

    Type Parameters

    Parameters

    • selector: ((child, i, children) => boolean)

      A selector function, which is evaluated for each of the children nodes, in order, being passed the child (child), the child’s index (i), and the list of children (children); the method selects the first child for which the selector return truthy, if any.

        • (child, i, children): boolean
        • Parameters

          • child: ChildElement
          • i: number
          • children: ChildElement[]

          Returns boolean

    Returns Selection<ResultElement, ResultDatum, GElement, Datum>

  • Returns the selection (for symmetry with transition.selection).

    Returns Selection<GElement, Datum, PElement, PDatum>

  • Returns the total number of elements in this selection.

    Returns number

  • Return a new selection that contains a copy of each group in this selection sorted according to the compare function. After sorting, re-inserts elements to match the resulting order (per selection.order).

    Note that sorting is not guaranteed to be stable; however, it is guaranteed to have the same behavior as your browser’s built-in sort method on arrays.

    Parameters

    • Optional comparator: ((a, b) => number)

      An optional comparator function, which defaults to "ascending". The function is passed two elements’ data a and b to compare. It should return either a negative, positive, or zero value. If negative, then a should be before b; if positive, then a should be after b; otherwise, a and b are considered equal and the order is arbitrary.

        • (a, b): number
        • Parameters

          • a: Datum
          • b: Datum

          Returns number

    Returns Selection<GElement, Datum, PElement, PDatum>

  • Returns the current value of the specified style property for the first (non-null) element in the selection. The current value is defined as the element’s inline value, if present, and otherwise its computed value. Accessing the current style value is generally useful only if you know the selection contains exactly one element.

    Parameters

    • name: string

      Name of the style

    Returns string

  • Clear the style with the specified name for the selected elements and returns this selection.

    Parameters

    • name: string

      Name of the style

    • value: null

      null,to clear the style

    Returns Selection<GElement, Datum, PElement, PDatum>

  • Sets the value of the style with the specified name for the selected elements and returns this selection. All elements are given the same style value.

    Parameters

    • name: string

      Name of the style

    • value: string | number | boolean

      Constant value for the style

    • Optional priority: "important"

      An optional priority flag, either null or the string important (without the exclamation point)

    Returns Selection<GElement, Datum, PElement, PDatum>

  • Sets the value of the style with the specified name for the selected elements and returns this selection. The value for the individual selected elements is determined by the value function.

    Parameters

    • name: string

      Name of the style

    • value: ValueFn<GElement, Datum, string | number | boolean>

      A value function which is evaluated for each selected element, in order, being passed the current datum (d), the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]). A null value will clear the style.

    • Optional priority: "important"

      An optional priority flag, either null or the string important (without the exclamation point)

    Returns Selection<GElement, Datum, PElement, PDatum>

  • Returns the text content for the first (non-null) element in the selection. This is generally useful only if you know the selection contains exactly one element.

    Returns string

  • Sets the text content to the specified value on all selected elements, replacing any existing child elements. 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 this 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.

    Parameters

    • value: string | number | boolean | ValueFn<GElement, Datum, string | number | boolean>

    Returns Selection<GElement, Datum, PElement, PDatum>

  • Returns a new transition on the given selection with the specified name. If a name is not specified, null is used. The new transition is only exclusive with other transitions of the same name.

    Parameters

    • Optional name: string

      Name of the transition.

    Returns Transition<GElement, Datum, PElement, PDatum>

  • Returns a new transition on the given selection.

    When using a transition instance, the returned transition has the same id and name as the specified transition. If a transition with the same id already exists on a selected element, the existing transition is returned for that element. Otherwise, the timing of the returned transition is inherited from the existing transition of the same id on the nearest ancestor of each selected element. Thus, this method can be used to synchronize a transition across multiple selections, or to re-select a transition for specific elements and modify its configuration.

    If the specified transition is not found on a selected node or its ancestors (such as if the transition already ended), the default timing parameters are used; however, in a future release, this will likely be changed to throw an error.

    Parameters

    Returns Transition<GElement, Datum, PElement, PDatum>