Plotly plots selection in JavaScript is very slow
Plotly plots selection in JavaScript is very slow
I am trying to plot a scatter plot of nearly 100k items using plotly
in javascript
. I then want to select certain points from the plot.
plotly
javascript
I am able to plot the graph as I needed. But when I am trying to select the points the selection tool runs to slow ie response from the tool is very slow. It only happens after a few seconds.
How can I make the selection faster.? Is it fully machine dependent and require more hardware for the purpose.?
The below code shows how I am plotting and selecting the points. x_selected
and y_selected
are two arrays used to store the points selected.
x_selected
y_selected
Plotly.plot(
graphDiv,
[
{
type: "scatter",
mode: "markers",
x: WS,
y: AP,
xaxis: "x",
yaxis: "y",
name: "WS v/s AP",
marker: { color: color1, size: 5 }
}
],
{
title: "Lasso around the scatter points to see sub-distributions",
dragmode: "lasso",
autoresize: false,
width: 1500,
height: 1500,
xaxis: {
zeroline: false
},
yaxis: {
domain: [0.55, 1]
},
xaxis2: {
domain: [0, 0.45],
anchor: "y2"
},
yaxis2: {
domain: [0, 0.45],
anchor: "x2"
},
xaxis3: {
domain: [0.55, 1],
anchor: "y3"
},
yaxis3: {
domain: [0, 0.45],
anchor: "x3"
}
}
);
// Record points
// to append the present selection
graphDiv.on("plotly_selected", function(eventData) {
var x = ;
var y = ;
x_selected = ;
y_selected = ;
var colors = ;
for (var i = 0; i < N; i++) colors.push(color1Light);
eventData.points.forEach(function(pt) {
x_selected.push(pt.x);
y_selected.push(pt.y);
colors[pt.pointNumber] = color1;
});
Selecting in the sense drawing with the selection tool and at the same time appending the points that come under selection to an array. I will update the question to show code
– Sreeram TP
Jun 29 at 10:06
Not sure how the Plotly selection tool works, but "at the same time appending the points that come under selection to an array" sounds like it uses the DOM intersection API or something similar. That's going to be painfully slow on that amount of SVG nodes.
– Sergiu Paraschiv
Jun 29 at 10:08
I can't reduce the number of points and maybe I want to encounter more points in the future.
– Sreeram TP
Jun 29 at 10:10
Everything you're using is "built-in". Maybe you could prevent it from doing anything until
mouseup
, because I see it tries to highlight points real-time while drawing with the lasso tool.– Sergiu Paraschiv
Jun 29 at 10:16
mouseup
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Plotly builds charts as SVG. 100k+ SVG nodes are definitely not something you'd want to use DOM to traverse/manipulate unless you know exactly what you are doing. You'll have to show us what exactly you mean by "selecting" points, otherwise there's no way we can give you input on how you could optimise this.
– Sergiu Paraschiv
Jun 29 at 10:02