Number
A KontrastNumber
holds a numeric value. In the simplest
case the value is directly taken from a numeric JavaScript value.
However, you can also assign mathematical expression as a string. The
expression is parsed, evaluated, and the result is stored in the
KontrastNumber
object.
Assignment
-
You can assign a JavaScript
number
. -
You can assign a
string
which is interpreted as a mathematical expression, such as'e^2'
,'sin(pi / 2))'
. All available functions are detailed here.
Context menu
In the context menu, the number can be entered as a string in the string format described above. Underlines are shown to clarify the grouping of the mathematical expression. There are some keyboard shortcuts:
-
Arrow up / Arrow down
Increase or decrease the number by a certain step size that is determined based on the typical range of the numbers.
-
Ctrl + Arrow up / Ctrl + Arrow down
Increase or decrease the number (with half the original step size)
-
Ctrl + Shift + Arrow up /
Ctrl + Shift + Arrow down
Increase or decrease the number (with one tenth the original step size)
Interface
Functions
-
assign(value: string | number)
Assign a new value. -
increase(amount: number)
Increase value by amount. -
decrease(amount: number)
Decrease value by amount. -
assignInstantly(value: string | number)
Assign a new value (without a smooth transition from the old value). -
addEventListener(eventName: string, callback: function)
Registers the callback function as an event listener for the specified event name. -
clearEventListener(eventName: string)
Remove all event listener callbacks associated with the event name.
Properties
-
type
:string
The read-only string 'KontrastNumber'.
-
defaultValue
:number
A read-only number that contains the default number of the specific property.
-
value
:number
The current value (as a JavaScript number).
Events
-
change
, callback:function () { … }
Event that fires whenever the value is changed.
See Events in Kontrast for more details of events.