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

Added FloatLogSlider #1928

Merged
merged 2 commits into from
Mar 23, 2018
Merged

Added FloatLogSlider #1928

merged 2 commits into from
Mar 23, 2018

Conversation

sebasguts
Copy link
Contributor

a slider that uses a logarithmic scale. Closes #719

Copy link
Member

@jasongrout jasongrout left a 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?

@@ -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)
Copy link
Member

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.


@validate('max')
def _validate_max(self, proposal):
"""Enforce min <= value <= max"""
Copy link
Member

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?

min = proposal['value']
if min > self.max:
raise TraitError('Setting min > max')
if min > self.value:
Copy link
Member

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)
Copy link
Member

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!

value : float
position of the slider
min : float
minimal position of the slider
Copy link
Member

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

minimal position of the slider
max : float
maximal position of the slider
step : float
Copy link
Member

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.

"""
_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)
Copy link
Member

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
Copy link
Member

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.

@sebasguts sebasguts force-pushed the master branch 2 times, most recently from a794665 to c1c6e59 Compare March 20, 2018 11:28
@sebasguts
Copy link
Contributor Author

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,
Copy link
Member

@jasongrout jasongrout Mar 20, 2018

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);
Copy link
Member

@jasongrout jasongrout Mar 20, 2018

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...)

Copy link
Member

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please dedent this line.

'.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)
Copy link
Member

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.

Copy link
Member

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)) {
Copy link
Member

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.

@jasongrout
Copy link
Member

Thanks! Just a few more comments above, and then I think we are good to go.

@sebasguts
Copy link
Contributor Author

Thanks for the review again :). I adressed all the comments, so I also changed the base to 10 and the default max to 4.

@jasongrout
Copy link
Member

Thanks! I noticed one last issue in doing final testing:

screen shot 2018-03-21 at 3 38 33 pm

Just invoking with FloatLogSlider() (or FloatLogSlider(value=0)) doesn't check against the min, apparently, so we get an invalid value (the value is actually 0, it's not just a readout problem).

@jasongrout
Copy link
Member

jasongrout commented Mar 22, 2018

I think the easiest way to correct it is to declare the default value for a _BoundedLogFloat to be one:

    value = CFloat(1.0, help="Float value").tag(sync=True)

(Would need to change the js side default too)

a slider that uses a logarithmic scale. Closes jupyter-widgets#719
@sebasguts
Copy link
Contributor Author

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 value=0 was passed, value=-1 for example would have set the initial value to 1. I assume it comes from the logarithm computation on the JavaScript side, but I am not completely sure.

@jasongrout
Copy link
Member

Looks good. Thanks!

@jasongrout jasongrout merged commit d1997c5 into jupyter-widgets:master Mar 23, 2018
@sebasguts
Copy link
Contributor Author

Thanks for all the useful comments and for merging this PR :).

@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
resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom scales for sliders
2 participants