plotly.js
plotly.js copied to clipboard
Plotly.update(...) to select points on a graph
Hi,
Use case :
I have a two axis graph and I want to update it with some selected points.
To do that I am using Plotly.update
function and the selectedpoints
property to pass the indexes of the points that I want to select.
Following the documentation :
It seems to expect a one dimensional array. But with a one dimensional array it is not working and with a two dimensional array it works.
I did debug a bit the code and it seems that in the _restyle
function (for instance in plotly_basic.js), we do some logic on the property value (to handle multi traces? )
for(i = 0; i < traces.length; i++) {
cont = data[traces[i]];
contFull = getFullTrace(traces[i]);
var preGUI = fullLayout._tracePreGUI[contFull._fullInput.uid];
param = makeNP(preGUI, guiEditFlag)(cont, ai);
oldVal = param.get();
//Here if my selectedpoints are '[1, 2, 3, 4, 5]', newVal will always be '[0]'
// if selectedpoints are '[[1, 2, 3, 4, 5]]', newVal be identical
newVal = Array.isArray(vi) ? vi[i % vi.length] : vi;
In my understanding selectedpoints
should be defined as a
Two dimensional array containing integer indices of selected points for each trace.
Am I wrong?
Not working example
https://codepen.io/loganwlv/pen/jOqXQjN
Working example :
https://codepen.io/loganwlv/pen/ExKGObP
I believe that doc is from the individual grace level for the scatter chart. So, in the update function, we would have an array of objects with the selectedpoints field set to the individual indices. The 4th argument contains the trace indices to update
at least this is how I’ve used it