Skip to content

Instantly share code, notes, and snippets.

Created October 26, 2015 05:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/b902f3a61e9b2663bad6 to your computer and use it in GitHub Desktop.
Save anonymous/b902f3a61e9b2663bad6 to your computer and use it in GitHub Desktop.
<-$
svg = d3.select '#map' .append 'svg:svg'
.attr 'width' '1440'
.attr 'height' '700'
g = svg.append 'g'
voronoi_map = g.append 'svg:g'
.attr 'id' 'voronoi'
circle = [[400 + 100 * Math.cos(i * 3.14 / 180), 300 + 100 * Math.sin(i * 3.14 / 180)] for i to 360]
circle = d3.geom.polygon circle
data = [[450, 350], [410, 360], [470, 310], [420, 320]]
voronoi = d3.geom.voronoi!
voronoi_map.selectAll "path" .data(voronoi data, (d) -> "M#{d.join 'L'}Z" .map (v) -> circle.clip d3.geom.polygon v)
.enter!append 'path'
.attr 'd' (d) -> "M#{d.join 'L'}Z"
.attr 'fill' 'none'
.attr 'stroke' 'black'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment