plotly / plotly.js

Open-source JavaScript charting library behind Plotly and Dash
https://plotly.com/javascript/
MIT License
16.94k stars 1.86k forks source link

add trace option to make some data not selectable in order to speed up slow box select #6822

Open danielsnider opened 9 months ago

danielsnider commented 9 months ago

Hi,

When there are a lot of data traces displayed in the plot (>10,000), box select is slow and laggy when you click and drag to select data traces. I notice it is even slower in version plotly.js@2.27.1 than it is in plotly.js@2.5.1. A hypothetical solution for me would be if you added a feature to exclude some traces from being selectable, as in the example below.

Example of proposed feature:

import React from 'react';
import Plot from 'react-plotly.js';

class MyPlot extends React.Component {
  render() {
    return (
      <Plot
        data={[
          {
            x: [1, 2, 3, 4],
            y: [10, 15, 13, 17],
            type: 'scattergl',
            mode: 'lines+markers',
            name: 'Selectable Trace'
          },
          {
            x: [1, 2, 3, 4],
            y: [16, 5, 11, 9],
            type: 'scattergl',
            mode: 'lines+markers',
            name: 'Non-selectable Trace',
            selectable: false   //  <------ THIS IS THE NEW FEATURE THAT IS BEING REQUESTED
          }
        ]}
        layout={{ 
          title: 'Selectable vs Non-selectable Traces'
        }}
      />
    );
  }
}

I have a temporary fix to speed up selection. When I tested this naive change, box select's click and drag is no longer laggy:

// Change in file: plotly.js/src/traces/scattergl/select.js
 module.exports = function select(searchInfo, selectionTester) {
  return [];  // Changed to always return no selected traces, because my own onSelected handler can do all the work using only the selected x, y range coordinates.
 }

If you can tell me how to monkey patch this in, that would be very helpful!

Thanks!

petervandenabeele commented 1 month ago

Not sure if related, but I posted a question on "slow box select" on Stack Overflow.

https://stackoverflow.com/questions/78892982/plotly-py-box-select-extremely-slow-on-first-call-on-second-and-higher-traces

For clarity, in that question, I avoid the effect that is pointed out in this feature request, by using only "lines" traces, that are excluded from this functionality already (like the exclusion you want here with the selectable flag).

Maybe it turns out the slow and laggy behaviour that is the starting point for this feature request is also related to the issue that I reported in the Stack Overflow question. An easy test would be to make your traces "lines" only (not "markers") and see if the slowness disappears (it should disappear on "lines only" for this feature of selectable to be useful).