Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brush sometimes jumps around after releasing drag #1736

Closed
PatriceHerstix opened this issue Jul 28, 2023 · 4 comments
Closed

Brush sometimes jumps around after releasing drag #1736

PatriceHerstix opened this issue Jul 28, 2023 · 4 comments

Comments

@PatriceHerstix
Copy link

At my work, I had to create a graph using the Brush component. I noticed that after moving the selection, it slides to a different place than it should. Most of the time it's not noticeable, but occasionally there's a noticeable jump.

I have successfully reproduced this bug in the demo of the brush, as can be seen in the video below:

2023-07-27.17-37-37.mp4
@LlewynWan
Copy link

LlewynWan commented Aug 3, 2023

I ran into a similar issue lately. I was updating positions (react hooks) of draggable components in an onDragEnd event, which should cause a re-rendering. However, I found that the dx and dy fed to useDrag function did not update until the positions changed. It means that dx & dy were only reset to 0 after a re-rendering took place.
I haven't checked the source code, but with the documentation alone, I can't say whether it's a bug or intended behaviour. I think the onDragEnd should be a callback after everything's reset?

@JeanBaptisteBolh
Copy link

JeanBaptisteBolh commented Mar 26, 2024

I haven't looked under the hood or anything... but this jumpy behavior goes away by adding a delay (with debounce) to the onChange function of the Brush component.

This does come at the cost of not having a smooth re-render of the chart while you are moving the brush around:

import { debounce } from "lodash";

const onBrushChange = debounce((domain: Bounds | null) => {
    // ... other logic to 
    setFilteredData(newData);  // update the data displayed
  }, 150);
  
  ...
  
<Brush
    // other props
    onChange={onBrushChange}
/>

@abhinaynference
Copy link

I have added the debounce but facing an issue : on leaving the handle my min and max values are increased by certain amount

@hshoff
Copy link
Member

hshoff commented May 24, 2024

Fixed in #1836. Released in @visx/brush@3.10.4

@hshoff hshoff closed this as completed May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants