Merge pull request #13535 from vvlladd28/bug/unit-convertor/gauge-range-chart
Fixed show value after unit converted in gauges and range chart
This commit is contained in:
		
						commit
						38d52762a0
					
				@ -285,10 +285,10 @@ function getValueDec(ctx: WidgetContext, _settings: AnalogueGaugeSettings): numb
 | 
				
			|||||||
  if (ctx.data && ctx.data[0]) {
 | 
					  if (ctx.data && ctx.data[0]) {
 | 
				
			||||||
    dataKey = ctx.data[0].dataKey;
 | 
					    dataKey = ctx.data[0].dataKey;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if (dataKey && isDefined(dataKey.decimals)) {
 | 
					  if (dataKey && isDefinedAndNotNull(dataKey.decimals)) {
 | 
				
			||||||
    return dataKey.decimals;
 | 
					    return dataKey.decimals;
 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
    return isDefinedAndNotNull(ctx.decimals) ? ctx.decimals : 0;
 | 
					    return ctx.decimals ?? 0;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -300,6 +300,6 @@ function getUnits(ctx: WidgetContext, settings: AnalogueGaugeSettings): TbUnit {
 | 
				
			|||||||
  if (dataKey?.units) {
 | 
					  if (dataKey?.units) {
 | 
				
			||||||
    return dataKey.units;
 | 
					    return dataKey.units;
 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
    return isDefinedAndNotNull(settings.units) ? settings.units : ctx.units;
 | 
					    return settings.units ?? ctx.units;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -32,7 +32,8 @@ import {
 | 
				
			|||||||
  ComponentStyle,
 | 
					  ComponentStyle,
 | 
				
			||||||
  getDataKey,
 | 
					  getDataKey,
 | 
				
			||||||
  overlayStyle,
 | 
					  overlayStyle,
 | 
				
			||||||
  textStyle
 | 
					  textStyle,
 | 
				
			||||||
 | 
					  ValueFormatProcessor
 | 
				
			||||||
} from '@shared/models/widget-settings.models';
 | 
					} from '@shared/models/widget-settings.models';
 | 
				
			||||||
import { isDefinedAndNotNull } from '@core/utils';
 | 
					import { isDefinedAndNotNull } from '@core/utils';
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
@ -113,11 +114,17 @@ export class RangeChartWidgetComponent implements OnInit, OnDestroy, AfterViewIn
 | 
				
			|||||||
    this.units = unitService.getTargetUnitSymbol(units);
 | 
					    this.units = unitService.getTargetUnitSymbol(units);
 | 
				
			||||||
    this.unitConvertor = unitService.geUnitConverter(units);
 | 
					    this.unitConvertor = unitService.geUnitConverter(units);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const valueFormat = ValueFormatProcessor.fromSettings(this.ctx.$injector, {
 | 
				
			||||||
 | 
					      units,
 | 
				
			||||||
 | 
					      decimals: this.decimals,
 | 
				
			||||||
 | 
					      ignoreUnitSymbol: true
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.backgroundStyle$ = backgroundStyle(this.settings.background, this.imagePipe, this.sanitizer);
 | 
					    this.backgroundStyle$ = backgroundStyle(this.settings.background, this.imagePipe, this.sanitizer);
 | 
				
			||||||
    this.overlayStyle = overlayStyle(this.settings.background.overlay);
 | 
					    this.overlayStyle = overlayStyle(this.settings.background.overlay);
 | 
				
			||||||
    this.padding = this.settings.background.overlay.enabled ? undefined : this.settings.padding;
 | 
					    this.padding = this.settings.background.overlay.enabled ? undefined : this.settings.padding;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.rangeItems = toRangeItems(this.settings.rangeColors, this.unitConvertor);
 | 
					    this.rangeItems = toRangeItems(this.settings.rangeColors, valueFormat);
 | 
				
			||||||
    this.visibleRangeItems = this.rangeItems.filter(item => item.visible);
 | 
					    this.visibleRangeItems = this.rangeItems.filter(item => item.visible);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.showLegend = this.settings.showLegend && !!this.rangeItems.length;
 | 
					    this.showLegend = this.settings.showLegend && !!this.rangeItems.length;
 | 
				
			||||||
 | 
				
			|||||||
@ -22,6 +22,7 @@ import {
 | 
				
			|||||||
  Font,
 | 
					  Font,
 | 
				
			||||||
  simpleDateFormat,
 | 
					  simpleDateFormat,
 | 
				
			||||||
  sortedColorRange,
 | 
					  sortedColorRange,
 | 
				
			||||||
 | 
					  ValueFormatProcessor,
 | 
				
			||||||
  ValueSourceType
 | 
					  ValueSourceType
 | 
				
			||||||
} from '@shared/models/widget-settings.models';
 | 
					} from '@shared/models/widget-settings.models';
 | 
				
			||||||
import { LegendPosition } from '@shared/models/widget.models';
 | 
					import { LegendPosition } from '@shared/models/widget.models';
 | 
				
			||||||
@ -291,21 +292,21 @@ export const rangeChartTimeSeriesKeySettings = (settings: RangeChartWidgetSettin
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const toRangeItems = (colorRanges: Array<ColorRange>, convertValue: (x: number) => number): RangeItem[] => {
 | 
					export const toRangeItems = (colorRanges: Array<ColorRange>, valueFormat: ValueFormatProcessor): RangeItem[] => {
 | 
				
			||||||
  const rangeItems: RangeItem[] = [];
 | 
					  const rangeItems: RangeItem[] = [];
 | 
				
			||||||
  let counter = 0;
 | 
					  let counter = 0;
 | 
				
			||||||
  const ranges = sortedColorRange(filterIncludingColorRanges(colorRanges)).filter(r => isNumber(r.from) || isNumber(r.to));
 | 
					  const ranges = sortedColorRange(filterIncludingColorRanges(colorRanges)).filter(r => isNumber(r.from) || isNumber(r.to));
 | 
				
			||||||
  for (let i = 0; i < ranges.length; i++) {
 | 
					  for (let i = 0; i < ranges.length; i++) {
 | 
				
			||||||
    const range = ranges[i];
 | 
					    const range = ranges[i];
 | 
				
			||||||
    let from = range.from;
 | 
					    let from = range.from;
 | 
				
			||||||
    const to = isDefinedAndNotNull(range.to) ? convertValue(range.to) : range.to;
 | 
					    const to = isDefinedAndNotNull(range.to) ? Number(valueFormat.format(range.to)) : range.to;
 | 
				
			||||||
    if (i > 0) {
 | 
					    if (i > 0) {
 | 
				
			||||||
      const prevRange = ranges[i - 1];
 | 
					      const prevRange = ranges[i - 1];
 | 
				
			||||||
      if (isNumber(prevRange.to) && isNumber(from) && from < prevRange.to) {
 | 
					      if (isNumber(prevRange.to) && isNumber(from) && from < prevRange.to) {
 | 
				
			||||||
        from = prevRange.to;
 | 
					        from = prevRange.to;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    from = isDefinedAndNotNull(from) ? convertValue(from) : from;
 | 
					    from = isDefinedAndNotNull(from) ? Number(valueFormat.format(from)) : from;
 | 
				
			||||||
    rangeItems.push(
 | 
					    rangeItems.push(
 | 
				
			||||||
      {
 | 
					      {
 | 
				
			||||||
        index: counter++,
 | 
					        index: counter++,
 | 
				
			||||||
 | 
				
			|||||||
@ -125,6 +125,7 @@ export class TbCanvasDigitalGauge {
 | 
				
			|||||||
    this.barColorProcessor = ColorProcessor.fromSettings(settings.barColor, this.ctx);
 | 
					    this.barColorProcessor = ColorProcessor.fromSettings(settings.barColor, this.ctx);
 | 
				
			||||||
    this.valueFormat = ValueFormatProcessor.fromSettings(this.ctx.$injector, {
 | 
					    this.valueFormat = ValueFormatProcessor.fromSettings(this.ctx.$injector, {
 | 
				
			||||||
      units: this.localSettings.units,
 | 
					      units: this.localSettings.units,
 | 
				
			||||||
 | 
					      decimals: this.localSettings.decimals,
 | 
				
			||||||
      ignoreUnitSymbol: true
 | 
					      ignoreUnitSymbol: true
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user