Skip to content

Instantly share code, notes, and snippets.

@awoodruff
Created October 23, 2015 21:26
Show Gist options
  • Save awoodruff/e00e13783852880142ea to your computer and use it in GitHub Desktop.
Save awoodruff/e00e13783852880142ea to your computer and use it in GitHub Desktop.
circular dot symbol thing
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() + ")");
@awoodruff
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment