Skip to content

Commit

Permalink
Function to calculate rounded step values for RangeSlider (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans Kallekleiv authored Jan 30, 2020
1 parent 2c55253 commit 20e0811
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions webviz_config/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from ._available_port import get_available_port
from ._silence_flask_startup import silence_flask_startup
from ._dash_component_utils import calculate_slider_step
16 changes: 16 additions & 0 deletions webviz_config/utils/_dash_component_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import math


def calculate_slider_step(min_value: float, max_value: float, steps=100):
"""Calculates a step value for use in e.g. dcc.RangeSlider() component
that will always be rounded.
The number of steps will be atleast the number
of input steps, but might not be precisely the same due to use of the floor function.
This function is necessary since there is currently no precision control in the underlying
React component (https://github.com/react-component/slider/issues/275).
"""

return 10 ** math.floor(math.log10((max_value - min_value) / steps))

0 comments on commit 20e0811

Please sign in to comment.