-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Color Picker: Drag smoothly #8576
Color Picker: Drag smoothly #8576
Conversation
- Simplifies the code - Makes the color picker fluid - Adds configurable debounce - Fixes some niche issues like svg selection Touch support will come later after MudBlazor#8394 is resolved
Tests and docs are in progress but please give feedback on if this change is even viable! |
@ScarletKuro Please show me how you would replace the timer code with PeriodicTimer |
I will try to PR in the branch on the work. Btw the branch doesn't compile. it would be nice if it would to make sure I didn't break anything with periodic timer. |
@ScarletKuro Sure. Is this likely to be accepted? Is the debounce technique ok? |
Lets ask @henon. Personally I think the drag smoothness is suppose to be like this out of the box, so I like the change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debounce looks good
src/MudBlazor.UnitTests.Viewer/TestComponents/ColorPicker/SimpleColorPickerTest.razor
Show resolved
Hide resolved
@ScarletKuro ready for you to take a look |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #8576 +/- ##
==========================================
+ Coverage 89.75% 89.84% +0.09%
==========================================
Files 411 414 +3
Lines 11817 11917 +100
Branches 2362 2364 +2
==========================================
+ Hits 10606 10707 +101
+ Misses 683 678 -5
- Partials 528 532 +4 ☔ View full report in Codecov by Sentry. |
@mikes-gh Could you check these formatting errors? |
Looks like the way you declared the array. Dotnet format puts each element on its own line which is sub optimal. Maybe dont refactor this and you wont have a problem |
I was a little concerned that even if I reverted that it would still get flagged because the file was changed, but I will try it later. do you think this format error should be fixed or ignored for now? @mikes-gh |
@danielchalmers added periodic timer, I left some commented code and comments, feel free to polish. |
@ScarletKuro while I have your attention maybe you could check the two tests that I skipped 😜 |
Can you describe in few words what's wrong with tests? You need to wait when the timer fires and sets new value? |
Oh did you change the tests? I'm on my phone and didn't see. Basically the drag test doesn't actually drag and the selector one has the wrong offset because I let its events pass through to the overlay |
No, I didn't touch the tests. |
Isn't one of the problems that you send:
while upd: tho it seems like this didn't really fix the test. |
Guys, there is serious problem in the terminology. Now I have renamed everything from debounce to throttle, in code and examples. |
Nice catch. Throttle does make a lot more sense for this control and was the original functionality |
posted new code, pls re-review. |
<MudAlert Severity="Severity.Warning"> | ||
In Spectrum mode, the color selector (circle) will follow the mouse. This is implemented by listening to the mouse move DOM event with an in-built throttle mechanism to prevent flooding events. However, there are occasions like long latency in Blazor Server-Side where this implementation hasn't the expected visual assistance. If DisableDragEffect is set to true, no events will be fired. Per default, the effect is enabled. | ||
</MudAlert> | ||
The <CodeInline>DebounceInterval</CodeInline> property controls how long to wait until the color is updated while dragging the pointer in the spectrum view. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Old property name. And description needs updating
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we mention the difference in Blazor Server again?
there are occasions like long latency in Blazor Server-Side where this implementation hasn't the expected visual assistance.
b3178d6
to
dee5a19
Compare
@ScarletKuro LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ThrottleDispatcher
has one little inaccuracy which I guess doesn't really matter in this case: It will ignore the last invocation.
It would matter if you want to do a throttled value update where you need the last value. Of course, for that you would need a timer that fires the last action that was discarded due to throtteling at the end of the interval.
o is throttled invocation
. is throttled discard
x is additional invocation at the interval end of the last discarded action
o...o...o. x
Nice catch. But I guess we can fix it later in case it will matter, don't feel like headbanging more on this, I've already lost count of what revision this is. |
One of the throttle tests is flakey, it produced a count of 9 instead of 10 in the last assertion on my machine when running all tests, not when run individually. What's the correct way to make it reliable? [Test]
public async Task ThrottleDispatcher_ThrottleAsync()
{
// Arrange
var counter = 0;
var dispatcher = new ThrottleDispatcher(100);
var tasks = new List<Task>();
Task Invoke()
{
counter++;
return Task.CompletedTask;
}
Task CallThrottleAsyncAfterDelay(int delay)
{
Task.Delay(delay).ConfigureAwait(false).GetAwaiter().GetResult();
return dispatcher.ThrottleAsync(Invoke);
}
// Act
for (var i = 0; i < 20; i++)
{
tasks.Add(CallThrottleAsyncAfterDelay(50));
}
// Assert
await Task.WhenAll(tasks);
counter.Should().Be(10);
} |
Can you test if this is more stable?
maybe we could also just add |
Strange, the other one is even more unstable, I can easily reproduce 6 instead of 7 by executing all three a couple of times (already added interlocking, it didn't help). Maybe this is due to a call has been discarded? [Test]
public async Task ThrottleDispatcher_ThrottleDelayAfterExecutionAsync()
{
// Arrange
var counter = 0;
var dispatcher = new ThrottleDispatcher(100, delayAfterExecution: true);
var tasks = new List<Task>();
async Task Invoke()
{
Interlocked.Increment(ref counter);
await Task.Delay(50);
}
Task CallThrottleAsyncAfterDelay(int delay)
{
Task.Delay(delay).ConfigureAwait(false).GetAwaiter().GetResult();
return dispatcher.ThrottleAsync(Invoke);
}
// Act
for (var i = 0; i < 20; i++)
{
tasks.Add(CallThrottleAsyncAfterDelay(50));
}
// Assert
await Task.WhenAll(tasks);
counter.Should().Be(7);
} |
I know of this problem in my own rate limiter implementations. What I did was to set flexible limits. Like the counter should be greater than 3 instead of exactly 7 |
Yeah, you are right. |
Co-authored-by: Artyom M <artem.melnikov@live.com>
Description
MudColor
exception when bound to a null string.How Has This Been Tested?
visually
Types of changes
video7.mp4
video6.mp4
Touch (#8394 required):
video8.mp4
Docs
video8.mp4
Checklist:
dev
).