-
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
Chart does not resize inside shadow DOM (e.g. Polymer) #5763
Comments
just fyi, you need triple backticks to escape multi-line code instead of just one backtick. I updated it for you |
@Dreamergirly81 please provide a live test case (e.g. jsfiddle). It's complicated and time consuming for us to setup a polymer project to debug your project. |
@simonbrunel i added a test case to stackblitz, because jsfiddle and many others does not work with polymer 3! Hope you can see the Problem here: |
Thanks @Dreamergirly81, stackblitz is fine. I'm not familiar with Polymer and it would require more investigation to find the cause of this issue but my first guess is that our responsive implementation doesn't currently support shadow DOM and thus is not able to detect when the canvas is attached to the DOM tree to insert the resize detector element. |
will chartjs support shadow dom in the future? It is a part of HTML 5 now and i think it should be supported in later versions. Or do you know if there is a easy fix/workaround for this? |
I don't know any fix/workaround and I'm not even sure that's the issue. If shadow DOM is indeed not supported, we will be happy to review PR that fix this issue). FYI, #5585 fixes a few things around that topic, included in v2.7.3 |
@Dreamergirly81 I had a look and it appears that the render-monitor CSS is injected in the wrong location. The method in the chart.js source that injects the CSS is injectCSS. The issue is that it puts the CSS in the document To test this theory I injected the CSS manually into the Polymer component in this test and resize works as expected. In terms of long term solutions, I'm not sure what the best option is. What I can think of so far is:
|
@etimberg thank you! I was able to use your test case in my project, because we really need resizing of the charts. I never thought that CSS is causing this Problem... |
I use |
@jwillmer one caution on that is that it only fires if the whole page resizes, but it won't fire if the div containing the chart resizes. |
It would require to detect when the node is attached to the DOM, which is exactly the purpose of the injected CSS.
I don't think @Dreamergirly81 @etimberg I'm not sure we will be able to correctly handle responsiveness within shadow DOM because we need to inject the CSS under all shadow roots and so we need to know when the canvas is added to the DOM in order to know the DOM scope. |
@simonbrunel now that #6048 is merged, how do you feel about solving this with a documentation update? I think it's going to be hard to get the style auto-injected in the right spot, but with the external CSS file it's not hard to fix. See this example |
I would like to point out this issue still is present. I just tested it within a web component using LitElement and there is no resize done. It only works if I override the render root with using directly the light dom - rendering any advantages of web components useless. |
In the meantime, I was able to get the Chart to resize inside the Shadow DOM with this snippet:
|
Expected Behavior
The Bar Chart should resize when the window size is changed.
Current Behavior
The wrapper div does resize, but the Chart does not.
Steps to Reproduce (for bugs)
https://stackblitz.com/edit/polymer310-testcase-chartjs
Environment
The text was updated successfully, but these errors were encountered: