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
allow multiple lines of text in the line label #129
Conversation
Would be great if this change can be merged! |
omg someone please merge this. 😓 |
@zreese @mheiduk it seems ... Nobody is actively maintaining this repo.. few pr have been merged since this year. @benmccann could you pls take a look at the prs. thanks a lot : ) |
This functionality would be really beneficial, could we please get this merged? |
@alex2wong I am not a maintainer of this repo and do not have merge rights. You could try the #dev Slack channel for Chart.js perhaps |
@benmccann I added you as collaborator to this repository (I thought it was already the case). @ All: we are looking for new maintainers for the annotation and zoom plugins, so if you are interested, please reach us on the #dev room of our Slack. |
src/types/line.js
Outdated
view.labelY + (view.labelHeight / 2) | ||
); | ||
|
||
if (view.labelContent !== null && view.labelContent.indexOf("\n") !== -1) { |
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.
do we need this if/else
check? view.labelContent.split("\n")
will return an array with a single element and then it should be able to be processed just like if there were multiple elements
src/types/line.js
Outdated
textWidth = ctx.measureText(longestLabel).width; | ||
|
||
model.labelHeight = (textHeight * labelContentArray.length) + (2 * model.labelYPadding); | ||
//Add padding for in between each label item |
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.
add a space after // and remove extraneous word "for"
src/types/line.js
Outdated
textYPosition | ||
); | ||
|
||
textYPosition += (view.labelFontSize + 5); |
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.
these parentheses are unnecessary
src/types/line.js
Outdated
|
||
model.labelHeight = (textHeight * labelContentArray.length) + (2 * model.labelYPadding); | ||
//Add padding for in between each label item | ||
model.labelHeight += 5 * (labelContentArray.length - 1); |
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.
this padding should probably be configurable. and perhaps the default should be something like fontSize / 3
@aoifef I setup a |
@aoifef just a reminder that you will need to make |
Hello, |
The main Chart.js repo typically takes input as an array for multiple lines instead of using |
src/types/line.js
Outdated
var textHeight = model.labelFontSize; | ||
model.labelHeight = textHeight + (2 * model.labelYPadding); | ||
|
||
if (model.labelContent !== null && model.labelContent.indexOf('\n') !== -1) { |
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.
This seems like it would fail if labelContent
is undefined
. Maybe just check model.labelContent
rather than model.labelContent !== null
@benmccann could you provide an example of this or point me in the right direction in the Chart.js repo? |
See https://www.chartjs.org/docs/latest/configuration/tooltip.html for example and also chartjs/Chart.js#6117 |
src/types/line.js
Outdated
|
||
model.labelHeight = (textHeight * model.labelContent.length) + (2 * model.labelYPadding); | ||
// Add padding in between each label item | ||
model.labelHeight += 5 * (model.labelContent.length - 1); |
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.
can we use model.labelYPadding
instead of hard coding 5
? (same below on line 282)
…/chartjs-plugin-annotation into line-label-multiple-lines
This is not working... |
@mtskf are you using the code from |
* commit '7037eea71314613a8af83d2298241841cbc34c4f': Fix undefined reference "preserveComments" not longer available on gulp-uglify (chartjs#177) Added PLUGIN ID because missing (chartjs#173) allow multiple lines of text in the line label (chartjs#129) Chart.js should be a peerDependency Fix getting chart borders for box size setting (chartjs#152) Fix a number of lint errors in the samples Add missing .htmllintrc Lint sample html (chartjs#150) Pass the index of value datapoint to getPixelValue (chartjs#109) move configure step to draw time, to support render call (chartjs#116) Read plugin options from plugins.annotation (chartjs#130) Add Travis config Add gulp lint task (chartjs#144) Fix Dropbox url # Conflicts: # README.md # package.json
Using "\n" in the label content will allow the user to take new lines for the line label.