Merge pull request #481 from Terny22/master

minor fix in digital-gauge widgets
This commit is contained in:
Igor Kulikov 2017-12-15 15:24:44 +02:00 committed by GitHub
commit d7fb192534
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 3 deletions

View File

@ -155,6 +155,15 @@ export default class CanvasDigitalGauge extends canvasGauges.BaseGauge {
return result; return result;
} }
set timestamp(timestamp) {
this.options.timestamp = timestamp;
this.draw();
}
get timestamp() {
return this.options.timestamp;
}
draw() { draw() {
try { try {
@ -195,7 +204,9 @@ export default class CanvasDigitalGauge extends canvasGauges.BaseGauge {
canvas.elementClone.initialized = true; 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; let context = this.contextValueClone;
// clear the cache // clear the cache
context.clearRect(x, y, w, h); context.clearRect(x, y, w, h);
@ -208,10 +219,13 @@ export default class CanvasDigitalGauge extends canvasGauges.BaseGauge {
if (options.showTimestamp) { if (options.showTimestamp) {
drawDigitalLabel(context, options); drawDigitalLabel(context, options);
this.elementValueClone.renderedTimestamp = this.timestamp;
} }
this.elementValueClone.initialized = true; this.elementValueClone.initialized = true;
this.elementValueClone.renderedValue = this.value; this.elementValueClone.renderedValue = this.value;
valueChanged = true;
} }
var progress = (canvasGauges.drawings.normalizedValue(options).normal - options.minValue) / 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); 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; let context = this.contextProgressClone;
// clear the cache // clear the cache
context.clearRect(x, y, w, h); context.clearRect(x, y, w, h);

View File

@ -197,8 +197,9 @@ export default class TbCanvasDigitalGauge {
if (cellData.data.length > 0) { if (cellData.data.length > 0) {
var tvPair = cellData.data[cellData.data.length - var tvPair = cellData.data[cellData.data.length -
1]; 1];
var timestamp;
if (this.localSettings.showTimestamp) { if (this.localSettings.showTimestamp) {
var timestamp = tvPair[0]; timestamp = tvPair[0];
var filter= this.ctx.$scope.$injector.get('$filter'); var filter= this.ctx.$scope.$injector.get('$filter');
var timestampDisplayValue = filter('date')(timestamp, this.localSettings.timestampFormat); var timestampDisplayValue = filter('date')(timestamp, this.localSettings.timestampFormat);
this.gauge.options.label = timestampDisplayValue; this.gauge.options.label = timestampDisplayValue;
@ -206,6 +207,8 @@ export default class TbCanvasDigitalGauge {
var value = tvPair[1]; var value = tvPair[1];
if(value !== this.gauge.value) { if(value !== this.gauge.value) {
this.gauge.value = value; this.gauge.value = value;
} else if (this.localSettings.showTimestamp && this.gauge.timestamp != timestamp) {
this.gauge.timestamp = timestamp;
} }
} }
} }