-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Build HTML via DOM manipulation (vs string manipulation) #6179
Conversation
…arArea legendCallback
Update documentation for generateLegend method; fix corresponding unit tests
This seems like a good change, but isn't backwards compatible. It'd be better if we changed the html fragment construction as you're doing here, but then still returned a string and added a TODO to change the return type in v3 |
Thanks @ian-pvd for your contribution. While I agree this way looks better, it's a breaking change that can't happen in v2. Furthermore in v3, I'm confident that will get rid of this HTML legend in favor of an external plugin to keep the core build as DOM independent as possible, thus the whole logic will be rewritten. Since @benmccann suggestion will not help to fix your Wordpress VIP concerns, I'm going to close this PR. |
@simonbrunel I don't understand why my suggestion wouldn't fix the Wordpress VIP concern. I believe the concern there is using string concatenation to build HTML. But if we instead build it via |
The current |
Ah, I wasn't sure because in the #general channel it referred to |
I may be wrong (I didn't see the Slack message) but I doubt WordPress VIP raises issues for using |
Hi @simonbrunel & @benmccann , thanks for following up so quickly on this PR. To clarify, the specific issue that was flagged by VIP was the use of strings to construct HTML markup. The specific cases that were flagged were those lines inside the I am trying to follow up with VIP after Ben's suggestion last night to see if we would be able to use |
@ian-pvd is it possible to access the code review for your project so we can see the reported issues? While reading the VIP guidelines, I found this: Inserting HTML directly into DOM with Javascript which is a blocker. That means you will not be able to use the |
…ds compatibility. Reverts test updates
HI @simonbrunel, unfortunately I'm unable to link directly to the VIP code review, however I can summarize the specific issues here:
Since this PR was closed, I've discussed @benmccann's suggestion of using DOM constructors to build the legend markup, but returning it as an HTML string to ensure backwards compatibility, and they have tentatively approved this suggestion. I have made changes to my branch which can be previewed here: Please let me know if this would be an acceptable resolution to the HTML string backwards compatibility issue. |
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.
lgtm
@ian-pvd Is this PR ready to be merged or is there anything else that needs to be done in order to get it accepted by the VIP code review? I'm fine to merge these changes even if it would solve your issue only as long as you don't need to call |
Hi @simonbrunel These changes should be sufficient to address the VIP concerns about using string construction and pending a quick re-review of the 2.8 => 2.9, changes Chart.js should be approved for use on WordPress VIP. |
I have made changes to the polar area and doughnut files, removing the This is based on @nagix 's comments:
As for I apologize, that I haven't really been working with Charts.js the past week so I'm in a different headspace, but I just wanted some clarification around what changes, if any, should be made to Again, sorry for being a little bit out of the loop on this, I'd like to help get this merged for 2.9 so let me know if there are additional changes. |
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.
List should have the class even if it's empty.
|
||
if (datasets.length) { | ||
for (var i = 0; i < datasets[0].data.length; ++i) { | ||
text.push('<li><span style="background-color:' + datasets[0].backgroundColor[i] + '"></span>'); | ||
list.setAttribute('class', chart.id + '-legend'); |
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.
class
is not set when datasets is empty. This line should be outside the if
to mimic old behavior.
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.
agreed. if we could fix this during the rebase that'd be great
|
||
if (datasets.length) { | ||
for (var i = 0; i < datasets[0].data.length; ++i) { | ||
text.push('<li><span style="background-color:' + datasets[0].backgroundColor[i] + '"></span>'); | ||
list.setAttribute('class', chart.id + '-legend'); |
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.
Same here
Any idea when this issue will be solved + v2.9 will be released? Been trying to hack something together myself with different chart types per dataset but seems like this will solve my issue. Thanks a lot! |
@ian-pvd just a quick reminder about this outstanding PR. we'd love to get it merged if you're able to address the comments. Thanks! |
@ian-pvd will you be able to update this PR so we can get it merged? |
Looking forward to the release of 2.9, hoping this gets resolved soon! |
I think this is good to merge as soon as the last comment from @kurkle is addressed |
A status on this? |
@Darkecudoua the last pending comment needs to be addressed |
Replaces #6179 and builds HTML legend strings using dom nodes rather than building up an HTML string directly.
Replaces chartjs#6179 and builds HTML legend strings using dom nodes rather than building up an HTML string directly.
Changes in this PR:
generateLegend()
callback builds legend markup to utilize DOM node constructors instead of HTML strings.outerHTML
Context:
These changes are in response to a request to use Chart.JS as part of a WordPress VIP theme, which necessitated a code review where three instances of HTML string constructors were flagged. These changes would bring the 2.8.0 version of Chart.JS into compliance with the WordPress VIP JavaScript coding standards, allowing it to be utilized on other VIP sites and themes.