...
|
...
|
@@ -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,
|
...
|
...
|
|