D3 - Selection

> Data Visualization (vis|viz|graphic|image) > D3 (Data-Driven Documents)

1 - About

D3 adopts the W3C Selectors API to identify document elements for selection.

Any number of operators can be applied to selected elements. These operators wrap the W3C DOM API, setting:

  • attributes (attr),
  • styles (style),
  • properties (property),
  • HTML (html)
  • and text (text) content.

D3’s selection operators such as attr, style and property allow to specify the value either as:

  • a constant (the same for all selected elements)
  • or a function (computed separately for each element).

Since each selection is simply an array, elements can also be accessed directly (e.g., [0]).

If you’re using a DOM framework like React, you probably don’t need selections (if you don’t need transitions)

Advertising

3 - Nested / Hierarchy Selection

4 - Operations

  • .each allows a function to be called on each element of a selection
  • .call allows a function to be called on the selection itself.

5 - Documentation / Reference

viz/d3/selection.txt · Last modified: 2019/02/16 17:40 by gerardnico