Overview

Smart.Gauge is a circular (or semi-circular) numeric control used to display or select a value from a range.

To initialize a gauge element the user has to include the following files to the head of the page:

  • smart.base.css – the CSS file containing the styles for element.
  • smart.element.js – the base class.
  • smart.button.js – additional JS file containing the definition for the value control buttons.
  • smart.complex.js – necessary for the initialization of the digital display.
  • smart.numeric.js – this file contains functions used for the processing of numeric objects.
  • smart.math.js – this file contains many of the mathematical functions used by the Smart.Gauge custom element.
  • smart.tickintervalhandler.js – this file contains functions used for calculating the tick interval of the Smart.Gauge custom element.
  • smart.tank.js – the JS file containing the definition for gauge’s base class – smartTank.
  • smart.draw.js – this file contains SVG rendering functionality used in Smart.Gauge
  • smart.numerictextbox.js – this file contains the smart-numeric-text-box custom element. The digital display of Smart.Gauge is an instance of smart-numeric-text-box.
  • smart.gauge.js – the JS file containing the definition for the element.

Here’s how to initialize a gauge element:

<!DOCTYPE html>
<html lang="en">
<head>
 <link rel="stylesheet" href="../../source/styles/smart.base.css" type="text/css" />
 <script type="text/javascript" src="webcomponents-lite.js"></script>
 <script type="text/javascript" src="../../source/smart.element.js"></script>
 <script type="text/javascript" src="../../source/smart.tank.js"></script>
 <script type="text/javascript" src="../../source/smart.gauge.js"></script>
 <script type="text/javascript" src="../../source/smart.draw.js"></script>
 <script type="text/javascript" src="../../source/smart.numeric.js"></script>
 <script type="text/javascript" src="../../source/smart.math.js"></script>
 <script type="text/javascript" src="../../source/smart.tickintervalhandler.js"></script>
 <script type="text/javascript" src="../../source/smart.numerictextbox.js"></script>
 <script type="text/javascript" src="../../source/smart.button.js"></script>
 <script type="text/javascript" src="../../source/smart.complex.js"></script>
</head>
<body>
 <smart-gauge></smart-gauge>
</body>
</html>

Demo

Note how smart.element.js and webcomponents.min.js are declared before everything else. This is mandatory for all custom elements.

Also note that the reference to smart.tank.js is declared before smart.gauge.js. This is important because Smart.Gauge extends Smart.Tank and reuses most of its methods.


In order to change the value of the gauge the value property has to be applied via javascript:

<!DOCTYPE html>
<html lang="en">
<head>
 <link rel="stylesheet" href="../../source/styles/smart.base.css" type="text/css" />
 <script type="text/javascript" src="webcomponents-lite.js"></script>
 <script type="text/javascript" src="../../source/smart.element.js"></script>
 <script type="text/javascript" src="../../source/smart.tank.js"></script>
 <script type="text/javascript" src="../../source/smart.gauge.js"></script>
 <script type="text/javascript" src="../../source/smart.draw.js"></script>
 <script type="text/javascript" src="../../source/smart.numeric.js"></script>
 <script type="text/javascript" src="../../source/smart.math.js"></script>
 <script type="text/javascript" src="../../source/smart.tickintervalhandler.js"></script>
 <script type="text/javascript" src="../../source/smart.numerictextbox.js"></script>
 <script type="text/javascript" src="../../source/smart.button.js"></script>
 <script type="text/javascript" src="../../source/smart.complex.js"></script>
 <script>
     window.onload = function () {
         var gauge = document.querySelector('smart-gauge');
         gauge.value = 25;
     }
 </script>
</head>
<body>
 <smart-gauge></smart-gauge>
</body>
</html>

Demo

or set it as HTML attribute:

<smart-gauge value="25"></smart-gauge>

Demo

Appearance


Smart.Gauge uses a scale to indicate the value. The scale can be positioned inside or outside of the element thanks to the scalePosition property. The property also allows gauge without scale, when is set to “none”. By default it’s located inside.

Let’s change the position of the scale via javascript:

<smart-gauge scale-position="outside"></smart-gauge>

Demo

The ticks of the scale can also be customized. They can be positioned above the track or inside it by setting the tickPosition property. tickPosition: track affects when analogDisplayType is fill or line.

<smart-gauge analog-display-type="fill" ticks-position="track"></smart-gauge>

Demo

The scale of the Gauge contains major and minor ticks which are visible by default. This can be re-configured. The user can display only the major, the minor or none of them if he prefers by setting the ticksVisibility property. This can also be done in the HTML code on initialization like so:

<smart-gauge ticks-visibility="major"></smart-gauge>

Demo

The scale of the Gauge has ticks and labels. Labels are also customizable. The user can control which of them to be visible:

  • none – no labels are visible
  • all – all labels are visible
  • endPoints – only the first and last labels are visible

The text of the label can also be modified thanks to the labelFormatFunction property. It’s a format function that takes one argument – the value of the label. The function must return a string representing the new text for the lables. The property can be applied via javascript like so:

                    <!DOCTYPE html>
<html lang="en">
<head>
 <link rel="stylesheet" href="../../source/styles/smart.base.css" type="text/css" />
 <script type="text/javascript" src="webcomponents-lite.js">
</script> <script type="text/javascript" src="../../source/smart.element.js"></script> <script type="text/javascript" src="../../source/smart.tank.js"></script> <script type="text/javascript" src="../../source/smart.gauge.js"></script> <script type="text/javascript" src="../../source/smart.draw.js"></script> <script type="text/javascript" src="../../source/smart.numeric.js"></script> <script type="text/javascript" src="../../source/smart.math.js"></script> <script type="text/javascript" src="../../source/smart.tickintervalhandler.js"></script> <script type="text/javascript" src="../../source/smart.numerictextbox.js"></script> <script type="text/javascript" src="../../source/smart.button.js"></script> <script type="text/javascript" src="../../source/smart.complex.js"></script> <script> window.onload = function () { var gauge = document.querySelector('smart-gauge'); gauge.labelFormatFunction = function (value) { return value + ' ' + 'in'; } } </script> </head> <body> <smart-gauge></smart-gauge> </body> </html>

Demo

Behavior

Smart.Gauge allows two types of scales:

  • integer – the values are integers only
  • floatingPoint – the values are floating point numbers

The type of the scale is determined by the scaleType property which can be set on initialization:

<smart-gauge scale-type="integer"></smart-gauge>

or changed later when the element is ready using javascript:

<script>
     window.onload = function () {
         var gauge = document.querySelector('smart-gauge');
         gauge.scaleType = 'floatingPoint';
     }
 </script>

When the scaleType is set to “floatingPoing”, the user can adjust the precision of the value via the “precisionDigits” property. This property determines how many numbers will appear after the decimal point of the current value. Can be set like every other property:

<smart-gauge precision-digits="2"></smart-gauge>

Demo

Smart.Gauge allows controlling the number significant digits shown on the scale. The significantDigits property determines how the value will be represented. For example, let’s say the user wants to configure the value to contain only 3 significant digits:

<smart-gauge max="100000" significant-digits="3"></smart-gauge>

Demo

Note: significantDigits and precisionDigits can’t be applied at the same time.


Smart.Gauge supports big numbers as well. The wordLength property determines the range of numbers the element can display. This property is applicable only when scaleType is ‘integer’

The available word lengths are:

  • int8 : from –128 to 127
  • uint8 : from 0 to 255
  • int16 : from –32,768 to 32,767
  • uint16 : from 0 to 65,535
  • int32 : from –2,147,483,648 to 2,147,483,647. Default value.
  • uint32 : from 0 to 4,294,967,295
  • int64 : from –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
  • uint64 : from 0 to 18,446,744,073,709,551,615

Here’s how to set it as attribute:

<smart-gauge scale-type="integer" word-length="uint8"></smart-gauge>

Demo


The mechanicalAction property of the element determines when the value will change. This property determines the behavior of the element. Possible values are:

  • switchUntilReleased – changes the value while the user is dragging the thumb. When the thumb is released the value is returned to it’s initial position.
  • switchWhenReleased – changes the value only when the thumb is released. Otherwise the value remains unchaged.
  • switchWhileDragging – changes the value while the user is dragging the thumb and retains the last value when the thumb is released. The default value of the property.
<smart-gauge mechanical-action="switchWhenReleased"></smart-gauge>

Demo


Coerce property determines the value interation. Once enabled the element uses the interval property to determines the next possible selectable value from the scale.

By setting the interval property the user can control the interval between the values. Interval is a property of type number and can be set on initialization or using javascript:

<!DOCTYPE html>
<html lang="en">
<head>
 <link rel="stylesheet" href="../../source/styles/smart.base.css" type="text/css" />
 <script type="text/javascript" src="webcomponents-lite.js"></script>
 <script type="text/javascript" src="../../source/smart.element.js"></script>
 <script type="text/javascript" src="../../source/smart.tank.js"></script>
 <script type="text/javascript" src="../../source/smart.gauge.js"></script>
 <script type="text/javascript" src="../../source/smart.draw.js"></script>
 <script type="text/javascript" src="../../source/smart.numeric.js"></script>
 <script type="text/javascript" src="../../source/smart.math.js"></script>
 <script type="text/javascript" src="../../source/smart.tickintervalhandler.js"></script>
 <script type="text/javascript" src="../../source/smart.numerictextbox.js"></script>
 <script type="text/javascript" src="../../source/smart.button.js"></script>
 <script type="text/javascript" src="../../source/smart.complex.js"></script>
 <script>
     window.onload = function () {
         var gauge = document.querySelector('smart-gauge');
         gauge.interval = 10;
         gauge.coerce = true;
     }
 </script>
</head>
<body>
 <smart-gauge></smart-gauge>
</body>
</html>

If coerce is enabled the thumb will snap to the next value based on the interval.

Keyboard Support

Smart.Gauge implements the following keys:

Key Action
Arrow Up / Arrow Right Increases the value.
Arrow Left / Arrow Down Decreases the value.
Home Sets the value to min.
End Sets the value to max.

Styling

Styling Smart.Gauge is done using normal CSS selectors and variables. Every stylable component of the element has a class name that can be targeted using the dot (“.”) selector following the class name:

Smart.Gauge uses the following CSS variables for styling:

  • –smart-gauge-default-width – the default width of Smart.Gauge.
  • –smart-gauge-default-height – the default height of Smart.Gauge.

Here’s how to apply the variables:

<!DOCTYPE html>
<html lang="en">
<head>
 <link rel="stylesheet" href="../../source/styles/smart.base.css" type="text/css" />
 <script type="text/javascript" src="webcomponents-lite.js"></script>
 <script type="text/javascript" src="../../source/smart.element.js"></script>
 <script type="text/javascript" src="../../source/smart.tank.js"></script>
 <script type="text/javascript" src="../../source/smart.gauge.js"></script>
 <script type="text/javascript" src="../../source/smart.draw.js"></script>
 <script type="text/javascript" src="../../source/smart.numeric.js"></script>
 <script type="text/javascript" src="../../source/smart.math.js"></script>
 <script type="text/javascript" src="../../source/smart.tickintervalhandler.js"></script>
 <script type="text/javascript" src="../../source/smart.numerictextbox.js"></script>
 <script type="text/javascript" src="../../source/smart.button.js"></script>
 <script type="text/javascript" src="../../source/smart.complex.js"></script>
 <style>
     smart-gauge {
         --smart-gauge-default-width: 200px;
         --smart-gauge-default-height: 200px;
     }
 </style>
</head>
<body>
 <smart-gauge></smart-gauge>
</body>
</html>

Demo