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