From f3b24b1822883acadbde4c38d4634c8fae84829e Mon Sep 17 00:00:00 2001 From: Jason Grout Date: Fri, 23 Mar 2018 11:34:13 -0700 Subject: [PATCH 1/2] Update the float log slider to have exponent notation at extreme values. (.2f -> .3g) --- ipywidgets/widgets/widget_float.py | 5 ++--- packages/controls/src/widget_float.ts | 2 +- packages/schema/jupyterwidgetmodels.latest.md | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/ipywidgets/widgets/widget_float.py b/ipywidgets/widgets/widget_float.py index 1a0430d50e..6a35ddfdd2 100644 --- a/ipywidgets/widgets/widget_float.py +++ b/ipywidgets/widgets/widget_float.py @@ -201,7 +201,7 @@ class FloatLogSlider(_BoundedLogFloat): readout : {True, False} default is True, display the current value of the slider next to it readout_format : str - default is '.2f', specifier for the format function used to represent + default is '.3g', specifier for the format function used to represent slider value for human consumption, modeled after Python 3's format specification mini-language (PEP 3101). """ @@ -212,12 +212,11 @@ class FloatLogSlider(_BoundedLogFloat): default_value='horizontal', help="Vertical or horizontal.").tag(sync=True) readout = Bool(True, help="Display the current value of the slider next to it.").tag(sync=True) readout_format = NumberFormat( - '.2f', help="Format for the readout").tag(sync=True) + '.3g', 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(10., help="Base for the logarithm").tag(sync=True) - style = InstanceDict(SliderStyle).tag(sync=True, **widget_serialization) diff --git a/packages/controls/src/widget_float.ts b/packages/controls/src/widget_float.ts index dc80665515..e2d532455f 100644 --- a/packages/controls/src/widget_float.ts +++ b/packages/controls/src/widget_float.ts @@ -80,7 +80,7 @@ class FloatLogSliderModel extends BoundedFloatModel { orientation: 'horizontal', _range: false, readout: true, - readout_format: '.2f', + readout_format: '.3g', slider_color: null, continuous_update: true, disabled: false, diff --git a/packages/schema/jupyterwidgetmodels.latest.md b/packages/schema/jupyterwidgetmodels.latest.md index 4a594f150a..b6cc1d191b 100644 --- a/packages/schema/jupyterwidgetmodels.latest.md +++ b/packages/schema/jupyterwidgetmodels.latest.md @@ -316,7 +316,7 @@ Attribute | Type | Default | Help `min` | number (float) | `0.0` | Min value for the exponent `orientation` | string (one of `'horizontal'`, `'vertical'`) | `'horizontal'` | Vertical or horizontal. `readout` | boolean | `true` | Display the current value of the slider next to it. -`readout_format` | string | `'.2f'` | Format for the readout +`readout_format` | string | `'.3g'` | Format for the readout `step` | number (float) | `0.1` | Minimum step in the exponent to increment the value `style` | reference to SliderStyle widget | reference to new instance | `value` | number (float) | `1.0` | Float value From b2c0e9869da6ce3c1e64bbcdd205ebd71c968346 Mon Sep 17 00:00:00 2001 From: Jason Grout Date: Fri, 23 Mar 2018 11:43:17 -0700 Subject: [PATCH 2/2] Add FloatLogSlider to the widget list. --- docs/source/examples/Widget List.ipynb | 32 +++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/docs/source/examples/Widget List.ipynb b/docs/source/examples/Widget List.ipynb index c71c8ae373..8b716251a2 100644 --- a/docs/source/examples/Widget List.ipynb +++ b/docs/source/examples/Widget List.ipynb @@ -40,7 +40,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "There are 10 widgets distributed with IPython that are designed to display numeric values. Widgets exist for displaying integers and floats, both bounded and unbounded. The integer widgets share a similar naming scheme to their floating point counterparts. By replacing `Float` with `Int` in the widget name, you can find the Integer equivalent." + "There are many widgets distributed with IPython that are designed to display numeric values. Widgets exist for displaying integers and floats, both bounded and unbounded. The integer widgets share a similar naming scheme to their floating point counterparts. By replacing `Float` with `Int` in the widget name, you can find the Integer equivalent." ] }, { @@ -218,6 +218,36 @@ ")" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### FloatLogSlider" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The `FloatLogSlider` has a log scale, which makes it easy to have a slider that covers a wide range of positive magnitudes. The `min` and `max` refer to the minimum and maximum exponents of the base, and the `value` refers to the actual value of the slider." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "widgets.FloatLogSlider(\n", + " value=10,\n", + " base=10,\n", + " min=-10, # max exponent of base\n", + " max=10, # min exponent of base\n", + " step=0.2, # exponent step\n", + " description='Log Slider'\n", + ")" + ] + }, { "cell_type": "markdown", "metadata": {},