Skip to content

Instantly share code, notes, and snippets.

@ramboldio
Created April 21, 2017 15:52
Show Gist options
  • Save ramboldio/851f20923f2b9f5694baab3520aac00b to your computer and use it in GitHub Desktop.
Save ramboldio/851f20923f2b9f5694baab3520aac00b to your computer and use it in GitHub Desktop.
Reasonable d3.js (v4) update logic
_updated3 : function (canvas, data) {
// JOIN data to canvas and provide selection object
const circlesSelection = canvas.selectAll("circle").data(data);
// get circles which have to be added and subtracted
const circlesToAdd = circlesSelection.enter();
const circlesToRemove = circlesSelection.exit();
// create and delete svg object
const newCricles = circlesToAdd.append(d3.creator("circle"));
const obsoleteCircles = circlesToRemove.remove();
// get currently visible circles
const currentCircles = newCricles.merge(circlesSelection);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment