Changed logic for processing boundary values and change labels

This commit is contained in:
ArtemDzhereleiko 2021-09-17 17:07:58 +03:00
parent 75817a16f4
commit bbea48215e
2 changed files with 18 additions and 14 deletions

View File

@ -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} =

View File

@ -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: {