Skip to content

Instantly share code, notes, and snippets.

@sara-maria
Last active February 8, 2018 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sara-maria/a3c42d769de29e609f9d154ef52185b2 to your computer and use it in GitHub Desktop.
Save sara-maria/a3c42d769de29e609f9d154ef52185b2 to your computer and use it in GitHub Desktop.
fresh block
license: mit
<!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