The circular buttons use callback to update which of the two is selected.
Last active
December 18, 2015 07:09
-
-
Save tgk/5744921 to your computer and use it in GitHub Desktop.
Circular buttons
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> | |
<meta charset="utf-8"> | |
<body> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script> | |
var width = 960, | |
height = 500; | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
function update(selected) | |
{ | |
// BUTTONS | |
var button = svg.selectAll("circle").data(["A", "B"]); | |
// enter | |
button.enter().append("circle") | |
.attr("cx", function(d, i) { return (i + 1) * 128; }) | |
.attr("cy", 128) | |
.attr("r", 60) | |
.style("stroke", "black") | |
.style("stroke-width", 3); | |
// update | |
button | |
.style("fill", | |
function(d) { | |
if (d == selected) | |
return "rgb(250,0,0)"; | |
else | |
return "rgb(128,128,128)"; | |
}) | |
// clicks | |
button | |
.on("mouseup", update); | |
} | |
update("A"); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment