Skip to content

Instantly share code, notes, and snippets.

@nickwhimster
Created July 14, 2015 21:43
Show Gist options
  • Save nickwhimster/3dec6e2873c826e3082c to your computer and use it in GitHub Desktop.
Save nickwhimster/3dec6e2873c826e3082c to your computer and use it in GitHub Desktop.
dohnut
{"description":"dohnut","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"pingpong","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"ajax-caching":true}
var data = [{g:300,name:"gold"},{g:238,name:"silver"},{g:309,name:"bronze"}];
var width = 700,
height = 350,
radius = Math.min(width, height) / 2;
var color = d3.scale.ordinal()
.range(["#98abc5", "#8a89a6", "#7b6888", "#6b486b", "#a05d56", "#d0743c", "#ff8c00"]);
var arc = d3.svg.arc()
.outerRadius(radius - 10)
.innerRadius(58);
var pie = d3.layout.pie()
.sort(null)
.value(function(d) { return d.g; });
var svg = d3.select("svg").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
var g = svg.selectAll(".arc")
.data(pie(data))
.enter().append("g")
.attr("class", "arc");
g.append("path")
.attr("d", arc)
.style("fill", function(d) { return color(d.data.name); });
g.append("text")
.attr("transform", function(d) { return "translate(" + arc.centroid(d) + ")"; })
.attr("dy", ".35em")
.style("text-anchor", "middle")
.text(function(d) { return d.data.name; });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment