airbnb / visx

🐯 visx | visualization components
https://airbnb.io/visx
MIT License
19.4k stars 712 forks source link

Ability to constrain brush interactions #1850

Open neefrehman opened 4 months ago

neefrehman commented 4 months ago

While working on the brushing implementation for some graphs, one thing that I've found missing is the ability to constrain the zoom level that a brush interaction could result in. For some of our time-series data, we want to always be able to show multiple datapoints in the graph, and brushing can sometimes make this hard to achieve if a user incrementally zooms in.

We can currently prevent the graph's data from being updated in our handleBrush function like so:

onBrushEnd={(newBounds) => {
  handleBrush(newBounds);
  if (lessThanThreeDataPointsInBounds(newBounds)) {
    return
  }
  updateShownDatapoints(newBounds)
}}

Though in this scenario the rendered selectedBox will still update with the new bounds. It would be nice to introduce an API that can solve this case, as well as introduce some other related DX and UX improvements, such as automatically "expanding" the selection to the smallest allowed domain.