Built with blockbuilder.org
Last active
February 8, 2018 13:56
-
-
Save sara-maria/a3c42d769de29e609f9d154ef52185b2 to your computer and use it in GitHub Desktop.
fresh block
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> | |
var width = 960; | |
var height = 500; | |
// 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 center = svg.append("g") | |
.attr("transform","translate(" + width/4 + ", " + height/2 + ")") | |
var radius = 200 | |
var data = d3.range(10); | |
console.log(data) | |
var selectedIndex = []; | |
function angle(i) { | |
return i/data.length*2*Math.PI; | |
} | |
var circle = center.selectAll("circle") | |
.data(data) | |
.enter().append("circle") | |
.attr("cx",function(d,i){ | |
return radius*Math.cos(angle(i)) | |
}) | |
.attr("cy",function(d,i){ | |
return radius*Math.sin(angle(i)) | |
}) | |
.attr("r",20) | |
.attr("fill",function(d) {return d3.rgb(20*d, 16*d, 200-30*d);}) | |
.on("mouseover",function(){ | |
d3.select(this) | |
.style("fill","red") | |
.style("opacity",".5") | |
.transition() | |
.attr("r",40) | |
}) | |
.on("mouseout",function(){ | |
d3.select(this) | |
.style("fill",function(d) {return d3.rgb(20*d, 16*d, 200-30*d);}) | |
.style("opacity","1") | |
.transition() | |
.attr("r",20) | |
}) | |
.on("click", function(d,i){ | |
selectedIndex = i; | |
console.log(selectedIndex) | |
}) | |
svg.append("text") | |
.text("JAZEKER!") | |
.attr("y", 200) | |
.attr("x", 120) | |
.attr("font-size", 46) | |
.attr("font-weight", "900") | |
.attr("font-family", "monospace") | |
.attr("fill", "red") | |
// var circle = svg.append("circle") | |
// .attr("cx",250) | |
// .attr("cy",250) | |
// .attr("r",20) | |
// .style("fill", "red") | |
// .style("stroke", "green") | |
// .style("stroke-width", 10) | |
// var rect = svg.append("rect") | |
// .attr("x",250) | |
// .attr("rx",25) | |
// .attr("y",250) | |
// .attr("width",100) | |
// .attr("height",120) | |
// .style("fill", "yellow") | |
// .style("stroke", "green") | |
// .style("stroke-width", 10) | |
// var line = svg.append("line") | |
// .attr("x1",100) | |
// .attr("y1",25) | |
// .attr("x2",250) | |
// .attr("y2",400) | |
// .style("stroke", "green") | |
// .style("stroke-width", 10) | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment