Built with blockbuilder.org
Created
February 8, 2018 13:52
-
-
Save sannehombroek/77f5796d3626cd2c0423d10000067ae8 to your computer and use it in GitHub Desktop.
d3 workshop
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", width) | |
.attr("height", height) | |
var radius=200; | |
var data=d3.range(10); | |
var center = svg.append("g") | |
.attr("transform","translate 500,200") | |
function angle(i) {return i/data.length * 2*Math.PI;} | |
var width=1000 | |
var height=500 | |
var selectedIndex=0; | |
var circles= center.selectAll("circle") | |
.data(data) | |
circles.enter().append("circle") | |
.attr("cx",function(d,i){ | |
return radius*Math.cos(angle(i)) | |
}) | |
.attr("cy", function(d,i){ | |
if(i==selectedIndex){return0;} | |
return radius*Math.sin(angle(i)) | |
}) | |
.attr("r",23) | |
.on("mouseover", function() {d3.select(this) | |
.style("fill","orange") | |
}) | |
.on("mouseout", function() {d3.select(this)} | |
.style("fill","black") | |
) | |
.on("click", function(){ | |
}) | |
// var circle = svg.append("circle") | |
// .attr("cx",300) | |
// .attr("cy", 300) | |
// .attr("r",50) | |
// .style("fill","orange") | |
// .style("stroke", "blue") | |
// .style("stroke-width",10) | |
// var rect = svg.append("rect") | |
// .attr("x",100) | |
// .attr("y", 200) | |
// .attr("width", 400) | |
// .attr("height", 50) | |
// .attr("rx", 10) | |
// .style("fill", "green") | |
// var line = svg.append("line") | |
// .attr("x1", 300) | |
// .attr("y1", 300) | |
// .attr("x2", 500) | |
// .attr("y2", 500) | |
// .style("stroke", "yellow") | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment