From bbea48215e33fb4aadf593ecfbe2e02c1f0c2493 Mon Sep 17 00:00:00 2001 From: ArtemDzhereleiko Date: Fri, 17 Sep 2021 17:07:58 +0300 Subject: [PATCH] Changed logic for processing boundary values and change labels --- .../widget/lib/canvas-digital-gauge.ts | 17 +++++++++-------- .../widget/lib/digital-gauge.models.ts | 15 +++++++++------ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/canvas-digital-gauge.ts b/ui-ngx/src/app/modules/home/components/widget/lib/canvas-digital-gauge.ts index 898ceb3b81..2665d6a864 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/canvas-digital-gauge.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/canvas-digital-gauge.ts @@ -466,9 +466,9 @@ export class CanvasDigitalGauge extends BaseGauge { const progress = (Drawings.normalizedValue(options).normal - options.minValue) / (options.maxValue - options.minValue); if (options.neonGlowBrightness) { - color = getProgressColor(progress, options.neonColorsRange); + color = getProgressColor(progress, options.neonColorsRange, options.neonColorValue); } else { - color = getProgressColor(progress, options.colorsRange); + color = getProgressColor(progress, options.colorsRange, options.neonColorValue); } } return color; @@ -814,14 +814,14 @@ function drawDigitalValue(context: DigitalGaugeCanvasRenderingContext2D, options drawText(context, options, 'Value', text, textX, textY); } -function getProgressColor(progress: number, colorsRange: DigitalGaugeColorRange[]): string { +function getProgressColor(progress: number, colorsRange: DigitalGaugeColorRange[], defaultColor: string): string { if (progress === 0 || colorsRange.length === 1) { - return colorsRange[0].rgbString; + return defaultColor; } - for (let j = 0; j < colorsRange.length; j++) { - if (progress <= colorsRange[j].pct) { + for (let j = 1; j < colorsRange.length; j += 2) { + if (progress >= colorsRange[j - 1].pct && progress <= colorsRange[j].pct) { const lower = colorsRange[j - 1]; const upper = colorsRange[j]; const range = upper.pct - lower.pct; @@ -836,6 +836,7 @@ function getProgressColor(progress: number, colorsRange: DigitalGaugeColorRange[ return color.toRgbString(); } } + return defaultColor; } function drawArcGlow(context: DigitalGaugeCanvasRenderingContext2D, @@ -945,9 +946,9 @@ function drawProgress(context: DigitalGaugeCanvasRenderingContext2D, options: CanvasDigitalGaugeOptions, progress: number) { let neonColor; if (options.neonGlowBrightness) { - context.currentColor = neonColor = getProgressColor(progress, options.neonColorsRange); + context.currentColor = neonColor = getProgressColor(progress, options.neonColorsRange, options.neonColorValue); } else { - context.currentColor = context.strokeStyle = getProgressColor(progress, options.colorsRange); + context.currentColor = context.strokeStyle = getProgressColor(progress, options.colorsRange, options.neonColorValue); } const {barLeft, barRight, barTop, baseX, width, barBottom, Cx, Cy, Rm, Ro, Ri, strokeWidth} = diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/digital-gauge.models.ts b/ui-ngx/src/app/modules/home/components/widget/lib/digital-gauge.models.ts index 0897d7a8eb..3cf768668d 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/digital-gauge.models.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/digital-gauge.models.ts @@ -190,7 +190,7 @@ export const digitalGaugeSettingsSchema: JsonSettingsSchema = { } }, fixedLevelColors: { - title: 'The colors for the indicator using boundary values', + title: 'The colors for the indicator using boundary values in percents', type: 'array', items: { title: 'levelColor', @@ -214,8 +214,9 @@ export const digitalGaugeSettingsSchema: JsonSettingsSchema = { type: 'string' }, value: { - title: '[From] Value (if predefined value is selected)', - type: 'number' + title: '[From] Value, % (if predefined value is selected)', + type: 'number', + default: 0 } } }, @@ -237,8 +238,9 @@ export const digitalGaugeSettingsSchema: JsonSettingsSchema = { type: 'string' }, value: { - title: '[To] Value (if predefined value is selected)', - type: 'number' + title: '[To] Value, % (if predefined value is selected)', + type: 'number', + default: 100 } } }, @@ -246,7 +248,8 @@ export const digitalGaugeSettingsSchema: JsonSettingsSchema = { title: 'Color', type: 'string' } - } + }, + required: ['color'], } }, showTicks: {