Meter

Meter

new Meter(optionsopt)

Source:
Properties:
Name Type Attributes Default Description
options.layout String <optional>
"left"

A string describing the layout of the meter. Possible values are "left", "right", "top" and "bottom". "left" and "right" are vertical layouts, where the meter is on the left or right of the scale, respectively. Similarly, "top" and "bottom" are horizontal layouts in which the meter is at the top or the bottom, respectively.

options.segment Integer <optional>
1

Segment size. Pixel positions of the meter level are rounded to multiples of this size. This can be used to give the level meter a LED effect and to reduce processor load.

options.value Number <optional>
0

Level value.

options.base Number <optional>
false

The base value of the meter. If set to false, the base will coincide with the minimum value options.min. The meter level is drawn starting from the base to the value.

options.value_label Number <optional>
0

Value to be displayed on the label.

options.format_value function <optional>
FORMAT("%.2f")

Function for formatting the label.

options.show_label Boolean <optional>
false

If set to true a label is displayed.

options.label Number <optional>
false

The title of the Meter. Set to false to hide it.

options.show_scale Boolean <optional>
true

Set to false to hide the scale.

options.value_label Number <optional>
0

The value to be drawn in the value label.

options.sync_value Boolean <optional>
true

Synchronize the value on the bar with the value label using options.format_value function.

options.foreground String | Boolean <optional>

Color to draw the overlay. Has to be set via option for performance reasons. Use pure opaque color. If opacity is needed, set via CSS on .aux-meter > .aux-bar > .aux-mask.

options.gradient Array.<Object> | Object | Boolean | function <optional>
false

The color gradient of the meter. Set to false to use the background option. Alternatively provide a callback to draw on the canvas manually. It receives the canvas's context, the widgets options, the canvas element and its width and height. Alternatively, provide an object with numeric values as key and the color as value, or an array of objects with 'value' and 'color' entry.

options.background String | Boolean <optional>

Background color to be used if no gradient is set.

Meter is a base class to build different meters from, such as LevelMeter. Meter contains a Scale widget and inherits all its options.

Note that level meters with high update frequencies can be very demanding when it comes to rendering performance. These performance requirements can be reduced by increasing the segment size using the segment option. Using a segment, the different level meter positions are reduced. This widget will take advantage of that by avoiding rendering those changes to the meter level, which fall into the same segment.

The meter is drawn as a mask above a background. The mask represents the inactive part of the meter. This mask is drawn into a canvas. The fillstyle of this mask is initialized from the background-color style of the canvas element with class aux-mask. Note that using a background-color value with opacity will lead to rendering artifacts in the meter. Instead, set the opacity of the mask to the desired value.

Parameters:
Name Type Attributes Default Description
options Object <optional>
{ }

An object containing initial options.

Extends

Members

_backdrop :HTMLCanvas

Source:

The canvas element drawing the background. Has class .aux-backdrop.

Type:
  • HTMLCanvas

_bar :HTMLDivElement

Source:

The DIV element containing the masks and drawing the background. Has class .aux-bar.

Type:
  • HTMLDivElement

_canvas :HTMLCanvas

Source:

The canvas element drawing the mask. Has class .aux-mask.

Type:
  • HTMLCanvas

element :HTMLDivElement

Source:

The main DIV container. Has class .aux-meter.

Type:
  • HTMLDivElement

label :Label

Source:

The Label displaying the title. Has class .aux-label.

Type:

scale :Scale

Source:

The Scale of the meter.

Type:

value :Label

Source:

The Label displaying the value.

Type:

Methods

addChild(child)

Source:
Inherited From:
See:

Registers a widget as a child widget. This method is used to build up the widget tree. It does not modify the DOM tree.

Parameters:
Name Type Description
child Widget

The child to add.

Fires:
  • Widget#event:child_added

addChildren(a)

Source:
Inherited From:

Registers an array of widgets as children.

Parameters:
Name Type Description
a Array.<Widget>

An array of Widgets.

allChildren()

Source:
Inherited From:

Returns an array of all children.

appendChild(child)

Source:
Inherited From:

Appends child.element to the widget element and registers child as a child widget.

Parameters:
Name Type Description
child Widget

The child widget to append.

appendChildren(children)

Source:
Inherited From:

Calls Widget#appendChild for an array of widgets.

Parameters:
Name Type Description
children Array.<Widget>

The child widgets to append.

destroy()

Source:
Overrides:

Dispose of this Widget.

destroyAndRemove()

Source:
Inherited From:

Dispose of this Widget and remove it from the DOM.

disableTansitions()

Source:
Inherited From:

Disable CSS transitions.

enableDraw()

Source:
Overrides:

Schedules this widget for drawing.

Fires:

enableDrawChildren()

Source:
Inherited From:

Enables rendering for all children of this widget.

enableTransitions()

Source:
Inherited From:

Enable CSS transitions.

forceHide()

Source:
Inherited From:

Hide the widget immediately by applying the class aux-hide. Does not call disableDraw().

forceShow()

Source:
Inherited From:

Show the widget immediately by applying the class aux-show. Does not call enableDraw().

getStyle()

Source:
Inherited From:

Returns the computed style of this widget's DOM element.

hidden()

Source:
Inherited From:

Returns the current hidden status.

hide()

Source:
Inherited From:

Hide the widget. This will result in the class aux-hide being applied to this widget in the next rendering step.

invalidate(key)

Source:
Inherited From:

Invalidates an option and triggers a redraw() call.

Parameters:
Name Type Description
key string

invalidateAll()

Source:
Inherited From:

Invalidates all dependencies which will trigger all renderers to rerun.

observeResize(cb)

Source:
Inherited From:

Calls a callback whenever the widget resizes. This method will trigger one resize.

Parameters:
Name Type Description
cb function

removeChild(child)

Source:
Inherited From:

Removes a child widget. Note that this method only modifies the widget tree and does not change the DOM.

Parameters:
Name Type Description
child Widget

The child to remove.

Fires:
  • Widget#event:child_removed

removeChildren(a)

Source:
Inherited From:

Removes an array of children.

Parameters:
Name Type Description
a Array.<Widget>

An array of Widgets.

set(key, value)

Source:
Inherited From:

Sets an option.

Parameters:
Name Type Description
key string

The option name.

value

The option value.

setStyle()

Source:
Inherited From:

Sets a CSS style property in this widget's DOM element.

show()

Source:
Inherited From:

Make the widget visible. This will apply the class aux-show during the next rendering step.

toggleHidden()

Source:
Inherited From:

Toggle the hidden status. This is equivalent to calling hide() or show(), depending on the current hidden status of this widget.

transitionsDisabled()

Source:
Inherited From:

Returns true if transitions are currently disabled on this widget.

visibleChildren()

Source:
Inherited From:

Returns an array of all visible children.

Events

destroy

Source:
Inherited From:

Is fired when a widget is destroyed.

doubleclick

Source:
Inherited From:

Is fired after a double click appeared. Set dblclick to 0 to disable click event handling.

Parameters:
Name Type Description
event string

The browsers MouseEvent.

GenericDOMEvents

Source:
Inherited From:

Generic DOM events. Please refer to W3Schools for further details.

hide

Source:
Inherited From:

The hide event is emitted when a widget is hidden and is not rendered anymore. This happens both with browser visibility changes and also internally when using layout widgets such as Pager.

initialized

Source:
Inherited From:

Is fired when a widget is initialized.

resize

Source:
Inherited From:

The resize event is emitted whenever a widget is being resized. This event can be used to e.g. measure its new size. Note that some widgets do internal adjustments after the resize event. If that is relevant, the Widget#resized event can be used instead.

resized

Source:
Inherited From:

The resized event is emitted after each rendering frame, which was triggered by a resize event.

set

Source:
Inherited From:

The set event is emitted when an option was set using the Widget#set method. The arguments are the option name and its new value.

Note that this happens both for user interaction and programmatical option changes.

show

Source:
Inherited From:

The show event is emitted when a widget is shown and is being rendered. This is the counterpart to Widget#hide.

visibility

Source:
Inherited From:

Is fired when the visibility state changes. The first argument is the visibility state, which is either true or false.