flekschas / regl-scatterplot

Scalable WebGL-based scatter plot library build with Regl
https://flekschas.github.io/regl-scatterplot/
MIT License
184 stars 21 forks source link

fix: two issues related to point filtering #181

Closed flekschas closed 3 weeks ago

flekschas commented 3 weeks ago

This PR fixes two issues related point filtering

Description

What was changed in this pull request?

  1. After filter out some points, trying to programmatically hover them with scatterplot.hover(filteredOutPointIdx) will not work anymore
  2. When re-drawing points with preventFilterReset: true, the point index buffer will not be recreated to persist the current filter state

Here's an example showing the scatterplot.draw(newPoints, { preventFilterReset: true }) works as intended now

https://github.com/flekschas/regl-scatterplot/assets/932103/e5e8ae77-d311-4740-af8e-9bbbc01f7ba6

I simulated this with the basic example using:

setTimeout(() => {
  scatterplot.filter(
    scatterplot
      .get('points')
      .map((point, i) => [point, i])
      .filter(([point]) => point[0] >= 0)
      .map(([_, i]) => i)
  );
  console.log('Filter down to points on the right');
}, [500]);

setTimeout(() => {
  scatterplot.draw(scatterplot.get('points'), { preventFilterReset: true });
  console.log('Re-draw points with `preventFilterReset: true`');
}, [1000]);

setTimeout(() => {
  scatterplot.unfilter();
  console.log('Unset filter');
}, [3000]);

Why is it necessary?

Fixes an issue raised in Jupyter-Scatter

Checklist