Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

select only updating elements with d3.js

Tags:

d3.js

With a d3.js join Is there a way to select only the 'updating' elements separately from the 'entering' elements?

updateAndEnter = d3.selectAll('element').data(data);

entering = updateAndEnter.enter();

exiting = updateAndEnter.exit();

updatingOnly = ??;
like image 656
johowie Avatar asked Oct 29 '12 21:10

johowie


1 Answers

Yes, the selection just after the data join contains the 'update only' elements. After appending to the enter() selection, it will be expanded to include the entering elements as well.

See General Update Pattern:

  // DATA JOIN
  // Join new data with old elements, if any.
  var text = svg.selectAll("text")
      .data(data);

  // UPDATE
  // Update old elements as needed.
  text.attr("class", "update");

  // ENTER
  // Create new elements as needed.
  text.enter().append("text")
      .attr("class", "enter")
      .attr("x", function(d, i) { return i * 32; })
      .attr("dy", ".35em");

  // ENTER + UPDATE
  // Appending to the enter selection expands the update selection to include
  // entering elements; so, operations on the update selection after appending to
  // the enter selection will apply to both entering and updating nodes.
  text.text(function(d) { return d; });

  // EXIT
  // Remove old elements as needed.
  text.exit().remove();
like image 55
nautat Avatar answered Oct 08 '22 12:10

nautat