rreusser / controls-state

⚙️ An object for managing state
https://observablehq.com/@rreusser/control-panel-2-prototype-test
21 stars 2 forks source link

Add scale: 'log' to the slider #4

Closed marcofugaro closed 4 years ago

marcofugaro commented 5 years ago

I've used it a couple of times, and it was really useful, being able to see the effect of a really high value when selecting the end of the slider.

It's the scale: 'log' option of the Slider, like it's implemented in control-panel.

It would be awesome to have it in controls-state as well.

rreusser commented 5 years ago

Absolutely. I think I'd rather make this LogSlider than Slider({type: 'log'}). These things tend to bring in lots of corner cases and make other things (like default ranges) subtly incorrect or logic-branchy when it'd really be easier and more concise to just separate them. (In fact, I don't use control-panel's log slider because I think my implementation has a couple annoying bugs I just haven't bothered to fix 😬) What's your opinion, @marcofugaro?

rreusser commented 5 years ago

Alternatively, I maybe wouldn't mind a shorthand of type: 'log' with a more explicit way to specify it:mapping: Math.log, inverseMapping: Math.exp` so that you can just be explicit about exactly how it's mapped and perform your own mapping.

marcofugaro commented 5 years ago

That's a great idea! Way more flexible, so the default would be something like:

mappingFunction: x => x

Or just mapping like you said.

Also what do you mean by inverseMapping? For when the slider goes the inverse way?

rreusser commented 5 years ago

If you don't have a mapping that defines both directions, you can move a slider and convert that to a mapped value, but you won't be able to assign a value and set the slider position. In that sense it needs to be an invertible mapping. You might be able to solve that with Newton-Raphson or something, but it seems safest to just allow the user to specify the inverse mapping directly rather than guessing.

marcofugaro commented 4 years ago

Closed in #12 actually