たれぱんのびぼーろく

わたしの備忘録、生物学とプログラミングが多いかも

d3-selection version4

D3js v4でSelectionsは変わりました!

もはやarrayではない

Selections no longer subclass Array using prototype chain injection; they are now plain objects, improving performance.
ref.

.data()は全部返します

When called in getter mode, selection.data now returns the data for all elements in the selection, rather than just the data for the first group of elements.
ref.

selectionは1 classのみに

There is now only one class of selection.
ref.

前からあったみたいだけど、便利そうなので復習

selection.each(function)

selectionの各nodeに対して
function(d, i, group) を実行.
d: datum, i: index, group: nodeの所属するgroup
thisはnodeに対応するDOM element.

ref.

selection.remove()

// remove.js
function remove() {
  var parent = this.parentNode;
  if (parent) parent.removeChild(this);
}

export default function() {
  return this.each(remove);
}


// index.js
...  
import selection_remove from "./remove";
...
Selection.prototype = selection.prototype = {
  ...  
  remove: selection_remove,
  ...
};

export default selection;