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

VictoryBrushContainer: add a threshold for mouseMove events to avoid accidental minimal draws #1443

Merged
merged 2 commits into from
Nov 26, 2019

Conversation

Hypnosphi
Copy link
Contributor

@Hypnosphi Hypnosphi commented Nov 22, 2019

When using defaultBrushArea: 'move', it's too easy to accidentally draw a minimal selection when in fact you just click the empty area. I've added a customisable threshold for handling mouseMove with default of 2px

Probably related: #1058

if (
(!allowResize && !allowDrag) ||
!this.withinBounds({ x, y }, fullDomainBox) ||
!this.hasMoved({ ...targetProps, x2: x, y2: y })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is currently a check for whether the mouse moved in onMouseUp. I think the check should stay there, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to do it there initialy, but the drawing happens even before the mouseup

Copy link
Contributor

@boygirl boygirl Nov 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see what you mean. Since this has to run on every mouse move, it would be great to be able to short circuit it for users who don't have a mouseMoveThreshold defined. Like (targetProps.mouseMoveThreshold && !this.hasMoved({ ...targetProps, x2: x, y2: y }))

It might also be nice to reuse this logic in onMouseUp instead of the more naive check

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reuse this logic in onMouseUp

Why? x2 won't be different from x1 unless onMouseMove handling actually happens

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General preference for a named function like hasMoved, but I guess (x1 === x2 || y1 === y2) is already pretty concise and clear.

@@ -45,7 +45,8 @@ export const brushContainerMixin = (base) =>
stroke: "transparent",
fill: "transparent"
},
handleWidth: 8
handleWidth: 8,
mouseMoveThreshold: 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value for mouseMoveThreshold should be 0

@boygirl
Copy link
Contributor

boygirl commented Nov 26, 2019

@Hypnosphi Thanks! I'll get a patch out for you tonight :)

@boygirl boygirl merged commit c16d4be into FormidableLabs:master Nov 26, 2019
@Hypnosphi Hypnosphi deleted the mouse-move-threshold branch November 27, 2019 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants