Skip to content

Instantly share code, notes, and snippets.

@infographicstw
Forked from anonymous/map.ls
Created October 26, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save infographicstw/c10902e24dc5a60a4f31 to your computer and use it in GitHub Desktop.
Save infographicstw/c10902e24dc5a60a4f31 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).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