Created
October 23, 2015 21:26
-
-
Save awoodruff/e00e13783852880142ea to your computer and use it in GitHub Desktop.
circular dot symbol thing
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
var g = symbols.append("g"), | |
statePath = d3.select( /* selector for the state polygon */ ), | |
centroid = path.centroid( statePath.datum() ); | |
var total = // whatever the total number of dots is | |
dotDiameter = 4, | |
dist = 0, | |
circumference = 0, | |
canFit = 1, | |
count = 0, | |
angleDelta = 0; | |
for ( var i=0; i<total; i++ ){ | |
count++; | |
if ( count > canFit ){ | |
dist += dotDiameter; | |
circumference = 2 * dist * Math.PI; | |
canFit = Math.floor( circumference / dotDiameter ), | |
angleDelta = 2 * Math.PI / canFit; | |
count = 0; | |
} | |
var currentAngle = angleDelta * count; | |
var x = Math.cos(currentAngle) * dist, | |
y = Math.sin(currentAngle) * dist; | |
g.append( "circle" ) | |
.attr("cx",x+dotDiameter/2) | |
.attr("cy",y+dotDiameter/2) | |
.attr("r",dotDiameter/2) | |
.attr("fill","#ccc") | |
.attr("stroke","#666"); | |
} | |
g.attr("transform","translate(" + centroid.toString() + ")"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Missing the rest of the code for context (and for definitions of variables like
symbols
), but this is the general form of something that would arrange dot symbols into a kind of spiral/circle.