the text shown in a label next to the number input field
function that returns the current target value
function to change the target value
Optional
textField: HTMLInputElementthe text field to use; if not provided, then a text field is created.
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
getter_function that returns the current target value
function that returns the current target value
Private
label_the name shown in a label next to the textField
Private
lastThe last value that the text field was set to, used to detect when user has intentionally changed the value; note that the target value will be different than this because of rounding.
Private
setter_function to change the target value
function to change the target value
Private
signifThe number of significant digits to display.
Private
textthe text field showing the double value
Private
value_The exact value of the target as last seen by this control; note that the displayed value may be different due to rounding.
Private
columnsPrivate
decimalReturns the number of fractional decimal places needed to show the number 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
doPrivate
formatPrivate
gainReturns 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 target value if observe is being called). The displayed value may be different due to rounding.
the value of this control
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 a value of –1 puts this 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 object 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
A text input element for displaying and editing the numeric value of a target object.
Because this is an Observer, you can connect it to a Subject; when the Subject broadcasts events, the observe method ensures that this control reflects the current target value.
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 setting is variable decimal places mode with 3 significant digits.
The displayed value is rounded to a certain number of digits, and therefore the displayed value can differ from the target value. NumericControlBase 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).To Do List
There is a problem with the current variable mode which is when you have a very tiny number, say 1.234567e-12, then it will format it like: 0.000000000001234567 when setting the significant digits to 7 and decimals to be variable. This is usually far bigger than we want. It should instead either switch to exponential, or have a maximum limit on the number of decimals shown. Or a limit on total number of digits shown, switching to exponential when needed.