Accepted answer

What would be the best way of storing these selections?

Well, that's too "opinion based" for S.O. However, I'll share a very crude solution, in which instead of creating for each dot a list of clusters it belongs to, we'll create a list of cluster with their corresponding dots. Pretty much the opposite of what you asked, but you can easily modify the resulting array (an array with the dots for each selection) to create your desired record (one array with the selections for each dot).

The first step is defining the array outside lasso_end:

var clusters = [];

Then, inside lasso_end, we get a list of selected dots:

var selected = lasso.items().filter(function(d){
    return d.selected===true

var selectedDots = selected[0].map(d=>;

Here, I'm mapping by ID. Then, we push the array into clusters:


Every time the user selects some dots, cluster becomes bigger. So, in the first time, you can get something like this:

var clusters = [["dot_62","dot_68","dot_87","dot_119"]];

And, in the second time:

var clusters = [["dot_62","dot_68","dot_87","dot_119"],

Here is a plunker, select your dots and check the console:

PS: As I said before, this is a very crude solution: if the user just clicks anywhere in the chart, clusters will have a new empty array. So, you'll have to modify it to your purposes.

Related Query

More Query from same tag