Merge pull request #13573 from ArtemDzhereleiko/AD/bug-fix/knob-digital-gauge/decimals
Fixed knob and digital gauge decimals setting
This commit is contained in:
		
						commit
						2b88d934f6
					
				@ -30,7 +30,7 @@ import {
 | 
			
		||||
  getTimewindowConfig,
 | 
			
		||||
  setTimewindowConfig
 | 
			
		||||
} from '@home/components/widget/config/timewindow-config-panel.component';
 | 
			
		||||
import { formatValue, isUndefined } from '@core/utils';
 | 
			
		||||
import { formatValue, isDefined, isUndefined } from '@core/utils';
 | 
			
		||||
import { Component } from '@angular/core';
 | 
			
		||||
import {
 | 
			
		||||
  convertLevelColorsSettingsToColorProcessor,
 | 
			
		||||
@ -115,7 +115,7 @@ export class DigitalSimpleGaugeBasicConfigComponent extends BasicWidgetConfigCom
 | 
			
		||||
      minMaxColor: [settings.minMaxFont?.color, []],
 | 
			
		||||
 | 
			
		||||
      showValue: [settings.showValue, []],
 | 
			
		||||
      decimals: [configData.config.decimals, []],
 | 
			
		||||
      decimals: [isDefined(configData.config.decimals) ? configData.config.decimals : settings.decimals, []],
 | 
			
		||||
      units: [configData.config.units, []],
 | 
			
		||||
      valueFont: [settings.valueFont, []],
 | 
			
		||||
      valueColor: [settings.valueFont?.color, []],
 | 
			
		||||
@ -157,6 +157,9 @@ export class DigitalSimpleGaugeBasicConfigComponent extends BasicWidgetConfigCom
 | 
			
		||||
    this.widgetConfig.config.settings.showValue = config.showValue;
 | 
			
		||||
    this.widgetConfig.config.units = config.units;
 | 
			
		||||
    this.widgetConfig.config.decimals = config.decimals;
 | 
			
		||||
    if (isDefined(this.widgetConfig.config.settings.decimals)) {
 | 
			
		||||
      delete this.widgetConfig.config.settings.decimals;
 | 
			
		||||
    }
 | 
			
		||||
    this.widgetConfig.config.settings.valueFont = config.valueFont;
 | 
			
		||||
    this.widgetConfig.config.settings.valueFont.color = config.valueColor;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -57,6 +57,7 @@ export class KnobComponent extends BasicActionWidgetComponent implements OnInit,
 | 
			
		||||
  maxValue: number;
 | 
			
		||||
  newValue = 0;
 | 
			
		||||
 | 
			
		||||
  private decimals: number;
 | 
			
		||||
  private startDeg = -1;
 | 
			
		||||
  private currentDeg = 0;
 | 
			
		||||
  private rotation = 0;
 | 
			
		||||
@ -143,9 +144,10 @@ export class KnobComponent extends BasicActionWidgetComponent implements OnInit,
 | 
			
		||||
      actionLabel: this.ctx.translate.instant('widgets.slider.on-value-change')};
 | 
			
		||||
    this.valueSetter = this.createValueSetter(valueChangeSettings);
 | 
			
		||||
 | 
			
		||||
    this.decimals = isDefined(this.ctx.decimals) ? this.ctx.decimals : 0;
 | 
			
		||||
    this.valueFormat = ValueFormatProcessor.fromSettings(this.ctx.$injector, {
 | 
			
		||||
      units: this.ctx.units,
 | 
			
		||||
      decimals: this.ctx.decimals,
 | 
			
		||||
      decimals: this.decimals,
 | 
			
		||||
      showZeroDecimals: true
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
@ -299,7 +301,7 @@ export class KnobComponent extends BasicActionWidgetComponent implements OnInit,
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private turn(ratio: number) {
 | 
			
		||||
    this.newValue = Number((this.minValue + (this.maxValue - this.minValue) * ratio).toFixed(this.ctx.decimals));
 | 
			
		||||
    this.newValue = Number((this.minValue + (this.maxValue - this.minValue) * ratio).toFixed(this.decimals));
 | 
			
		||||
    if (this.canvasBar.value !== this.newValue) {
 | 
			
		||||
      this.canvasBar.value = this.newValue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -57,7 +57,7 @@ export class KnobControlWidgetSettingsComponent extends WidgetSettingsComponent
 | 
			
		||||
 | 
			
		||||
  protected prepareInputSettings(settings: WidgetSettings): WidgetSettings {
 | 
			
		||||
    const knobSettings = prepareKnobSettings(deepClone(settings) as any) as WidgetSettings;
 | 
			
		||||
    knobSettings.valueDecimals = this.widgetConfig?.config?.decimals ?? 2;
 | 
			
		||||
    knobSettings.valueDecimals = this.widgetConfig?.config?.decimals;
 | 
			
		||||
    knobSettings.valueUnits = deepClone(this.widgetConfig?.config?.units);
 | 
			
		||||
    return super.prepareInputSettings(knobSettings);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -37,7 +37,7 @@ import {
 | 
			
		||||
  digitalGaugeLayoutTranslations,
 | 
			
		||||
  DigitalGaugeType
 | 
			
		||||
} from '@home/components/widget/lib/digital-gauge.models';
 | 
			
		||||
import { formatValue } from '@core/utils';
 | 
			
		||||
import { formatValue, isDefined } from '@core/utils';
 | 
			
		||||
import {
 | 
			
		||||
  ColorSettings,
 | 
			
		||||
  ColorType,
 | 
			
		||||
@ -247,6 +247,10 @@ export class DigitalGaugeWidgetSettingsComponent extends WidgetSettingsComponent
 | 
			
		||||
    settings.titleFont.color = this.digitalGaugeWidgetSettingsForm.get('titleColor').value;
 | 
			
		||||
    settings.labelFont.color = this.digitalGaugeWidgetSettingsForm.get('labelColor').value;
 | 
			
		||||
 | 
			
		||||
    if (isDefined(settings.decimals)) {
 | 
			
		||||
      delete settings.decimals;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return settings;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -45,7 +45,7 @@ export const knobWidgetDefaultSettings: KnobSettings = {
 | 
			
		||||
    defaultValue: 50,
 | 
			
		||||
    executeRpc: {
 | 
			
		||||
      method: 'getValue',
 | 
			
		||||
      requestTimeout: 500,
 | 
			
		||||
      requestTimeout: 5000,
 | 
			
		||||
      requestPersistent: false,
 | 
			
		||||
      persistentPollingInterval: 5000
 | 
			
		||||
    },
 | 
			
		||||
@ -70,7 +70,7 @@ export const knobWidgetDefaultSettings: KnobSettings = {
 | 
			
		||||
    action: SetValueAction.EXECUTE_RPC,
 | 
			
		||||
    executeRpc: {
 | 
			
		||||
      method: 'setValue',
 | 
			
		||||
      requestTimeout: 500,
 | 
			
		||||
      requestTimeout: 5000,
 | 
			
		||||
      requestPersistent: false,
 | 
			
		||||
      persistentPollingInterval: 5000
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user