|
|
@ -4,13 +4,14 @@ |
|
|
import * as CanvasGauges from 'canvas-gauges'; |
|
|
import * as CanvasGauges from 'canvas-gauges'; |
|
|
import { FontSettings, getFontFamily } from '@home/components/widget/lib/settings.models'; |
|
|
import { FontSettings, getFontFamily } from '@home/components/widget/lib/settings.models'; |
|
|
import { WidgetContext } from '@home/models/widget-component.models'; |
|
|
import { WidgetContext } from '@home/models/widget-component.models'; |
|
|
import { isDefined, isDefinedAndNotNull } from '@core/utils'; |
|
|
import { isDefined, isDefinedAndNotNull, isNumeric } from '@core/utils'; |
|
|
import tinycolor from 'tinycolor2'; |
|
|
import tinycolor from 'tinycolor2'; |
|
|
import { TbUnit } from '@shared/models/unit.models'; |
|
|
import { TbUnit } from '@shared/models/unit.models'; |
|
|
import { ValueFormatProcessor } from '@shared/models/widget-settings.models'; |
|
|
import { ValueFormatProcessor } from '@shared/models/widget-settings.models'; |
|
|
import { UnitService } from '@core/services/unit.service'; |
|
|
import { UnitService } from '@core/services/unit.service'; |
|
|
import { DataKey } from '@shared/models/widget.models'; |
|
|
import { DataKey } from '@shared/models/widget.models'; |
|
|
import { CustomTranslatePipe } from '@shared/pipe/custom-translate.pipe'; |
|
|
import { CustomTranslatePipe } from '@shared/pipe/custom-translate.pipe'; |
|
|
|
|
|
import { NOT_SUPPORTED } from '@shared/models/telemetry/telemetry.models'; |
|
|
import Highlight = CanvasGauges.Highlight; |
|
|
import Highlight = CanvasGauges.Highlight; |
|
|
import BaseGauge = CanvasGauges.BaseGauge; |
|
|
import BaseGauge = CanvasGauges.BaseGauge; |
|
|
import GenericOptions = CanvasGauges.GenericOptions; |
|
|
import GenericOptions = CanvasGauges.GenericOptions; |
|
|
@ -61,6 +62,9 @@ interface BaseGaugeModel extends BaseGauge { |
|
|
_value?: number; |
|
|
_value?: number; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export const getGaugeValueText = (value: any): string => |
|
|
|
|
|
!isDefinedAndNotNull(value) || value === '' ? 'N/A' : !isNumeric(value) ? NOT_SUPPORTED : ''; |
|
|
|
|
|
|
|
|
export abstract class TbBaseGauge<S, O extends GenericOptions> { |
|
|
export abstract class TbBaseGauge<S, O extends GenericOptions> { |
|
|
|
|
|
|
|
|
private gauge: BaseGaugeModel; |
|
|
private gauge: BaseGaugeModel; |
|
|
@ -80,20 +84,23 @@ export abstract class TbBaseGauge<S, O extends GenericOptions> { |
|
|
update() { |
|
|
update() { |
|
|
if (this.ctx.data.length > 0) { |
|
|
if (this.ctx.data.length > 0) { |
|
|
const cellData = this.ctx.data[0]; |
|
|
const cellData = this.ctx.data[0]; |
|
|
if (cellData.data.length > 0) { |
|
|
const origValue = cellData.data.length > 0 ? cellData.data[cellData.data.length - 1][1] : null; |
|
|
const tvPair = cellData.data[cellData.data.length - 1]; |
|
|
let value = parseFloat(origValue); |
|
|
let value = parseFloat(tvPair[1]); |
|
|
if (this.formatValue) { |
|
|
if (this.formatValue) { |
|
|
value = parseFloat(this.formatValue.format(value)); |
|
|
value = parseFloat(this.formatValue.format(value)); |
|
|
} |
|
|
} |
|
|
const valueText = getGaugeValueText(origValue); |
|
|
if (value !== this.gauge.value) { |
|
|
if (this.gauge.options.valueText !== valueText) { |
|
|
if (!this.gauge.options.animation) { |
|
|
this.gauge.update({valueText} as GenericOptions); |
|
|
this.gauge._value = value; |
|
|
} |
|
|
} else { |
|
|
const gaugeValue = valueText ? this.gauge.options.minValue : value; |
|
|
delete this.gauge._value; |
|
|
if (!isNaN(gaugeValue) && gaugeValue !== this.gauge.value) { |
|
|
} |
|
|
if (!this.gauge.options.animation) { |
|
|
this.gauge.value = value; |
|
|
this.gauge._value = gaugeValue; |
|
|
|
|
|
} else { |
|
|
|
|
|
delete this.gauge._value; |
|
|
} |
|
|
} |
|
|
|
|
|
this.gauge.value = gaugeValue; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|