Skip to content

Conversation

@ameccia
Copy link

@ameccia ameccia commented Feb 4, 2022

No description provided.


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).

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];
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.

if (line.search(regexChecks[num]) >= 0) {
parts = line.replace(regexChecks[num], (num == 2 ? ' $1' : ' ')).split(' ');
}
}
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.

loop through until you find the correct regex, split accordingly.
if it is camel-case, I had to check with a ternary: (num == 2 ? ' $1' : ' '))

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


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.

Copy link

@jgrantr jgrantr left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@ameccia
Copy link
Author

ameccia commented Feb 7, 2022

My only concern at this point is the lack of testing. I have no idea how to test any of this code at this point, so this may wait for Clint to return from vacation and assist with testing before merge/release.


for(let num in regexChecks) {
if (line.search(regexChecks[num]) >= 0) {
parts = line.replace(regexChecks[num], (num == 2 ? ' $1' : ' ')).split(' ');

Choose a reason for hiding this comment

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

This will overwrite the array that parts was instantiated as, and will not accumulate more than a single regex replacement - This should instead be something like parts.push(... - Also might be a little cleaner to wrap this loop up as a reduce rather than a for loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants