d3 scatterplot example using the Breakfast Cereal Dataset from http://idvbook.com and based on the scatterplot example at http://bl.ocks.org/mbostock/3887118
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!");
}
- Click into the drawing area to start the selection frame
- move the mouse to resize the selection frame
- Release the mouse button to resize the selection frame
(The circles are just for illustrating purposes)