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

Custom scales for sliders #719

Closed
aplavin opened this issue Aug 16, 2016 · 8 comments · Fixed by #1928
Closed

Custom scales for sliders #719

aplavin opened this issue Aug 16, 2016 · 8 comments · Fixed by #1928
Labels
feature request good first issue resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion.
Milestone

Comments

@aplavin
Copy link

aplavin commented Aug 16, 2016

Often when using sliders to manipulate some algorithm parameters it is useful to have logarithmic scale, instead of linear. Now I guess the only way is to manually apply the transformation in the handler, e.g. have the slider from -3 to 3 and in handler write value = 10**value. One thing is that it's not really convenient (code defining the real slider range becomes split into two parts in entirely different places), and another is that the slider label of course shows the "raw" value, not the real one used in computations.

I think there is a relatively easy solution - add two function arguments for FloatSlider to convert back and forth between the slider raw value and the real one (in my example they would be lambda x: 10**x and lambda x: log10(x), and/or maybe a boolean argument log for convenience, as probably logarithmic scale is needed way more often than other custom ones.

@SylvainCorlay
Copy link
Member

Or one could use d3 scales for this.

@aplavin
Copy link
Author

aplavin commented Aug 16, 2016

@SylvainCorlay do you mean it can be done using the current version of ipywidgets? I never used d3, and after looking at its tutorial on scales can't see how to integrate it with sliders/widgets.

@SylvainCorlay
Copy link
Member

No it cannot be done with the current version.

I was merely suggesting that instead of re-inventing the wheel we use d3 scales if we were to implemented scaled sliders.

@SylvainCorlay
Copy link
Member

@ellisonbg

@jdfreder
Copy link
Contributor

I don't think using a Python lambda would make sense here because the scale would be rendered in Javascript. We'd have to serialize the values before sending them to JS land, which would be prone to overflows.

@jasongrout jasongrout added this to the Backlog milestone Nov 8, 2016
@rafaqz
Copy link

rafaqz commented Nov 24, 2017

Bump on this issue. Setting a slider to be log-scaled over its range is a common need - I guess it should be as common as a log scale on a plot.

It's much cleaner having a log setting on the slider than transforming the return values with a separate function. Say you have 30 sliders for otherwise indistinguishable variables that are built programatically and displayed in order - but some need log scaling and others do not. Setting a 'log' flag on slider creation would make this really easy, while coding it manually, not so much. Lambdas might be overkill, as log and linear modes will cover 99.9% of use. Log should also be simple to implement.

@jasongrout
Copy link
Member

Agreed that log should be easy to implement. I think it may be easiest to just implement a FloatLogSlider. I'll make this a 'good first issue' since it seems to be relatively self-contained.

@sebasguts
Copy link
Contributor

I will give this a shot

sebasguts added a commit to sebasguts/ipywidgets that referenced this issue Jan 23, 2018
a slider that uses a logarithmic scale. Closes jupyter-widgets#719
sebasguts added a commit to sebasguts/ipywidgets that referenced this issue Jan 23, 2018
a slider that uses a logarithmic scale. Closes jupyter-widgets#719
sebasguts added a commit to sebasguts/ipywidgets that referenced this issue Mar 20, 2018
a slider that uses a logarithmic scale. Closes jupyter-widgets#719
sebasguts added a commit to sebasguts/ipywidgets that referenced this issue Mar 20, 2018
a slider that uses a logarithmic scale. Closes jupyter-widgets#719
sebasguts added a commit to sebasguts/ipywidgets that referenced this issue Mar 21, 2018
a slider that uses a logarithmic scale. Closes jupyter-widgets#719
sebasguts added a commit to sebasguts/ipywidgets that referenced this issue Mar 22, 2018
a slider that uses a logarithmic scale. Closes jupyter-widgets#719
@jasongrout jasongrout modified the milestones: Future, 7.2 Mar 29, 2018
@github-actions github-actions bot added the resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion. label Feb 7, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature request good first issue resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants