D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
CoreyBurkhart
Full window
Github gist
Click Transition
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://d3js.org/d3.v4.min.js"></script> <style> body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } .circle, .updated { fill: red; } </style> </head> <body> <script> // Feel free to change or delete any of the code you see in this editor! var width = 900, height = 500, data = [50, 100, 150, 200, 250, 300, 350, 400]; var svg = d3.select("body").append("svg") .attr("width", width) .attr("height", height) .on('click', triggerTransition.bind(this)) var t = d3.transition() .duration(200) .ease(d3.easeLinear) var g = svg.append('g') .attr('class', 'group') .selectAll('.circle') .data(data) .enter() .append('circle') .attr('class', 'circle') .attr('r', 20) .attr('cx', width / 8) .attr('cy', function(d) {return d}) function triggerTransition() { data = [50, 100, 150, 200]; d3.selectAll('.circle') .data(data) // update .attr('class', 'updated') .exit() //exit and remove w/ transition .transition(t) .delay(function(d, i){return i * 400}) .attr('cx', 600) .remove() d3.selectAll('.updated') .transition(t) .delay(function(d, i){return i * 200}) .style('fill', 'blue') //update data that will stay // .attr('cy', function(d){return d* 2}) } </script> </body>
https://d3js.org/d3.v4.min.js