From 7497647c5574da419f739b649096c805ad49f51b Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 30 Jun 2019 12:31:41 +0200 Subject: [PATCH] Flexible decimals and fontsize at speedometer --- CockpitSpace/Speedometer.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/CockpitSpace/Speedometer.js b/CockpitSpace/Speedometer.js index d42e4a5b4..b20fc3a09 100644 --- a/CockpitSpace/Speedometer.js +++ b/CockpitSpace/Speedometer.js @@ -178,16 +178,27 @@ function newSpeedometer () { /* We put the thisObject.params.VALUE in the middle */ fontSize = 22 - + if (thisObject.params.VALUE > 999) { + fontSize = 18 + } + if (thisObject.params.VALUE > 9999) { + fontSize = 14 + } + if (thisObject.params.VALUE > 99999) { + fontSize = 10 + } browserCanvasContext.font = 'bold ' + fontSize + 'px ' + UI_FONT.PRIMARY label = thisObject.params.VALUE + if (isNaN(label) === false) { label = Number(label) + + label = Math.trunc(label * Math.pow(10, thisObject.params.DECIMALS)) / Math.pow(10, thisObject.params.DECIMALS) if (label === 0) { label = label.toFixed(2) } else { label = label.toLocaleString() } } - label = label.substring(0, 6) + // label = label.substring(0, 6) xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO + 7