From a1cfd82ab32ba1361a92fafe7b01bcbb79b0ee58 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 16 Mar 2020 14:35:13 +0100 Subject: [PATCH] dynamicDecimals --- Scales/RateScale.js | 7 +------ Utilities.js | 9 +++++++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Scales/RateScale.js b/Scales/RateScale.js index 2c728aa11..8e208d9b3 100644 --- a/Scales/RateScale.js +++ b/Scales/RateScale.js @@ -487,12 +487,7 @@ function newRateScale () { rate = coordinateSystem.max.y } - let decimals = 2 - if (rate < 1) { decimals = 4 } - if (Math.trunc(rate * 100) < 1) { decimals = 6 } - if (Math.trunc(rate * 10000) < 1) { decimals = 8 } - if (Math.trunc(rate * 1000000) < 1) { decimals = 10 } - let label = (rate - Math.trunc(rate)).toFixed(decimals) + let label = dynamicDecimals(rate) let labelArray = label.split('.') let label1 = thisObject.payload.node.payload.parentNode.name let label2 = (Math.trunc(rate)).toLocaleString() diff --git a/Utilities.js b/Utilities.js index 2588156b9..8b4262173 100644 --- a/Utilities.js +++ b/Utilities.js @@ -22,6 +22,15 @@ function drawContainerBackground (container, color, opacity, fitFunction) { browserCanvasContext.fill() } +function dynamicDecimals (value) { + let decimals = 2 + if (value < 1) { decimals = 4 } + if (Math.trunc(value * 100) < 1) { decimals = 6 } + if (Math.trunc(value * 10000) < 1) { decimals = 8 } + if (Math.trunc(value * 1000000) < 1) { decimals = 10 } + return (value - Math.trunc(value)).toFixed(decimals) +} + function savePropertyAtNodeConfig (payload, propertyName, value) { try { let code = JSON.parse(payload.node.code)