new Range(options)

TK.Range is used for calculating linear scales from different values. They are useful to build coordinate systems, calculate pixel positions for different scale types and the like. TK.Range is used e.g. in TK.Scale, TK.MeterBase and TK.Graph to draw elements on a certain position according to a value on an arbitrary scale.

Name Type Description
options Object
Name Type Attributes Default Description
options.scale string <optional>

What kind of value are we working with?

  • "linear"
  • "decibel" / "log2"
  • "frequency"
  • function (value, options, coef) {}
If a function instead of a constant is handed over, it receives the actual options object as the second argument and is supposed to return a coefficient between 0 and 1. If the third argument "coef" is true, it is supposed to return a value depending on a coefficient handed over as the first argument.

options.reverse boolean <optional>

true if the range is reversed.

options.basis number <optional>

Dimensions of the range, set to width/height in pixels, if you need it for drawing purposes, to 100 if you need percentual values or to 1 if you just need a linear coefficient for a e.g. logarithmic scale.

options.min number <optional>

The minimum value possible.

options.max number <optional>

The maximum value possible.

options.step number <optional>

Step size, needed for e.g. user interaction

options.shift_up number <optional>

Multiplier for e.g. SHIFT pressed while stepping

options.shift_down number <optional>

Multiplier for e.g. SHIFT + CONTROL pressed while stepping

options.snap mixed <optional>

Snap the value to a virtual grid with this distance Using snap option with float values causes the range to reduce its minimum and maximum values depending on the amount of decimal digits because of the implementation of math in JavaScript. Using a step size of e.g. 1.125 reduces the maximum usable value from 9,007,199,254,740,992 to 9,007,199,254,740.992 (note the decimal point)

options.round boolean <optional>

if snap is set decide how to jump between snaps. Setting this to true slips to the next snap if the value is more than on its half way to it. Otherwise the value has to reach the next snap until it is hold there again.

Mixes In:


Methods inherited from TK.Base

add_event(event, func, prevent, stop)

Register an event handler.

add_events(events, func)

Add multiple event handlers at once, either as dedicated event handlers or a list of event descriptors with a single handler function.

delegate_events(element) → {HTMLElement}

Delegates all occuring DOM events of a specific DOM node to the widget. This way the widget fires e.g. a click event if someone clicks on the given DOM node.


Destroys all event handlers and the options object.

fire_event(event, …args)

Fires an event.


Fires several events.


Get the value of an option.

has_event_listeners(event) → {boolean}

Test if the event descriptor has some handler functions in the queue.

remove_event(event, func)

Removes the given function from the event queue. If it is a native DOM event, it removes the DOM event listener as well.

remove_events(events, func)

Remove multiple event handlers at once, either as dedicated event handlers or a list of event descriptors with a single handler function.

set(key, value)

Sets an option. Fires both the events set with arguments key and value; and the event 'set_'+key with argument value.


Merges a new options object into the existing one including deep copies of objects. If an option key begins with the string "on" it is considered as event handler. In this case the value should be the handler function for the event with the corresponding name without the first "on" characters.

Events inherited from TK.Base


Is fired when an element is delegated.


Is fired when an instance is initialized.


Is fired when an option is set.


Is fired when an option is set.