-
Notifications
You must be signed in to change notification settings - Fork 949
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
Added FloatLogSlider #1928
Added FloatLogSlider #1928
Conversation
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.
Thanks again for adding this! There are a few places I noted where it's confusing what is talking about the exponent and what is talking about the actual value. Can you look at those?
ipywidgets/widgets/widget_float.py
Outdated
@@ -58,6 +58,39 @@ def _validate_max(self, proposal): | |||
self.value = max | |||
return max | |||
|
|||
class _BoundedLogFloat(_Float): | |||
max = CFloat(10.0, help="Max value").tag(sync=True) |
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.
Can we clarify that the min/max are exponents, while the value is an actual number? That was confusing to me.
ipywidgets/widgets/widget_float.py
Outdated
|
||
@validate('max') | ||
def _validate_max(self, proposal): | ||
"""Enforce min <= value <= max""" |
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.
We should compare value to the base**min
and base**max
, right?
ipywidgets/widgets/widget_float.py
Outdated
min = proposal['value'] | ||
if min > self.max: | ||
raise TraitError('Setting min > max') | ||
if min > self.value: |
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.
We should compare value to the base**min
and base**max
, right?
@@ -141,6 +176,46 @@ class FloatSlider(_BoundedFloat): | |||
continuous_update = Bool(True, help="Update the value of the widget as the user is holding the slider.").tag(sync=True) | |||
disabled = Bool(False, help="Enable or disable user changes").tag(sync=True) | |||
|
|||
style = InstanceDict(SliderStyle).tag(sync=True, **widget_serialization) |
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.
Thanks for catching that we didn't have the right style!
ipywidgets/widgets/widget_float.py
Outdated
value : float | ||
position of the slider | ||
min : float | ||
minimal position of the slider |
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.
Again, please clarify min/max are exponents
ipywidgets/widgets/widget_float.py
Outdated
minimal position of the slider | ||
max : float | ||
maximal position of the slider | ||
step : float |
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.
Please clarify step is a step in the exponent, not the actual value.
ipywidgets/widgets/widget_float.py
Outdated
""" | ||
_view_name = Unicode('FloatLogSliderView').tag(sync=True) | ||
_model_name = Unicode('FloatLogSliderModel').tag(sync=True) | ||
step = CFloat(0.1, help="Minimum step to increment the value").tag(sync=True) |
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.
help should clarify this is changing the exponent.
`description` | string | `''` | Description of the control. | ||
`disabled` | boolean | `false` | Enable or disable user changes | ||
`layout` | reference to Layout widget | reference to new instance | | ||
`max` | number (float) | `10.0` | Max value |
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.
Changing the help above to clarify min/max/step are talking about the exponent, then regenerating this, should change the docs here too.
a794665
to
c1c6e59
Compare
Thanks for the review :). I changed all the comments as proposed, and updated the PR. |
return _.extend(super.defaults(), { | ||
_model_name: 'FloatLogSliderModel', | ||
_view_name: 'FloatLogSliderView', | ||
step: 1.0, |
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.
step
has a different default than the python side.
if (isNaN(value as number)) { | ||
this.readout.textContent = this.valueToString(this.model.get('value')); | ||
} else { | ||
value = Math.max(Math.min(value as number, vmax), vmin); |
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.
This is comparing the actual value to vmin and vmax, which are exponents. This means that setting the value using the readout is clipped by the exponents, not the actual value range (e.g., try setting the readout to 20 with the default parameters...)
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.
Also, you don't need the as number
here either.
this.touch(); | ||
} | ||
|
||
_validate_slide_value(x) { |
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.
Please dedent this line.
ipywidgets/widgets/widget_float.py
Outdated
'.2f', help="Format for the readout").tag(sync=True) | ||
continuous_update = Bool(True, help="Update the value of the widget as the user is holding the slider.").tag(sync=True) | ||
disabled = Bool(False, help="Enable or disable user changes").tag(sync=True) | ||
base = CFloat(2., help="Base for the logarithm").tag(sync=True) |
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.
I know we had this discussion before - what do you think about defaulting to base 10? I think that might be more common in everyday use.
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.
If we did change it to base 10 (I think we probably ought to), we probably ought to default the max to something like 4, so we only go up to 10k.
let vmin = this.model.get('min'); | ||
let vmax = this.model.get('max'); | ||
|
||
if (isNaN(value as number)) { |
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.
You don't need the as number
since the stringToValue
function above is declared as returning a number.
Thanks! Just a few more comments above, and then I think we are good to go. |
Thanks for the review again :). I adressed all the comments, so I also changed the base to 10 and the default max to 4. |
I think the easiest way to correct it is to declare the default
(Would need to change the js side default too) |
a slider that uses a logarithmic scale. Closes jupyter-widgets#719
Thank you for the review again, and thanks for the catch. I actually did not test it without parameters. I added the default to both sides, and the bug seems to have disappeared. This one was quite strange, as it only seem to be appeared if |
Looks good. Thanks! |
Thanks for all the useful comments and for merging this PR :). |
a slider that uses a logarithmic scale. Closes #719