From a7ba0a7d1d83aebb555c812eb892c7fd03a35e41 Mon Sep 17 00:00:00 2001 From: Toby Date: Tue, 18 Mar 2025 10:22:52 +0100 Subject: [PATCH] Fix scale function in ftui.helper.js The current scale implementation can lead to return values beyond min/max being specified when the value is out of bounds. This commit ensures that the boundaries are kept. --- www/ftui/modules/ftui/ftui.helper.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/www/ftui/modules/ftui/ftui.helper.js b/www/ftui/modules/ftui/ftui.helper.js index 8c622b84..2b0f5570 100755 --- a/www/ftui/modules/ftui/ftui.helper.js +++ b/www/ftui/modules/ftui/ftui.helper.js @@ -423,9 +423,18 @@ export function formatMoney(amount) { } export function scale(value, minIn, maxIn, minOut, maxOut) { - const slope = (minOut - maxOut) / (minIn - maxIn); - const intercept = slope * -(minIn) + minOut; - return value * slope + intercept; + if(value <= minIn) { + return minOut; + } + else if(value >= maxIn) { + return maxOut; + } + else + { + const slope = (minOut - maxOut) / (minIn - maxIn); + const intercept = slope * -(minIn) + minOut; + return value * slope + intercept; + } } export function limit(value, minIn, maxIn) {