slider
compute_step
def compute_step(difference: Decimal) -> Decimal
Compute what step should be used for the given domain difference.
The step is computed as: step = 10^(floor(log10(difference))) / 10
For cases where the step is a decimal (i.e. when the log10 is negative), the result is quantized to a fixed number of decimal places to avoid floating point imprecision.
Arguments:
difference
: The domain difference (must be positive).
Returns:
The computed step.
Slider
from dara.components.common.slider import Slider
class Slider(FormComponent)
A component to create a slider. The domain, ticks, stepping, rails and rail labels are controllable. The number of handles and their initial values are set via the number of values supplied. The value variable will update when handles are moved.
A simple Slider component with a single handle that tracks the selected value over a given range is created via:
from dara.core import Variable
from dara.components.common import Slider
value_var = Variable(0.5)
Slider(
domain=[0.0, 1.0],
value=value_var,
)
A more complex example with multiple handles, a set step size, specified ticks, a right hand rail and a track label is created via:
from dara.core import Variable
from dara.components.common import Slider
value_var = Variable([-3, 6, 8])
Slider(
domain=[-10, 10],
step=2,
rail_from_start=False,
rail_labels=['My Slider'],
rail_to_end=True,
ticks=[-9, -5, -1, 1, 5, 9],
value=value_var,
)
Setting the disable_input_alternative to True removes the switch for changing the slider to a numerical input box:
from dara.core.definitions import Variable
from dara.components.common import Slider
value_var = Variable(0.5)
Slider(
domain=[0.0, 1.0],
value=value_var,
disable_input_alternative=True,
)
Arguments:
domain
: The range of the slideronchange
: Optional action to call on each slider updatestep
: The step size of the sliderrail_from_start
: Boolean, if True the track is rendered from leftmost handle to the endrail_labels
: A label for the trackrail_to_end
: Boolean, if True the track is rendered from rightmost handle to the endthumb_labels
: A list of labels for the slider's thumbsticks
: List specifying the position of the ticksvalue
: A Variable instance recording the component's state; can be a single number for single-handle Slider, or an N-length array for a Slider with N handlesdisable_input_alternative
: Boolean, if True disable the rendering of the input alternative switchid
: the key to be used if this component is within a form
Attributes
- domain: List[float]
- onchange: Optional[Action]
- step: Optional[float]
- rail_from_start: bool
- rail_labels: Optional[List[str]]
- rail_to_end: bool
- thumb_labels: Optional[List[str]]
- ticks: Optional[List[Union[float, int]]]
- value: Optional[Union[Variable[Any], UrlVariable[Any]]]
- disable_input_alternative: bool
- id: Optional[str]