Comments (10)
Unfortunately you can't do that. The slider is based on breaking the domain into steps. To do what you want to do, you would need to round the values to fit your step.
from react-compound-slider.
I was afraid you'd say that. Rounding the values is precisely what breaks the compatibility with my video player setup. To fix it I've rounded as you suggest, and stuck in a test to see whether the player's actually playing to prevent a slider -> player backreaction. It basically seems to work, but it'll be more robust when I can incorporate in the #42 changes.
Also, I'm still getting a few console warnings about invalid values - my rounding is sometimes 1E-8
different from your internal one. To fix this, I'm wondering whether it would be a good idea either to allow a flag to turn off these warnings, or to expose your valueToStep
or DiscreteScale
so these could be used for external rounding. Reproducing DiscreteScale
with its d3-array
dependencies seems cumbersome just to avoid rounding errors.
from react-compound-slider.
Ok. Yeah, we can wait for that PR to come in. In the mean time I took a crack at doing a video player to understand the issue. I don't know much about the HTML 5 video tag but this make sense to me...
https://codesandbox.io/s/1z51zn6q23
Does that do what you want it to do?
from react-compound-slider.
Hi, yes that works. Thanks. But I'm a bit confused about your use of videoCursor
. Seems you can achieve the same results without using videoCursor
at all, and just setting values
in onUpdate()
:
https://codesandbox.io/s/4jqk9ywwj9
Or am I missing something? It seems to give the same behavior as your version in both chrome and safari.
from react-compound-slider.
You're right! Yep, I had it continue to play while seeking before and then changed it, so that's not needed. This is much cleaner and mimics the controls on YouTube I think. Nice.
from react-compound-slider.
What do you think about the issues I mentioned above about providing a 'snap-to-nearest-rounding' option or exposing the internal rounding functions? In your solution you've reproduced it with Math.round
but that might not reliably reproduce the internal calcs, depending on the user's choice of domain and precision.
from react-compound-slider.
Yeah, to me, because of the issues with floating point numbers the method I used there is very safe and you can dial up or down to get more precision. It will always work and the reality is there's only so many pixels on the screen so you can't get infinite precision in a slider. In the video I did a hundredth of a second and it seems pretty fluid to me.
Have any ideas on what to do? Or maybe an example that you couldn't do this way?
from react-compound-slider.
Right, in cases where the slider's being used as a timeslider for a few minutes in real time, then simply always setting the step size to a nice number like 0.01 seconds probably gives no rounding issues. But perhaps the user wants to set the stepsize to be domain/1000 so that he doesn't need to worry about very long or short intervals giving unusable numbers of steps on the slider. In this case you can start getting rounding errors if you externally use Math.round
vs the internal DiscreteScale
class.
I think the most conservative proposal would be to expose Slider.valueToStep
as a function, then anyone having rounding issues can just apply this function rather than their own home-grown rounding. Alternatively (or even additionally), allow a silentSnap
option to be passed to the slider, which just turns off the rounding console warnings. I'd actually argue that this should be the default, since other sliders don't seem to give these types of console warnings.
from react-compound-slider.
I see. Yeah, I like the idea of just being able to turn off warnings. You want to do a PR for exposing the valueToStep?
from react-compound-slider.
I think this one is done. Open it back up if not.
from react-compound-slider.
Related Issues (20)
- SVG Handle Example? HOT 1
- airbnb slider in pure js or in jquery
- Tutorial step generates TypeError: children is not a function
- Showing rail in varying color based on tick position HOT 2
- Rounding error with domain that contain decimals HOT 1
- Handle id being sorted
- Handling values and step HOT 2
- Cannot read property 'type' of null error in 3.1.0 HOT 2
- the name of Ticks is undefined HOT 2
- Change in step behavior HOT 4
- Step of 0.01 results in too many decimal places in some generated values HOT 2
- Removing the `d3-array` dependency? HOT 2
- Handle tooltips need number formatting HOT 1
- Make Range slider draggable HOT 7
- Custom mode = same min/max value? HOT 1
- Allow slider to work in popup window by registering event listener with Slider's ownerDocument
- Show track with linear gradient?
- Dragging works incorrectly on wide slider with scrolls HOT 1
- How to avoid "jumping" handles?
- GetEventData function return undefined
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-compound-slider.