Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions ui/js/components/elements/tree.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,37 +35,44 @@ d3.selection.prototype.tspans2 = function(lines, lh) {
return '<tspan fill="' + ((['errors', 'error', 'red'].indexOf(k) != -1) ? 'red' : '') + '">' + d[k] + '</tspan>'
}).join('')
})
}
}


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) {
Copy link
Author

@ameccia ameccia Feb 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maxCharactersPerLine updated to have a default of 43, maxLines updated to 3 (43 * 3 = 129, most of AWS names are 128 maximum from what I could find).

const regexChecks = [/_/ig, /-/ig, /([A-Z])/g];
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

many bot names are not following a standard naming structure... As such you can find the following names:
test_bot_123
test-bot-123
testBot123

This regex will check all forms and separate accordingly.

var parts = [],
lines = [],
words = [],
maxChars = maxCharactersPerLine || 40
words = [];

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) {
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] += '...'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seemed more efficient instead of hardcoding

}

return lines
Expand Down Expand Up @@ -589,7 +596,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 || ''));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didnt see a reason to do any of this here. Let the function do the work.

})

nodeText.call(me.getBB)
Expand Down