Graphite icon indicating copy to clipboard operation
Graphite copied to clipboard

Add shaking a dragged node free from its link

Open pwbh opened this issue 1 year ago • 16 comments

I have added a simple shake detection for #904

~~It seems to work well enough, although I can change it to work against some time delta which will check the differences between values in each "aggressive" movement back and forth, it probably will be more accurate, but please test this see how it feels first :)~~

pwbh avatar Feb 09 '24 08:02 pwbh

📦 Build Complete for 2af578f0ef163ad2b58b588477ef8332156109ea
https://7d1ca7d1.graphite.pages.dev

github-actions[bot] avatar Feb 09 '24 16:02 github-actions[bot]

Actually I am seeing that fast movement to left or right is triggering the shake check, I will improve it to use deltas between movement left and right and only trigger if the movement has been both to left and right in interval of some threshold, this should produce more accurate results.

pwbh avatar Feb 09 '24 17:02 pwbh

Yes, following what I mentioned in my comment in the issue, you need to take a much more sophisticated approach specifically designed to actually detect a user's intentional pointer shake over a series of samples spanning time, probably about half a second. That means recording every sample over that time in a running queue (discarding any that are older than that age) and performing analysis on them each frame. I suggested a metric which optimizes for detecting (beyond some threshold) a high ratio of direction change over average displacement, meaning the user is keeping the mouse in a relatively similar position but shaking a lot.

Keavon avatar Feb 09 '24 20:02 Keavon

@Keavon I have updated the implementation, feels much more accurate 😄

pwbh avatar Feb 11 '24 15:02 pwbh

!build

Keavon avatar Feb 11 '24 21:02 Keavon

📦 Build Complete for 16c4cf2005070e78bb4bb257d357f3084c6b88dc
https://d59f087a.graphite.pages.dev

github-actions[bot] avatar Feb 11 '24 21:02 github-actions[bot]

I gave it a quick test and it seems to have a very high rate of false positives. I also gave a quick glance at the code and I don't see a division sign anywhere, meaning I'm not sure if you took my suggestion to use an algorithm based on ratio of direction change over average displacement. Can you please carefully re-read my suggested algorithm and precisely implement that? (I also noticed that you seem to be using only the X axis, which I don't think is robust compared to considering both axes together. Direction change can be measured as the cross product of the vectors of mouse deltas in neighboring samples.)

Keavon avatar Feb 12 '24 09:02 Keavon

I gave it a quick test and it seems to have a very high rate of false positives. I also gave a quick glance at the code and I don't see a division sign anywhere, meaning I'm not sure if you took my suggestion to use an algorithm based on ratio of direction change over average displacement. Can you please carefully re-read my suggested algorithm and precisely implement that? (I also noticed that you seem to be using only the X axis, which I don't think is robust compared to considering both axes together. Direction change can be measured as the cross product of the vectors of mouse deltas in neighboring samples.)

It returns a lot of false positives because of the alert message, it felt better when I tested it against trigger with console.log instead which doesn't blurs the focus of dragging the node, but I'll tweak it to reflect your comment anyway, thanks.

pwbh avatar Feb 12 '24 10:02 pwbh

@Keavon just an FYI, but before going with your suggestions I'd like to try to tweak this implementation tomorrow morning, I just realized its missing a few things (for example I am not checking whether a movement occurred in both directions, and not only in one before checking for difference in captured positions), I'll test it again and if those changes won't achieve the desired effect, I'll reimplement it by your suggestion.

pwbh avatar Feb 12 '24 20:02 pwbh

!build

Keavon avatar Feb 14 '24 07:02 Keavon

📦 Build Complete for 08e1f3015fa11f21890c1f5ae392c6b8e8cb945b
https://ac031e5b.graphite.pages.dev

github-actions[bot] avatar Feb 14 '24 07:02 github-actions[bot]

!build

Keavon avatar Feb 15 '24 06:02 Keavon

📦 Build Complete for 5859d6587ba9e03a4cadf6841ed5527d7a5cc784
https://283259b3.graphite.pages.dev

github-actions[bot] avatar Feb 15 '24 06:02 github-actions[bot]

I'll look more closely at the code for shake detection, but it behaves reasonably well at the moment. Please proceed with implementing the actual shake removal now which should call into the backend (and I think that will require changes to the backend to implement the actual removal, you can reference the deletion code which does the job of reconnecting the link.)

Keavon avatar Feb 15 '24 21:02 Keavon

Checking on your status.

Keavon avatar Feb 29 '24 21:02 Keavon

hey hey hey, will try to finish it up in the coming week, sorry for the delay, was working on couple of personal stuff.

pwbh avatar Mar 30 '24 19:03 pwbh