the ParameterNumber to display and control
the minimum value that the slider can reach
the maximum value that the slider can reach
Optional
multiply: booleanwhether the slider increases by multiplying or adding the
delta for each step; default is false
meaning "add"
Optional
increments: numberthe number of increments, between max and min, that the value can take on; default is 100
Private
columns_The number of columns (characters) shown in the text field.
Private
decimalFixed number of fractional decimal places to show, or -1 if variable.
Private
firstTrue when first click in field after gaining focus.
Private
paramThe exact value of the Parameter as last seen by this control; note that the displayed value may be different due to rounding.
Private
signifThe number of significant digits to display.
Private
sliderThe value according to the slider control; used to detect when user has intentionally changed the value. This value can change only by discrete increments therefore it only approximates the current parameter value.
Private
textthe text field showing the double value
Private
textboxThe last value that the text field was set to, used to detect when user has intentionally changed the value; note that the parameter value will be different than this because of rounding.
Private
changePrivate
clickPrivate
clickPrivate
columnsPrivate
decimalReturns the number of fractional decimal places needed to show the number
x
with the given number of significant digits.
the number to display
the number of significant digits to show
the number of fractional decimal places needed
Private
focusPrivate
formatReturns the number of significant digits to show when formatting the number. Only has an effect in variable decimal places mode, see getDecimalPlaces.
the number of significant digits to show when formatting the number
Returns the value of this control (which should match the Parameter value if observe is being called).
the value that this control is currently displaying
Notifies this Observer that a change has occurred in the Subject.
contains information about what has changed in the Subject: typically either a one-time GenericEvent, or a change to the value of a Parameter
Sets the fixed number of fractional decimal places to show when formatting the number, or puts this SliderControl into variable decimal places mode where the number of decimal places depends on the desired number of significant digits. See setSignifDigits.
the fixed number of fractional decimal places to show when formatting the number, or –1 to have variable number of fractional decimal places.
this SliderControl for chaining setters
Sets the number of significant digits to show when formatting the number. Only has an effect in variable decimal places mode, see setDecimalPlaces.
the number of significant digits to show when formatting the number
this object for chaining setters
Returns a minimal string representation of this object, usually giving just identity information like the class name and name of the object.
For an object whose main purpose is to represent another Printable object, it is
recommended to include the result of calling toStringShort
on that other object.
For example, calling toStringShort()
on a DisplayShape might return something like
this:
DisplayShape{polygon:Polygon{'chain3'}}
a minimal string representation of this object.
Private
validateGenerated using TypeDoc
Creates a "slider plus textbox" control that displays and modifies the given ParameterNumber. Consists of a label plus a slider and textbox which show the value of the ParameterNumber. Modifying the slider changes the value of the ParameterNumber, as does editing the number in the textbox.
In most browsers you can use the arrow keys to adjust the value after clicking on the slider. Some browsers highlight the slider when it is active.
The HTML elements created are wrapped in a single
<div>
element. The slider has a classname ofslider
for CSS scripting. The label is just text within the<div>
.SliderControl Math
The value of the SliderControl can only roughly match the value of the ParameterNumber because SliderControl can only take on discrete values. In the following,
sliderIndex
means the value of the HTML range element, which is an integer from 0 toincrements
.SliderControl can multiply or add a factor to move between increments. If it adds, the relationships are:
If it multiplies, the relationships are:
Number Formatting
The number is formatted without any thousands separators and with the number of fractional decimal places depending on the "mode".
Fixed decimal places mode shows the number of decimal places given by getDecimalPlaces. Ignores significant digits setting. Fixed decimal places mode is active when
getDecimalPlaces()
returns 0 or greater.Variable decimal places mode ensures that the requested number of significant digits are visible. Adjusts decimal places shown based on the magnitude of the value. See setSignifDigits. Variable decimal places mode is active when
getDecimalPlaces()
returns –1.The default settings are gotten from the ParameterNumber: see ParameterNumber.setDecimalPlaces and ParameterNumber.setSignifDigits.
The displayed value is rounded to a certain number of digits, and therefore the displayed value can differ from the target value. SliderControl allows for this difference by only making changes to the target value when the the user modifies the displayed value, or when setValue is called.
Preventing Forbidden Values
To prevent the user from entering forbidden values (such as enforcing upper or lower limits) the setter function can throw an Error. An alert is displayed to the user with the text of the Error. After dismissing the alert, the displayed value will be restored to match the current target value, as returned by the
getter
. (Note that the user's input is discarded).How SliderControl Works
Both the slider and the text are approximations of the value of the ParameterNumber. SliderControl allows for this difference by only making changes to the target value when the the user modifies the displayed value, or when setValue is called.
There are 3 entities to coordinate: ParameterNumber, textbox, slider. Each has its own notion of the current value; changes can come from any of the 3 entities. The textbox and slider are limited in the values they can represent because of rounding in textbox or increments in slider. Essentially we need to:
Distinguish between a genuine change vs. events coming thru as a result of updating a control or ParameterNumber in response to a genuine change (we can call these 'echo events').
when a genuine change occurs, update all 3 entities.
The ParameterNumber can take on any value allowed by the ParameterNumber's upper and lower limits. If the ParameterNumber takes on a value outside the range of the slider, then the slider will be at its min or max position.
Odd Behavior in Browsers
In all browsers, clicking in the slider area moves the thumb to that position. In Safari and Chrome, clicking directly on the thumb does not change the value. But in Firefox, clicking directly on the thumb does "move to that position" which results in the value being set to the nearest increment.
Safari does not visually highlight the thumb after clicking it.
In Safari, to be able to "tab select" to get to the slider, turn on the option in Preferences>Advanced called "Press Tab to highlight each item on a webpage".
History
In an earlier version the slider and text box were both contained in a
<label>
element. This caused confusion because click events would be passed to thefor
entity of the label. Thefor
attribute of a label seems to be the first control unless it is explicitly specified. The solution is to not use<label>
for grouping the slider elements, but use a<div>
instead.