Skip to content

Instantly share code, notes, and snippets.

@shobhitg
Last active April 27, 2017 23:56
Show Gist options
  • Save shobhitg/8cdced5bf70a7abf5a884bb9fb3d317d to your computer and use it in GitHub Desktop.
Save shobhitg/8cdced5bf70a7abf5a884bb9fb3d317d 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 radius = 100, size=20;
// Converts from degrees to radians.
Math.radians = function(degrees) {
return degrees * Math.PI / 180;
};
// Converts from radians to degrees.
Math.degrees = function(radians) {
return radians * 180 / Math.PI;
};
// Feel free to change or delete any of the code you see in this editor!
var svg = d3.select("body").append("svg")
.attr("width", 960)
.attr("height", 500)
var statesData = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming', 'District of Columbia', 'Puerto Rico', 'Guam', 'American Samoa', 'U.S. Virgin Islands', 'Northern Mariana Islands']
//Draw the arcs themselves
svg.selectAll('text')
.data(statesData)
.enter().append('text')
.text(function(d){
return d;
})
.attr('x', function(d,i){return radius*Math.cos(Math.radians((180*i/size)-90)) + 0;})
.attr('y', function(d,i){return radius*2*Math.sin(Math.radians((180*i/size)-90)) + 250;})
// .attr("class", "monthArc")
// .attr("id", function(d,i) { return "monthArc_"+i; }) //Give each slice a unique ID
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment