Table of Contents

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.

Property

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.

Type

Each

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

Remove (elements)

The remove operator discards selected elements.

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. (???)