plotly.js icon indicating copy to clipboard operation
plotly.js copied to clipboard

Plotly.update(...) to select points on a graph

Open LoganWlv opened this issue 4 years ago • 1 comments

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 :

image

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

LoganWlv avatar Sep 23 '20 12:09 LoganWlv

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

jakeflorentine avatar Jun 21 '22 19:06 jakeflorentine