Built with blockbuilder.org
Last active
October 17, 2016 23:26
-
-
Save sampathweb/2d1eb60f870d07a4a7ac1d7c742817a1 to your computer and use it in GitHub Desktop.
merging selections
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: mit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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; } | |
</style> | |
</head> | |
<body> | |
<script> | |
// Feel free to change or delete any of the code you see in this editor! | |
var svg = d3.select("body").append("svg") | |
.attr("width", 960) | |
.attr("height", 500) | |
var dataFirst = [ | |
{ldap: "enjalot", x: 0}, | |
{ldap: "siumei", x: 1}, | |
{ldap: "ramesh", x: 2} | |
] | |
var dataLater = [ | |
{ldap: "sami", x: 3}, | |
{ldap: "logan", x: 4}, | |
{ldap: "phillip", x: 5}, | |
{ldap: "siumei", x: 6} | |
]; | |
svg.selectAll("circle") | |
.data(dataFirst, function(d) { | |
return d.ldap; | |
}) | |
.enter() | |
.append("circle") | |
.attr("r", 30) | |
.attr("cx", function(d, i) { | |
return 50 + i * 80 | |
}) | |
.attr("cy",100) | |
.attr("fill", "#eda39a") | |
.on("mouseover", function(d) { | |
console.log(d); | |
}) | |
setTimeout(function() { | |
var circles = svg.selectAll("circle") | |
.data(dataLater, function(d){ | |
return d.ldap; | |
}); | |
var enteredCircles = circles | |
.enter() | |
.append("circle") | |
.attr("r", 30) | |
.attr("cx", function(d, i) { | |
return 50 + d.x * 80 | |
}) | |
.attr("cy",100) | |
.attr("fill", "#862417"); | |
enteredCircles.merge(circles) | |
.attr("cx", function(d, i){ | |
return 50 + d.x * 80 | |
}) | |
.style("stroke", "#111") | |
}, 1000) | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment