Skip to content

Instantly share code, notes, and snippets.

@danharr
Created April 15, 2014 15:03
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 danharr/10739790 to your computer and use it in GitHub Desktop.
Save danharr/10739790 to your computer and use it in GitHub Desktop.
simple voronoi
{"description":"simple voronoi","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"points.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"style.css":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/dR1mfxr.png","ajax-caching":true}
var vertices = tributary.points.map(function(d) {
return [d.x, d.y]
});
var svg = d3.select("svg");
var xScale = d3.scale.linear().domain([0,200]).range([10,600]);
var mydata = [
[100,200],
[200,400],
[50,25],
[400,680],
[200,200]
];
svg.selectAll("circle")
.data(mydata)
.enter()
.append("circle")
.attr({
cx: function(d) { return xScale(d[0]) },
cy: function(d) { return d[1] },
r: 5
})
var voronoi = d3.geom.voronoi(mydata)
var pathFn = function(d) {
return "M" + d.join("L") + "Z";
}
svg.selectAll("path")
.data(voronoi)
.enter()
.append("path")
.attr("d", pathFn)
.classed("voronoi", true)
[
{"x": 100, "y": 100},
{"x": 150, "y": 120},
{"x": 200, "y": 130},
{"x": 100, "y": 400},
{"x": 100, "y": 500},
{"x": 140, "y": 400},
{"x": 550, "y": 400},
{"x": 450, "y": 350},
{"x": 238, "y": 309},
{"x": 321, "y": 500},
{"x": 140, "y": 223},
{"x": 322, "y": 213},
{"x": 648, "y": 350},
{"x": 587, "y": 120}
]
.voronoi {
fill: #8AEEEE;
stroke: #000000;
fill-opacity: 0.5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment