From bef0bd48c23e386d585378987229fd47b650359a Mon Sep 17 00:00:00 2001 From: ameccia Date: Fri, 4 Feb 2022 17:04:38 -0500 Subject: [PATCH 1/3] expanding bot names in main layout --- ui/js/components/elements/tree.jsx | 32 ++++++++++++++++++------------ 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/ui/js/components/elements/tree.jsx b/ui/js/components/elements/tree.jsx index e82aa58..bec1e36 100644 --- a/ui/js/components/elements/tree.jsx +++ b/ui/js/components/elements/tree.jsx @@ -38,34 +38,40 @@ d3.selection.prototype.tspans2 = function(lines, lh) { } -d3.wordwrap = function (line, maxCharactersPerLine, maxLines = 2) { - var parts = line.split(/([^a-z][a-z]*)/), //split at non-words +d3.wordwrap = function (line = '', maxCharactersPerLine = 43, maxLines = 3) { + const regexChecks = [/_/ig, /-/ig, /([A-Z])/g]; + var parts = [], lines = [], - words = [], - maxChars = maxCharactersPerLine || 40 + words = []; + + for(let num in regexChecks) { + if (line.search(regexChecks[num]) >= 0) { + parts = line.replace(regexChecks[num], (num == 2 ? ' $1' : ' ')).split(' '); + } + } parts.forEach(function (part) { if (part) { - if (words.length > 0 && (words.join('').length + part.length) > maxChars) { - lines.push(words.join('')) + if (words.length > 0 && (words.join(' ').length + part.length) > maxCharactersPerLine) { + lines.push(words.join(' ')) words = [] } - //if it's too long, chop it - while (part.length > maxChars) { - lines.push(part.slice(0, maxChars - 1) + '-') - part = part.slice(maxChars - 1) + //if the word is too long, chop it + while (part.length > maxCharactersPerLine) { + lines.push(part.slice(0, maxCharactersPerLine - 1) + '-') + part = part.slice(maxCharactersPerLine - 1) } words.push(part) } }) if (words.length) { - lines.push(words.join('')) + lines.push(words.join(' ')) } if (lines.length > maxLines) { lines = lines.slice(0, maxLines) - lines[1] += '...' + lines[maxLines - 1] += '...' } return lines @@ -589,7 +595,7 @@ class Tree extends React.Component { }) nodeText.tspans2(function (d) { - return d3.wordwrap((d.label || '').toString().replace(/_/ig, ' '), 20) //12 + return d3.wordwrap((d.label || '')); }) nodeText.call(me.getBB) From 3e4a6f0f5f0f2ed737d92e53a11cc61dc4b8a874 Mon Sep 17 00:00:00 2001 From: ameccia Date: Fri, 4 Feb 2022 17:12:53 -0500 Subject: [PATCH 2/3] did not care for num as a variable name --- ui/js/components/elements/tree.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ui/js/components/elements/tree.jsx b/ui/js/components/elements/tree.jsx index bec1e36..5b2d502 100644 --- a/ui/js/components/elements/tree.jsx +++ b/ui/js/components/elements/tree.jsx @@ -44,9 +44,9 @@ d3.wordwrap = function (line = '', maxCharactersPerLine = 43, maxLines = 3) { lines = [], words = []; - for(let num in regexChecks) { - if (line.search(regexChecks[num]) >= 0) { - parts = line.replace(regexChecks[num], (num == 2 ? ' $1' : ' ')).split(' '); + for(let regexCheck in regexChecks) { + if (line.search(regexChecks[regexCheck]) >= 0) { + parts = line.replace(regexChecks[regexCheck], (regexCheck == 2 ? ' $1' : ' ')).split(' '); } } From 157282bce39209562914490ab3f669f79b5517aa Mon Sep 17 00:00:00 2001 From: ameccia Date: Mon, 7 Feb 2022 14:35:36 -0500 Subject: [PATCH 3/3] Updating for loop logic due to feedback --- ui/js/components/elements/tree.jsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ui/js/components/elements/tree.jsx b/ui/js/components/elements/tree.jsx index 5b2d502..0643d8c 100644 --- a/ui/js/components/elements/tree.jsx +++ b/ui/js/components/elements/tree.jsx @@ -35,7 +35,7 @@ d3.selection.prototype.tspans2 = function(lines, lh) { return '' + d[k] + '' }).join('') }) -} +} d3.wordwrap = function (line = '', maxCharactersPerLine = 43, maxLines = 3) { @@ -44,11 +44,12 @@ d3.wordwrap = function (line = '', maxCharactersPerLine = 43, maxLines = 3) { lines = [], words = []; - for(let regexCheck in regexChecks) { - if (line.search(regexChecks[regexCheck]) >= 0) { - parts = line.replace(regexChecks[regexCheck], (regexCheck == 2 ? ' $1' : ' ')).split(' '); + const parts = regexChecks.reduce((accumulator, regexCheck, index) => { + if(line.search(regexCheck) >= 0) { + accumulator.push(line.replace(regexChecks[index], (index == 2 ? ' $1' : ' ')).split(' ')); } - } + return accumulator; + }, []); parts.forEach(function (part) { if (part) {