Created
December 31, 2011 12:22
-
-
Save jasondavies/1543851 to your computer and use it in GitHub Desktop.
Fast highlighting in D3
This file contains hidden or 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> | |
<title>Fast highlighting in D3</title> | |
<style> | |
circle { fill: #fff; stroke: #000; } | |
.highlight { fill: #fc0; } | |
</style> | |
<script src="http://d3js.org/d3.v2.min.js"></script> | |
</head> | |
<body> | |
<script> | |
var w = 500, | |
active = null; | |
d3.select("body").append("svg") | |
.attr("width", w) | |
.attr("height", w) | |
.selectAll("circle") | |
.data(d3.range(1000)) | |
.enter().append("circle") | |
.attr("r", 10) | |
.attr("cx", x) | |
.attr("cy", x) | |
.on("click", function() { | |
if (active) active.classed("highlight", false); | |
active = d3.select(this.parentNode.appendChild(this)) | |
.classed("highlight", true); | |
}); | |
function x() { | |
return Math.random() * w; | |
} | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment