From ce2237c73d8551ff0de1bd21fa6cf8ed20d8018b Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 5 Nov 2020 19:24:08 +0100 Subject: [PATCH] Splitting Text --- Utilities.js | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/Utilities.js b/Utilities.js index 4c16cb55e..64dd1540f 100644 --- a/Utilities.js +++ b/Utilities.js @@ -14,7 +14,7 @@ function dynamicDecimals(value, minDecimals) { } let decimals = 0 if (value < 1) { decimals = 2 } - + if (Math.abs(Math.trunc(value * 10)) < 1) { decimals = 4 } if (Math.abs(Math.trunc(value * 100)) < 1) { decimals = 5 } if (Math.abs(Math.trunc(value * 1000)) < 1) { decimals = 6 } @@ -24,8 +24,8 @@ function dynamicDecimals(value, minDecimals) { if (Math.abs(Math.trunc(value * 10000000)) < 1) { decimals = 10 } if (Math.abs(Math.trunc(value * 100000000000)) < 1) { value = 0; decimals = 0 } - if (decimals < minDecimals) {decimals = minDecimals} - + if (decimals < minDecimals) { decimals = minDecimals } + let returnValue = Number(value).toFixed(decimals) return returnValue } @@ -99,3 +99,27 @@ function newUniqueId() { return v.toString(16) }) } + +function splitTextIntoPhrases(text, wordsPerLine) { + let splittedLabel = text.split(' ') + let phrases = [] + let phrase = '' + let wordCount = 0 + for (let i = 0; i < splittedLabel.length; i++) { + phrase = phrase + splittedLabel[i] + wordCount++ + + if (i < splittedLabel.length - 1 && wordCount < wordsPerLine) { + phrase = phrase + ' ' + } + if (wordCount >= wordsPerLine) { + phrases.push(phrase) + phrase = '' + wordCount = 0 + } + } + if (wordCount > 0) { + phrases.push(phrase) + } + return phrases +} \ No newline at end of file