-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enable truncation based on single long words and number of line restriction #91
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great work @IPWright83! I left a couple comments. After that, this should be good to go.
src/textWrap.js
Outdated
@@ -125,6 +126,15 @@ export default function() { | |||
return arguments.length ? (lineHeight = _, textWrap) : lineHeight; | |||
}; | |||
|
|||
/** | |||
@memberof textWrap | |||
@desc If *value* is specified, sets the maximum number of lines allowed when wrapping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a period to the end of this sentence
src/TextBox.js
Outdated
else if (fS > fMax) fS = fMax; | ||
// Constraint the font size | ||
fS = Math.max(fS, fMin); | ||
fS = Math.min(fS, fMax); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to use the max
and min
functions imported from d3-array
instead of the vanilla JS Math functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interested to know the reason for this? Happy to make the change but I'm always pro vanilla if possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's just ever-so-slightly more robust than the built-in (and is already included as a dependency). I suppose in this case it doesn't matter ¯\(ツ)/¯
Unlike the built-in Math.max, this method ignores undefined values; this is useful for ignoring missing data. In addition, elements are compared using natural order rather than numeric order. For example, the maximum of the strings [“20”, “3”] is “3”, while the maximum of the numbers [20, 3] is 20.
pages/Truncate.html
Outdated
|
||
d3PlusWrap(g, circles); | ||
|
||
</script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please move this file to a directory called dev/
, which will then remove it from the repo. We don't store test HTML files in the repository.
@davelandry Thanks for your feedback. I'll look at making those changes. One thing of note is that I'm struggling a little getting it working within our product at the moment (you might be able to help). I'm including via an npm install, and getting issues with all the Have you come across anything similar? |
@davelandry let me know if this is ok. If so be great if you have a chance to publish before Monday. Save me publishing my own internal version to use :) |
@IPWright83 just published this PR with a new release. thanks again! what kind of errors are you getting with installing using npm? |
also, what type of environment are you installing it into? |
@davelandry I think I'm managed to fix my npm issues now fortunately. Took a bit of battling but we have our own d3 bundle (due to an old npm bug) and essentially I was getting 2 instances of Glad to have helped, thanks for producing the library in the first place. |
@IPWright83 can you publish the solution to your NPM troubles? We're having the same exact issue, also due to the extra addition of d3. Getting the selection prototype not having a transition function. Thank you! |
@anatolyg Took me a while to sort out, but I was getting the following structure (bearing in mind we have our own bundle of d3):
Note that the companyx/d3 d3plus-text So while it should have been able to pull in just |
Added a maximum number of lines feature: closes #75
Resolved issues where no text was being displayed when a single word was too large: closes #76
Description
For #75 I've added an additional
maxLines()
option that can be changed onTextBox.js
. This defaults tonull
which indicates there is no limit applied. When wrapping occurs this gets passed down intotextWrap.js
and is considered when it determines whether truncation needs to occur.For #76 this was due to the word being too long to physically fit, therefore
lineData
was being set to an empty array yielding a blank result. I've modified this to call the ellipsis function and pass the result into a newtextTruncate
function. This will reduce the length of the original word and append ellipsis until it can successfully fit in the given width constraints. This does change the behavior for a single long word so have indicated as a breaking change.Types of changes
Checklist