Built with blockbuilder.org
xxxxxxxxxx
<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; }
</style>
</head>
<body>
<button>Update</button>
<script>
let data1 = [1,2,3,4,5,6,7,8,9,10]; //ENTER ALL
let data2 = [1,1,3,4,6,7,9,10]; //EXIT 2, 5, 8
let data3 = [1,2,3,4,5,6,7,9]; //ENTER 2, 5; EXIT 8, 10
let radius = 25;
let duration = 5000;
var svg = d3.select("body").append("svg")
.attr("width", 960)
.attr("height", 500)
update(data1);
function update(data) {
let circles = svg.selectAll("circle")
.data(data, function(d){ return d; });
let enter = circles.enter()
.append("circle")
.style("opacity", 0)
.style("fill", "blue")
.attr("r", radius)
.attr("cy", 25)
.attr("cx", function(d){ return 55 * d })
let exit = circles.exit();
let merge = circles.merge(enter)
.transition()
.duration(duration)
.style("opacity", 1)
exit.transition()
.duration(duration)
.style("opacity", 0)
.remove();
};
let currentData = 1;
d3.select("button")
.on("click", function(){
if (currentData == 1) {
update(data2);
currentData = 2;
} else if (currentData == 2) {
update(data3);
currentData = 3;
} else if (currentData == 3) {
update(data1);
currentData = 1;
} ;
})
</script>
</body>
https://d3js.org/d3.v4.min.js