I have a trouble executing the following snippet. It is callback code for a larger python Bokeh plotting. Since my experience with javascript is limited I was drawing from this question on how to loop over an array in javascript.
This is the modified objects2 = ColumnDataSource(data=dict(x=[],y1=[],y2=[],y3=[], y4=[]))
var inds = cb_obj.get('selected')['1d'].indices; // Obtains column numbers
var d1 = m1.get('data'); // Obtains matrix with numbered columns that correspond to inds
var d2 = s2.get('data'); // Plotted data columns that get modified according to inds
var ys = ['y1','y2','y3','y4']; // Array of names of columns in d2/s2
var j, y, select= ys.slice(0,inds.length+1), // Limit number of columns to number of inds
//This piece is from the linked question - a loop through select (e.g only 'y1' and 'y2')
var len = select.length;
for(j=0; j<len; ++j) {
if (j in select) {
y = selected[j];
// For each selected name of a column
d2[y] = []; // Erase current value
// Fill the column from d1 (12 is just the length of the column)
for (var i = 0; i < 12; i++) {
d2[y].push(d1[inds[j]][i]),
}
}
}
s2.trigger('change');
The second loop was working just fine for a predefined number of y1,y2, when only two indices were passed to it. But my goal is to make the selection size dynamic i.e for a varying number of indices like [1,5,65,76] or [1,8] which is passed down from outside to inds, the code is to fill up appropriate number of ys so either y1,y2,y3,y4 or just y1,y2 with data from d1/m1.
From what I can tell the code "should" be doing just that , but I am obviously not seeing something.
For comparison here is the previous version of code that worked, but was limited to exactly two indices.
var inds = cb_obj.get('selected')['1d'].indices;
var d1 = m1.get('data');
var d2 = s2.get('data');
d2['y'] = []
d2['y2'] = []
for (i = 0; i < 12; i++) {
d2['y1'].push(d1[inds['0']][i]),
d2['y2'].push(d1[inds['1']][i])
}
s2.trigger('change');
Here is the whole thing (Python) with sample data for better visualization.