Commit c4fd3cb5ace8e2a443f79bb831d6b64b40332434

Authored by Vladyslav_Prykhodko
1 parent 4af92b25

Fixed show ticks and start donut angle for gauge; Refactoring

... ... @@ -32,7 +32,7 @@ const tinycolor = tinycolor_;
32 32
33 33 const analogueLinearGaugeSettingsSchemaValue = getAnalogueLinearGaugeSettingsSchema();
34 34
35   -export class TbAnalogueLinearGauge extends TbAnalogueGauge<AnalogueLinearGaugeSettings,LinearGaugeOptions>{
  35 +export class TbAnalogueLinearGauge extends TbAnalogueGauge<AnalogueLinearGaugeSettings, LinearGaugeOptions>{
36 36
37 37 static get settingsSchema(): JsonSettingsSchema {
38 38 return analogueLinearGaugeSettingsSchemaValue;
... ...
... ... @@ -28,7 +28,7 @@ import BaseGauge = CanvasGauges.BaseGauge;
28 28
29 29 const analogueRadialGaugeSettingsSchemaValue = getAnalogueRadialGaugeSettingsSchema();
30 30
31   -export class TbAnalogueRadialGauge extends TbAnalogueGauge<AnalogueRadialGaugeSettings,RadialGaugeOptions>{
  31 +export class TbAnalogueRadialGauge extends TbAnalogueGauge<AnalogueRadialGaugeSettings, RadialGaugeOptions>{
32 32
33 33 static get settingsSchema(): JsonSettingsSchema {
34 34 return analogueRadialGaugeSettingsSchemaValue;
... ...
... ... @@ -18,7 +18,7 @@ import * as CanvasGauges from 'canvas-gauges';
18 18 import { FontStyle, FontWeight } from '@home/components/widget/lib/settings.models';
19 19 import * as tinycolor_ from 'tinycolor2';
20 20 import { ColorFormats } from 'tinycolor2';
21   -import { isDefined, isString, isUndefined, padValue } from '@core/utils';
  21 +import { isDefined, isDefinedAndNotNull, isString, isUndefined, padValue } from '@core/utils';
22 22 import GenericOptions = CanvasGauges.GenericOptions;
23 23 import BaseGauge = CanvasGauges.BaseGauge;
24 24
... ... @@ -220,7 +220,7 @@ export class CanvasDigitalGauge extends BaseGauge {
220 220 public _value: number;
221 221
222 222 constructor(options: CanvasDigitalGaugeOptions) {
223   - options = {...defaultDigitalGaugeOptions,...(options || {})};
  223 + options = {...defaultDigitalGaugeOptions, ...(options || {})};
224 224 super(CanvasDigitalGauge.configure(options));
225 225 this.initValueClone();
226 226 }
... ... @@ -236,10 +236,10 @@ export class CanvasDigitalGauge extends BaseGauge {
236 236 }
237 237
238 238 if (options.gaugeType === 'donut') {
239   - if (!options.donutStartAngle) {
  239 + if (!isDefinedAndNotNull(options.donutStartAngle)) {
240 240 options.donutStartAngle = 1.5 * Math.PI;
241 241 }
242   - if (!options.donutEndAngle) {
  242 + if (!isDefinedAndNotNull(options.donutEndAngle)) {
243 243 options.donutEndAngle = options.donutStartAngle + 2 * Math.PI;
244 244 }
245 245 }
... ... @@ -255,7 +255,7 @@ export class CanvasDigitalGauge extends BaseGauge {
255 255 const levelColor: any = options.levelColors[i];
256 256 if (levelColor !== null) {
257 257 let percentage: number;
258   - if(isColorProperty){
  258 + if (isColorProperty) {
259 259 percentage = inc * i;
260 260 } else {
261 261 percentage = CanvasDigitalGauge.normalizeValue(levelColor.value, options.minValue, options.maxValue);
... ... @@ -280,7 +280,7 @@ export class CanvasDigitalGauge extends BaseGauge {
280 280 options.ticksValue = [];
281 281 for (const tick of options.ticks) {
282 282 if (tick !== null) {
283   - options.ticksValue.push(CanvasDigitalGauge.normalizeValue(tick, options.minValue, options.maxValue))
  283 + options.ticksValue.push(CanvasDigitalGauge.normalizeValue(tick, options.minValue, options.maxValue));
284 284 }
285 285 }
286 286
... ... @@ -294,7 +294,7 @@ export class CanvasDigitalGauge extends BaseGauge {
294 294 return options;
295 295 }
296 296
297   - static normalizeValue (value: number, min: number, max: number): number {
  297 + static normalizeValue(value: number, min: number, max: number): number {
298 298 const normalValue = (value - min) / (max - min);
299 299 if (normalValue <= 0) {
300 300 return 0;
... ... @@ -539,8 +539,8 @@ function barDimensions(context: DigitalGaugeCanvasRenderingContext2D,
539 539 titleOffset += bd.fontSizeFactor * 2;
540 540 bd.titleY = bd.baseY + titleOffset;
541 541 titleOffset += bd.fontSizeFactor * 2;
542   - bd.Cy += titleOffset/2;
543   - bd.Ro -= titleOffset/2;
  542 + bd.Cy += titleOffset / 2;
  543 + bd.Ro -= titleOffset / 2;
544 544 }
545 545 bd.Ri = bd.Ro - bd.width / 6.666666666666667 * gws * 1.2;
546 546 bd.Cx = bd.baseX + bd.width / 2;
... ... @@ -575,8 +575,8 @@ function barDimensions(context: DigitalGaugeCanvasRenderingContext2D,
575 575 const valueHeight = determineFontHeight(options, 'Value', bd.fontSizeFactor).height;
576 576 const labelHeight = determineFontHeight(options, 'Label', bd.fontSizeFactor).height;
577 577 const total = valueHeight + labelHeight;
578   - bd.labelY = bd.Cy + total/2;
579   - bd.valueY = bd.Cy - total/2 + valueHeight/2;
  578 + bd.labelY = bd.Cy + total / 2;
  579 + bd.valueY = bd.Cy - total / 2 + valueHeight / 2;
580 580 } else {
581 581 bd.valueY = bd.Cy;
582 582 }
... ... @@ -586,8 +586,8 @@ function barDimensions(context: DigitalGaugeCanvasRenderingContext2D,
586 586 bd.labelY = bd.Cy + (8 + options.fontLabelSize) * bd.fontSizeFactor;
587 587 bd.minY = bd.maxY = bd.labelY;
588 588 if (options.roundedLineCap) {
589   - bd.minY += bd.strokeWidth/2;
590   - bd.maxY += bd.strokeWidth/2;
  589 + bd.minY += bd.strokeWidth / 2;
  590 + bd.maxY += bd.strokeWidth / 2;
591 591 }
592 592 bd.minX = bd.Cx - bd.Rm;
593 593 bd.maxX = bd.Cx + bd.Rm;
... ... @@ -604,15 +604,15 @@ function barDimensions(context: DigitalGaugeCanvasRenderingContext2D,
604 604
605 605 if (options.hideMinMax && options.label === '') {
606 606 bd.labelY = bd.barBottom;
607   - bd.barLeft = bd.origBaseX + options.fontMinMaxSize/3 * bd.fontSizeFactor;
608   - bd.barRight = bd.origBaseX + w + /*bd.width*/ - options.fontMinMaxSize/3 * bd.fontSizeFactor;
  607 + bd.barLeft = bd.origBaseX + options.fontMinMaxSize / 3 * bd.fontSizeFactor;
  608 + bd.barRight = bd.origBaseX + w + /*bd.width*/ -options.fontMinMaxSize / 3 * bd.fontSizeFactor;
609 609 } else {
610 610 context.font = Drawings.font(options, 'MinMax', bd.fontSizeFactor);
611   - const minTextWidth = context.measureText(options.minValue+'').width;
612   - const maxTextWidth = context.measureText(options.maxValue+'').width;
  611 + const minTextWidth = context.measureText(options.minValue + '').width;
  612 + const maxTextWidth = context.measureText(options.maxValue + '').width;
613 613 const maxW = Math.max(minTextWidth, maxTextWidth);
614   - bd.minX = bd.origBaseX + maxW/2 + options.fontMinMaxSize/3 * bd.fontSizeFactor;
615   - bd.maxX = bd.origBaseX + w + /*bd.width*/ - maxW/2 - options.fontMinMaxSize/3 * bd.fontSizeFactor;
  614 + bd.minX = bd.origBaseX + maxW / 2 + options.fontMinMaxSize / 3 * bd.fontSizeFactor;
  615 + bd.maxX = bd.origBaseX + w + /*bd.width*/ -maxW / 2 - options.fontMinMaxSize / 3 * bd.fontSizeFactor;
616 616 bd.barLeft = bd.minX;
617 617 bd.barRight = bd.maxX;
618 618 bd.labelY = bd.barBottom + (8 + options.fontLabelSize) * bd.fontSizeFactor;
... ... @@ -632,7 +632,7 @@ function barDimensions(context: DigitalGaugeCanvasRenderingContext2D,
632 632 bd.barBottom = bd.labelY - (8 + options.fontLabelSize) * bd.fontSizeFactor;
633 633 }
634 634 bd.minX = bd.maxX =
635   - bd.baseX + bd.width/2 + bd.strokeWidth/2 + options.fontMinMaxSize/3 * bd.fontSizeFactor;
  635 + bd.baseX + bd.width / 2 + bd.strokeWidth / 2 + options.fontMinMaxSize / 3 * bd.fontSizeFactor;
636 636 bd.minY = bd.barBottom;
637 637 bd.maxY = bd.barTop;
638 638 bd.fontMinMaxBaseline = 'middle';
... ... @@ -658,13 +658,13 @@ function barDimensions(context: DigitalGaugeCanvasRenderingContext2D,
658 658 // tslint:disable-next-line:no-bitwise
659 659 dashCount = (dashCount - 1) | 1;
660 660 }
661   - bd.dashLength = Math.ceil(circumference/dashCount);
  661 + bd.dashLength = Math.ceil(circumference / dashCount);
662 662 }
663 663
664 664 return bd;
665 665 }
666 666
667   -function determineFontHeight (options: CanvasDigitalGaugeOptions, target: string, baseSize: number): FontHeightInfo {
  667 +function determineFontHeight(options: CanvasDigitalGaugeOptions, target: string, baseSize: number): FontHeightInfo {
668 668 const fontStyleStr = 'font-style:' + options['font' + target + 'Style'] + ';font-weight:' +
669 669 options['font' + target + 'Weight'] + ';font-size:' +
670 670 options['font' + target + 'Size'] * baseSize + 'px;font-family:' +
... ... @@ -688,9 +688,9 @@ function determineFontHeight (options: CanvasDigitalGaugeOptions, target: string
688 688
689 689 try {
690 690 result = {};
691   - block.css({ verticalAlign: 'baseline' });
  691 + block.css({verticalAlign: 'baseline'});
692 692 result.ascent = block.offset().top - text.offset().top;
693   - block.css({ verticalAlign: 'bottom' });
  693 + block.css({verticalAlign: 'bottom'});
694 694 result.height = block.offset().top - text.offset().top;
695 695 result.descent = result.height - result.ascent;
696 696 } finally {
... ... @@ -720,15 +720,15 @@ function drawBackground(context: DigitalGaugeCanvasRenderingContext2D, options:
720 720 context.stroke();
721 721 } else if (options.gaugeType === 'arc') {
722 722 context.arc(context.barDimensions.Cx, context.barDimensions.Cy,
723   - context.barDimensions.Rm, Math.PI, 2*Math.PI);
  723 + context.barDimensions.Rm, Math.PI, 2 * Math.PI);
724 724 context.stroke();
725 725 } else if (options.gaugeType === 'horizontalBar') {
726   - context.moveTo(barLeft,barTop + strokeWidth/2);
727   - context.lineTo(barRight,barTop + strokeWidth/2);
  726 + context.moveTo(barLeft, barTop + strokeWidth / 2);
  727 + context.lineTo(barRight, barTop + strokeWidth / 2);
728 728 context.stroke();
729 729 } else if (options.gaugeType === 'verticalBar') {
730   - context.moveTo(baseX + width/2, barBottom);
731   - context.lineTo(baseX + width/2, barTop);
  730 + context.moveTo(baseX + width / 2, barBottom);
  731 + context.lineTo(baseX + width / 2, barTop);
732 732 context.stroke();
733 733 }
734 734 }
... ... @@ -740,7 +740,9 @@ function drawText(context: DigitalGaugeCanvasRenderingContext2D, options: Canvas
740 740 }
741 741
742 742 function drawDigitalTitle(context: DigitalGaugeCanvasRenderingContext2D, options: CanvasDigitalGaugeOptions) {
743   - if (!options.title || typeof options.title !== 'string') return;
  743 + if (!options.title || typeof options.title !== 'string') {
  744 + return;
  745 + }
744 746
745 747 const {titleY, width, baseX, fontSizeFactor} =
746 748 context.barDimensions;
... ... @@ -756,7 +758,9 @@ function drawDigitalTitle(context: DigitalGaugeCanvasRenderingContext2D, options
756 758 }
757 759
758 760 function drawDigitalLabel(context: DigitalGaugeCanvasRenderingContext2D, options: CanvasDigitalGaugeOptions) {
759   - if (!options.label || options.label === '') return;
  761 + if (!options.label || options.label === '') {
  762 + return;
  763 + }
760 764
761 765 const {labelY, baseX, width, fontSizeFactor} =
762 766 context.barDimensions;
... ... @@ -772,7 +776,9 @@ function drawDigitalLabel(context: DigitalGaugeCanvasRenderingContext2D, options
772 776 }
773 777
774 778 function drawDigitalMinMax(context: DigitalGaugeCanvasRenderingContext2D, options: CanvasDigitalGaugeOptions) {
775   - if (options.hideMinMax || options.gaugeType === 'donut') return;
  779 + if (options.hideMinMax || options.gaugeType === 'donut') {
  780 + return;
  781 + }
776 782
777 783 const {minY, maxY, minX, maxX, fontSizeFactor, fontMinMaxAlign, fontMinMaxBaseline} =
778 784 context.barDimensions;
... ... @@ -782,12 +788,14 @@ function drawDigitalMinMax(context: DigitalGaugeCanvasRenderingContext2D, option
782 788 context.textBaseline = fontMinMaxBaseline;
783 789 context.font = Drawings.font(options, 'MinMax', fontSizeFactor);
784 790 context.lineWidth = 0;
785   - drawText(context, options, 'MinMax', options.minValue+'', minX, minY);
786   - drawText(context, options, 'MinMax', options.maxValue+'', maxX, maxY);
  791 + drawText(context, options, 'MinMax', options.minValue + '', minX, minY);
  792 + drawText(context, options, 'MinMax', options.maxValue + '', maxX, maxY);
787 793 }
788 794
789 795 function drawDigitalValue(context: DigitalGaugeCanvasRenderingContext2D, options: CanvasDigitalGaugeOptions, value: any) {
790   - if (options.hideValue) return;
  796 + if (options.hideValue) {
  797 + return;
  798 + }
791 799
792 800 const {valueY, baseX, width, fontSizeFactor, fontValueBaseline} =
793 801 context.barDimensions;
... ... @@ -837,16 +845,16 @@ function drawArcGlow(context: DigitalGaugeCanvasRenderingContext2D,
837 845 context.setLineDash([]);
838 846 const strokeWidth = Ro - Ri;
839 847 const blur = 0.55;
840   - const edge = strokeWidth*blur;
841   - context.lineWidth = strokeWidth+edge;
842   - const stop = blur/(2*blur+2);
843   - const glowGradient = context.createRadialGradient(Cx,Cy,Ri-edge/2,Cx,Cy,Ro+edge/2);
  848 + const edge = strokeWidth * blur;
  849 + context.lineWidth = strokeWidth + edge;
  850 + const stop = blur / (2 * blur + 2);
  851 + const glowGradient = context.createRadialGradient(Cx, Cy, Ri - edge / 2, Cx, Cy, Ro + edge / 2);
844 852 const color1 = tinycolor(color).setAlpha(0.5).toRgbString();
845 853 const color2 = tinycolor(color).setAlpha(0).toRgbString();
846   - glowGradient.addColorStop(0,color2);
847   - glowGradient.addColorStop(stop,color1);
848   - glowGradient.addColorStop(1.0-stop,color1);
849   - glowGradient.addColorStop(1,color2);
  854 + glowGradient.addColorStop(0, color2);
  855 + glowGradient.addColorStop(stop, color1);
  856 + glowGradient.addColorStop(1.0 - stop, color1);
  857 + glowGradient.addColorStop(1, color2);
850 858 context.strokeStyle = glowGradient;
851 859 context.beginPath();
852 860 const e = 0.01 * Math.PI;
... ... @@ -863,21 +871,21 @@ function drawBarGlow(context: DigitalGaugeCanvasRenderingContext2D, startX: numb
863 871 endX: number, endY: number, color: string, strokeWidth: number, isVertical: boolean) {
864 872 context.setLineDash([]);
865 873 const blur = 0.55;
866   - const edge = strokeWidth*blur;
867   - context.lineWidth = strokeWidth+edge;
868   - const stop = blur/(2*blur+2);
869   - const gradientStartX = isVertical ? startX - context.lineWidth/2 : 0;
870   - const gradientStartY = isVertical ? 0 : startY - context.lineWidth/2;
871   - const gradientStopX = isVertical ? startX + context.lineWidth/2 : 0;
872   - const gradientStopY = isVertical ? 0 : startY + context.lineWidth/2;
873   -
874   - const glowGradient = context.createLinearGradient(gradientStartX,gradientStartY,gradientStopX,gradientStopY);
  874 + const edge = strokeWidth * blur;
  875 + context.lineWidth = strokeWidth + edge;
  876 + const stop = blur / (2 * blur + 2);
  877 + const gradientStartX = isVertical ? startX - context.lineWidth / 2 : 0;
  878 + const gradientStartY = isVertical ? 0 : startY - context.lineWidth / 2;
  879 + const gradientStopX = isVertical ? startX + context.lineWidth / 2 : 0;
  880 + const gradientStopY = isVertical ? 0 : startY + context.lineWidth / 2;
  881 +
  882 + const glowGradient = context.createLinearGradient(gradientStartX, gradientStartY, gradientStopX, gradientStopY);
875 883 const color1 = tinycolor(color).setAlpha(0.5).toRgbString();
876 884 const color2 = tinycolor(color).setAlpha(0).toRgbString();
877   - glowGradient.addColorStop(0,color2);
878   - glowGradient.addColorStop(stop,color1);
879   - glowGradient.addColorStop(1.0-stop,color1);
880   - glowGradient.addColorStop(1,color2);
  885 + glowGradient.addColorStop(0, color2);
  886 + glowGradient.addColorStop(stop, color1);
  887 + glowGradient.addColorStop(1.0 - stop, color1);
  888 + glowGradient.addColorStop(1, color2);
881 889 context.strokeStyle = glowGradient;
882 890 const dx = isVertical ? 0 : 0.05 * context.lineWidth;
883 891 const dy = isVertical ? 0.05 * context.lineWidth : 0;
... ... @@ -984,12 +992,12 @@ function drawProgress(context: DigitalGaugeCanvasRenderingContext2D,
984 992 context.strokeStyle = neonColor;
985 993 }
986 994 context.beginPath();
987   - context.moveTo(barLeft,barTop + strokeWidth/2);
988   - context.lineTo(barLeft + (barRight-barLeft)*progress, barTop + strokeWidth/2);
  995 + context.moveTo(barLeft, barTop + strokeWidth / 2);
  996 + context.lineTo(barLeft + (barRight - barLeft) * progress, barTop + strokeWidth / 2);
989 997 context.stroke();
990 998 if (options.neonGlowBrightness && !options.isMobile) {
991   - drawBarGlow(context, barLeft, barTop + strokeWidth/2,
992   - barLeft + (barRight-barLeft)*progress, barTop + strokeWidth/2,
  999 + drawBarGlow(context, barLeft, barTop + strokeWidth / 2,
  1000 + barLeft + (barRight - barLeft) * progress, barTop + strokeWidth / 2,
993 1001 neonColor, strokeWidth, false);
994 1002 }
995 1003 drawTickBar(context, options.ticksValue, barLeft, barTop, barRight - barLeft, strokeWidth,
... ... @@ -999,12 +1007,12 @@ function drawProgress(context: DigitalGaugeCanvasRenderingContext2D,
999 1007 context.strokeStyle = neonColor;
1000 1008 }
1001 1009 context.beginPath();
1002   - context.moveTo(baseX + width/2, barBottom);
1003   - context.lineTo(baseX + width/2, barBottom - (barBottom-barTop)*progress);
  1010 + context.moveTo(baseX + width / 2, barBottom);
  1011 + context.lineTo(baseX + width / 2, barBottom - (barBottom - barTop) * progress);
1004 1012 context.stroke();
1005 1013 if (options.neonGlowBrightness && !options.isMobile) {
1006   - drawBarGlow(context, baseX + width/2, barBottom,
1007   - baseX + width/2, barBottom - (barBottom-barTop)*progress,
  1014 + drawBarGlow(context, baseX + width / 2, barBottom,
  1015 + baseX + width / 2, barBottom - (barBottom - barTop) * progress,
1008 1016 neonColor, strokeWidth, true);
1009 1017 }
1010 1018 drawTickBar(context, options.ticksValue, baseX + width / 2, barTop, barTop - barBottom, strokeWidth,
... ...
... ... @@ -694,7 +694,7 @@ export const digitalGaugeSettingsSchema: JsonSettingsSchema = {
694 694 },
695 695 {
696 696 value: '700',
697   - label: '800'
  697 + label: '700'
698 698 },
699 699 {
700 700 value: '800',
... ... @@ -783,7 +783,7 @@ export const digitalGaugeSettingsSchema: JsonSettingsSchema = {
783 783 },
784 784 {
785 785 value: '700',
786   - label: '800'
  786 + label: '700'
787 787 },
788 788 {
789 789 value: '800',
... ... @@ -872,7 +872,7 @@ export const digitalGaugeSettingsSchema: JsonSettingsSchema = {
872 872 },
873 873 {
874 874 value: '700',
875   - label: '800'
  875 + label: '700'
876 876 },
877 877 {
878 878 value: '800',
... ... @@ -961,7 +961,7 @@ export const digitalGaugeSettingsSchema: JsonSettingsSchema = {
961 961 },
962 962 {
963 963 value: '700',
964   - label: '800'
  964 + label: '700'
965 965 },
966 966 {
967 967 value: '800',
... ...
... ... @@ -25,7 +25,7 @@ import {
25 25 FixedLevelColors
26 26 } from '@home/components/widget/lib/digital-gauge.models';
27 27 import * as tinycolor_ from 'tinycolor2';
28   -import { isDefined } from '@core/utils';
  28 +import { isDefined, isDefinedAndNotNull } from '@core/utils';
29 29 import { prepareFontSettings } from '@home/components/widget/lib/settings.models';
30 30 import { CanvasDigitalGauge, CanvasDigitalGaugeOptions } from '@home/components/widget/lib/canvas-digital-gauge';
31 31 import { DatePipe } from '@angular/common';
... ... @@ -53,7 +53,7 @@ export class TbCanvasDigitalGauge {
53 53 }
54 54
55 55 constructor(protected ctx: WidgetContext, canvasId: string) {
56   - const gaugeElement = $('#'+canvasId, ctx.$container)[0];
  56 + const gaugeElement = $('#' + canvasId, ctx.$container)[0];
57 57 const settings: DigitalGaugeSettings = ctx.settings;
58 58
59 59 this.localSettings = {};
... ... @@ -80,7 +80,7 @@ export class TbCanvasDigitalGauge {
80 80
81 81 this.localSettings.useFixedLevelColor = settings.useFixedLevelColor || false;
82 82 if (!settings.useFixedLevelColor) {
83   - if (!settings.levelColors || settings.levelColors.length <= 0) {
  83 + if (!settings.levelColors || settings.levelColors.length === 0) {
84 84 this.localSettings.levelColors = [keyColor];
85 85 } else {
86 86 this.localSettings.levelColors = settings.levelColors.slice();
... ... @@ -97,14 +97,15 @@ export class TbCanvasDigitalGauge {
97 97 this.localSettings.colorTicks = settings.colorTicks || '#666';
98 98
99 99 this.localSettings.decimals = isDefined(dataKey.decimals) ? dataKey.decimals :
100   - ((isDefined(settings.decimals) && settings.decimals !== null)
101   - ? settings.decimals : ctx.decimals);
  100 + (isDefinedAndNotNull(settings.decimals) ? settings.decimals : ctx.decimals);
102 101
103 102 this.localSettings.units = dataKey.units && dataKey.units.length ? dataKey.units :
104 103 (isDefined(settings.units) && settings.units.length > 0 ? settings.units : ctx.units);
105 104
106 105 this.localSettings.hideValue = settings.showValue !== true;
107 106 this.localSettings.hideMinMax = settings.showMinMax !== true;
  107 + this.localSettings.donutStartAngle = isDefinedAndNotNull(settings.donutStartAngle) ?
  108 + -TbCanvasDigitalGauge.toRadians(settings.donutStartAngle) : null;
108 109
109 110 this.localSettings.title = ((settings.showTitle === true) ?
110 111 (settings.title && settings.title.length > 0 ?
... ... @@ -191,14 +192,15 @@ export class TbCanvasDigitalGauge {
191 192 hideValue: this.localSettings.hideValue,
192 193 hideMinMax: this.localSettings.hideMinMax,
193 194
  195 + donutStartAngle: this.localSettings.donutStartAngle,
  196 +
194 197 valueDec: this.localSettings.decimals,
195 198
196 199 neonGlowBrightness: this.localSettings.neonGlowBrightness,
197 200
198 201 // animations
199 202 animation: settings.animation !== false && !ctx.isMobile,
200   - animationDuration: (isDefined(settings.animationDuration) && settings.animationDuration !== null)
201   - ? settings.animationDuration : 500,
  203 + animationDuration: isDefinedAndNotNull(settings.animationDuration) ? settings.animationDuration : 500,
202 204 animationRule: settings.animationRule || 'linear',
203 205
204 206 isMobile: ctx.isMobile
... ... @@ -241,7 +243,7 @@ export class TbCanvasDigitalGauge {
241 243 if (findDataKey) {
242 244 findDataKey.settings.push(settings);
243 245 } else {
244   - datasource.dataKeys.push(dataKey)
  246 + datasource.dataKeys.push(dataKey);
245 247 }
246 248 } else {
247 249 const datasourceAttribute: Datasource = {
... ... @@ -257,17 +259,23 @@ export class TbCanvasDigitalGauge {
257 259 return datasources;
258 260 }
259 261
  262 + private static toRadians(angle: number): number {
  263 + return angle * (Math.PI / 180);
  264 + }
  265 +
260 266 init() {
261   - if (this.localSettings.useFixedLevelColor) {
262   - if (this.localSettings.fixedLevelColors && this.localSettings.fixedLevelColors.length > 0) {
263   - this.localSettings.levelColors = this.settingLevelColorsSubscribe(this.localSettings.fixedLevelColors);
264   - }
  267 + let updateSetting = false;
265 268
266   - if (this.localSettings.showTicks) {
267   - if (this.localSettings.ticksValue && this.localSettings.ticksValue.length) {
268   - this.localSettings.ticks = this.settingTicksSubscribe(this.localSettings.ticksValue);
269   - }
270   - }
  269 + if (this.localSettings.useFixedLevelColor && this.localSettings.fixedLevelColors?.length > 0) {
  270 + this.localSettings.levelColors = this.settingLevelColorsSubscribe(this.localSettings.fixedLevelColors);
  271 + updateSetting = true;
  272 + }
  273 + if (this.localSettings.showTicks && this.localSettings.ticksValue?.length) {
  274 + this.localSettings.ticks = this.settingTicksSubscribe(this.localSettings.ticksValue);
  275 + updateSetting = true;
  276 + }
  277 +
  278 + if (updateSetting) {
271 279 this.updateSetting();
272 280 }
273 281 }
... ... @@ -281,7 +289,7 @@ export class TbCanvasDigitalGauge {
281 289 predefineLevelColors.push({
282 290 value: levelSetting.value,
283 291 color
284   - })
  292 + });
285 293 } else if (levelSetting.entityAlias && levelSetting.attribute) {
286 294 try {
287 295 levelColorsDatasource = TbCanvasDigitalGauge.generateDatasource(this.ctx, levelColorsDatasource,
... ... @@ -293,7 +301,7 @@ export class TbCanvasDigitalGauge {
293 301 }
294 302 }
295 303
296   - for(const levelColor of options){
  304 + for (const levelColor of options) {
297 305 if (levelColor.from) {
298 306 setLevelColor.call(this, levelColor.from, levelColor.color);
299 307 }
... ... @@ -313,9 +321,9 @@ export class TbCanvasDigitalGauge {
313 321 let ticksDatasource: Datasource[] = [];
314 322 const predefineTicks: number[] = [];
315 323
316   - for(const tick of options){
  324 + for (const tick of options) {
317 325 if (tick.valueSource === 'predefinedValue' && isFinite(tick.value)) {
318   - predefineTicks.push(tick.value)
  326 + predefineTicks.push(tick.value);
319 327 } else if (tick.entityAlias && tick.attribute) {
320 328 try {
321 329 ticksDatasource = TbCanvasDigitalGauge
... ... @@ -398,7 +406,7 @@ export class TbCanvasDigitalGauge {
398 406 filter.transform(timestamp, this.localSettings.timestampFormat);
399 407 }
400 408 const value = tvPair[1];
401   - if(value !== this.gauge.value) {
  409 + if (value !== this.gauge.value) {
402 410 if (!this.gauge.options.animation) {
403 411 this.gauge._value = value;
404 412 }
... ...