-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Function to calculate rounded step values for RangeSlider (#186)
- Loading branch information
Hans Kallekleiv
authored
Jan 30, 2020
1 parent
2c55253
commit 20e0811
Showing
2 changed files
with
17 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |