Forked from: https://gist.github.com/gtb104/3667340
Here’s a d3 plugin that allows you to create a polygon selection. You instantiate it just like d3.svg.brush.
var brush = d3.svg.polybrush();
It has an extra public method that ‘brush’ does not, and that’s ‘isWithinExtent(x, y)’. You can use this method to test if a given point falls within the drawn extent.
if (brush.isWithinExtent(x, y)) {
console.log("I'm inside!");
}
Usage:
Click to add an anchor point, double click to close the selection.
Drag the selection to reposition it.
Double click outside the selection to clear it.
Areas For Improvement: