D3 - Operator

1 - About

Operators act on selections, modifying content.

Operator values are specified either as constants or functions; the latter (the functions) are evaluated for each element. (The functions are evaluated per element with access to data).

To tighten the scope of reference capture, D3 applies operators immediately; for example, D3’s attr operator immediately sets attributes on selected nodes and then returns.

3 - Property

3.1 - Chaining

The operator return value is the selection and therefore D3 supports method chaining.

For example, the append and insert operators add a new element for each element in the current selection, returning the added nodes, thus allowing the convenient creation of nested structures.

4 - Type

4.1 - Each

While the built-in operators satisfy most needs, the each operator invokes an arbitrary JavaScript callback for total generality.

4.2 - Remove (elements)

The remove operator discards selected elements.

4.3 - Functional

Once data is bound to elements, it is passed to functional operators as the first argument (by convention, d), along with the numeric index (i). These arguments were chosen for parity with JavaScript’s built-in array methods. This approach:

  • simplifies D3’s selection structure (requiring only one level of grouping) (???)
  • avoids variable arguments. (???)

Data Science
Data Analysis
Data Science
Linear Algebra Mathematics

Powered by ComboStrap