thingsboard-aplcache

Merge pull request #481 from Terny22/master minor fix in

12/15/2017 11:24:44 AM

Details

diff --git a/ui/src/app/widget/lib/canvas-digital-gauge.js b/ui/src/app/widget/lib/canvas-digital-gauge.js
index cf0f682..231fb6f 100644
--- a/ui/src/app/widget/lib/canvas-digital-gauge.js
+++ b/ui/src/app/widget/lib/canvas-digital-gauge.js
@@ -197,8 +197,9 @@ export default class TbCanvasDigitalGauge {
             if (cellData.data.length > 0) {
                 var tvPair = cellData.data[cellData.data.length -
                 1];
+                var timestamp;
                 if (this.localSettings.showTimestamp) {
-                    var timestamp = tvPair[0];
+                    timestamp = tvPair[0];
                     var filter= this.ctx.$scope.$injector.get('$filter');
                     var timestampDisplayValue = filter('date')(timestamp, this.localSettings.timestampFormat);
                     this.gauge.options.label = timestampDisplayValue;
@@ -206,6 +207,8 @@ export default class TbCanvasDigitalGauge {
                 var value = tvPair[1];
                 if(value !== this.gauge.value) {
                     this.gauge.value = value;
+                } else if (this.localSettings.showTimestamp && this.gauge.timestamp != timestamp) {
+                    this.gauge.timestamp = timestamp;
                 }
             }
         }
diff --git a/ui/src/app/widget/lib/CanvasDigitalGauge.js b/ui/src/app/widget/lib/CanvasDigitalGauge.js
index a1cfca2..bd3ff98 100644
--- a/ui/src/app/widget/lib/CanvasDigitalGauge.js
+++ b/ui/src/app/widget/lib/CanvasDigitalGauge.js
@@ -155,6 +155,15 @@ export default class CanvasDigitalGauge extends canvasGauges.BaseGauge {
         return result;
     }
 
+    set timestamp(timestamp) {
+        this.options.timestamp = timestamp;
+        this.draw();
+    }
+
+    get timestamp() {
+        return this.options.timestamp;
+    }
+
     draw() {
         try {
 
@@ -195,7 +204,9 @@ export default class CanvasDigitalGauge extends canvasGauges.BaseGauge {
                 canvas.elementClone.initialized = true;
             }
 
-            if (!this.elementValueClone.initialized || this.elementValueClone.renderedValue !== this.value) {
+            var valueChanged = false;
+
+            if (!this.elementValueClone.initialized || this.elementValueClone.renderedValue !== this.value || (options.showTimestamp && this.elementValueClone.renderedTimestamp !== this.timestamp)) {
                 let context = this.contextValueClone;
                 // clear the cache
                 context.clearRect(x, y, w, h);
@@ -208,10 +219,13 @@ export default class CanvasDigitalGauge extends canvasGauges.BaseGauge {
 
                 if (options.showTimestamp) {
                     drawDigitalLabel(context, options);
+                    this.elementValueClone.renderedTimestamp = this.timestamp;
                 }
 
                 this.elementValueClone.initialized = true;
                 this.elementValueClone.renderedValue = this.value;
+
+                valueChanged = true;
             }
 
             var progress = (canvasGauges.drawings.normalizedValue(options).normal - options.minValue) /
@@ -219,7 +233,7 @@ export default class CanvasDigitalGauge extends canvasGauges.BaseGauge {
 
             var fixedProgress = progress.toFixed(3);
 
-            if (!this.elementProgressClone.initialized || this.elementProgressClone.renderedProgress !== fixedProgress) {
+            if (!this.elementProgressClone.initialized || this.elementProgressClone.renderedProgress !== fixedProgress || valueChanged) {
                 let context = this.contextProgressClone;
                 // clear the cache
                 context.clearRect(x, y, w, h);