Skip to content

Commit

Permalink
Allow defining slider format (#1142)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored Mar 12, 2020
1 parent 1f1399f commit 4fd6223
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 34 deletions.
15 changes: 1 addition & 14 deletions examples/reference/widgets/FileDownload.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,9 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.5"
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
Expand Down
25 changes: 23 additions & 2 deletions examples/reference/widgets/FloatSlider.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@
"##### Display\n",
"\n",
"* **``bar_color``** (color): Color of the slider bar as a hexadecimal RGB value\n",
"* **``callback_policy``** (str, **DEPRECATED**): Policy to determine when slider events are triggered (one of 'continuous', 'throttle', 'mouseup')\n",
"* **``callback_throttle``** (int, **DEPRECATED**): Number of milliseconds to pause between callback calls as the slider is moved\n",
"* **``direction``** (str): Whether the slider should go from left to right ('ltr') or right to left ('rtl')\n",
"* **``disabled``** (boolean): Whether the widget is editable\n",
"* **``format``** (str, bokeh.models.TickFormatter): Formatter to apply to the slider value\n",
"* **``name``** (str): The title of the widget\n",
"* **``orientation``** (str): Whether the slider should be displayed in a 'horizontal' or 'vertical' orientation.\n",
"* **``tooltips``** (boolean): Whether to display tooltips on the slider handle\n",
Expand Down Expand Up @@ -72,6 +71,28 @@
"float_slider.value"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A custom format string or bokeh TickFormatter may be used to format the slider values:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from bokeh.models.formatters import PrintfTickFormatter\n",
"\n",
"str_format = pn.widgets.FloatSlider(name='Distance', format='1[.]00')\n",
"\n",
"tick_format = pn.widgets.FloatSlider(name='Distance', format=PrintfTickFormatter(format='%.3f m'))\n",
"\n",
"pn.Column(str_format, tick_format)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
25 changes: 23 additions & 2 deletions examples/reference/widgets/IntSlider.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@
"##### Display\n",
"\n",
"* **``bar_color``** (color): Color of the slider bar as a hexadecimal RGB value\n",
"* **``callback_policy``** (str, **DEPRECATED**): Policy to determine when slider events are triggered (one of 'continuous', 'throttle', 'mouseup')\n",
"* **``callback_throttle``** (int, **DEPRECATED**): Number of milliseconds to pause between callback calls as the slider is moved\n",
"* **``direction``** (str): Whether the slider should go from left to right ('ltr') or right to left ('rtl')\n",
"* **``disabled``** (boolean): Whether the widget is editable\n",
"* **``format``** (str, bokeh.models.TickFormatter): Formatter to apply to the slider value\n",
"* **``name``** (str): The title of the widget\n",
"* **``orientation``** (str): Whether the slider should be displayed in a 'horizontal' or 'vertical' orientation.\n",
"* **``tooltips``** (boolean): Whether to display tooltips on the slider handle\n",
Expand Down Expand Up @@ -72,6 +71,28 @@
"int_slider.value"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A custom format string or bokeh TickFormatter may be used to format the slider values:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from bokeh.models.formatters import PrintfTickFormatter\n",
"\n",
"str_format = pn.widgets.FloatSlider(name='Rank', format='0o', start=0, end=100)\n",
"\n",
"tick_format = pn.widgets.FloatSlider(name='Count', format=PrintfTickFormatter(format='%d ducks'), start=0, end=100)\n",
"\n",
"pn.Column(str_format, tick_format)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
15 changes: 1 addition & 14 deletions examples/reference/widgets/MultiChoice.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,9 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.5"
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
Expand Down
25 changes: 23 additions & 2 deletions examples/reference/widgets/RangeSlider.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@
"##### Display\n",
"\n",
"* **``bar_color``** (color): Color of the slider bar as a hexadecimal RGB value\n",
"* **``callback_policy``** (str, **DEPRECATED**): Policy to determine when slider events are triggered (one of 'continuous', 'throttle', 'mouseup')\n",
"* **``callback_throttle``** (int, **DEPRECATED**): Number of milliseconds to pause between callback calls as the slider is moved\n",
"* **``direction``** (str): Whether the slider should go from left to right ('ltr') or right to left ('rtl')\n",
"* **``disabled``** (boolean): Whether the widget is editable\n",
"* **``format``** (str, bokeh.models.TickFormatter): Formatter to apply to the slider value\n",
"* **``name``** (str): The title of the widget\n",
"* **``orientation``** (str): Whether the slider should be displayed in a 'horizontal' or 'vertical' orientation.\n",
"* **``tooltips``** (boolean): Whether to display tooltips on the slider handle\n",
Expand Down Expand Up @@ -73,6 +72,28 @@
"range_slider.value"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A custom format string or bokeh TickFormatter may be used to format the slider values:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from bokeh.models.formatters import PrintfTickFormatter\n",
"\n",
"str_format = pn.widgets.RangeSlider(name='Distance', format='0.0a', start=100000, end=1000000)\n",
"\n",
"tick_format = pn.widgets.RangeSlider(name='Distance', format=PrintfTickFormatter(format='%.3f m'))\n",
"\n",
"pn.Column(str_format, tick_format)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
8 changes: 8 additions & 0 deletions panel/widgets/slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import numpy as np

from bokeh.models import CustomJS
from bokeh.models.formatters import TickFormatter
from bokeh.models.widgets import (
DateSlider as _BkDateSlider, DateRangeSlider as _BkDateRangeSlider,
RangeSlider as _BkRangeSlider, Slider as _BkSlider)
Expand All @@ -24,6 +25,7 @@
from .input import StaticText



class _SliderBase(Widget):

bar_color = param.Color(default="#e6e6e6", doc="""
Expand All @@ -50,6 +52,9 @@ class _SliderBase(Widget):

class ContinuousSlider(_SliderBase):

format = param.ClassSelector(class_=string_types+(TickFormatter,), doc="""
Allows defining a custom format string or bokeh TickFormatter.""")

_supports_embed = True

__abstract = True
Expand Down Expand Up @@ -275,6 +280,9 @@ def values(self):

class RangeSlider(_SliderBase):

format = param.ClassSelector(class_=string_types+(TickFormatter,), doc="""
Allows defining a custom format string or bokeh TickFormatter.""")

value = param.NumericTuple(default=(0, 1), length=2)

value_throttled = param.NumericTuple(default=None, length=2)
Expand Down

0 comments on commit 4fd6223

Please sign in to comment.