-
Notifications
You must be signed in to change notification settings - Fork 465
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
Fix: Render/resize the plot only if it is visible #1029
Conversation
Opening this PR as draft. We really need to discuss this. All of this might need a change in ipywidgets: wait for the first cc. @maartenbreddels |
bf7ab84
to
3154b06
Compare
This delays the rendering of the plot to when the plot is actually visible on the page and has available space. This fixes an issue when having bqplots in Tab widgets. Because we waited for the displayed promise to be resolved (which is resolved on after-attach), the plot was rendered under invisible tabs with an available size of 0, and was not resized when clicking on the tab. This was resulting in a weirdly shrinked plot. This changes this behavior by waiting for the element to be actually shown on the page (after-show is triggered when clicking on the tab) and has available space. Signed-off-by: martinRenou <[email protected]>
3154b06
to
0c56d3b
Compare
This will fix #1023 by lazily rendering the plot. |
Signed-off-by: martinRenou <[email protected]>
0db4c9b
to
2ae204a
Compare
@maartenbreddels I have a working version using the intersection observer. Although it breaks tests for now. |
Signed-off-by: martinRenou <[email protected]>
Tests are passing again by enforcing the visible status of the plot in tests. |
@maartenbreddels I'd be interested to know if that works with your tablet |
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.
Looks good, I did not test on my tablet (not here). It does add a lot of complexity, but I'm not sure we can avoid that.
I've also opened a new issue about fixing the underlying issue in ipywidgets: jupyter-widgets/ipywidgets#2762 |
You could just listen for the |
It was actually the first version of this PR (see 0c56d3b), but it was not working properly (see this comment). Also, the intersection Observer is a bit different from the |
How does this handle the case where you scroll a visible bqplot plot off the screen, then resize the browser window, then scroll back to see the plot? Will it automatically resize as soon as it becomes visible? |
#1047 is an alternative implementation that uses the phosphor after-show event. It's not as fancy, in that it doesn't use the browser visibility capabilities, but it is quite a bit simpler. Thoughts? |
Yes :) |
I agree. I tried this approach at first but could not make it work. I guess I forgot the Even though this PR brings more optimizations on the resize (resize plot only if it is visible), I would say simpler is better, we can close my PR. |
Closed in favor of #1047 |
This delays the rendering and the resize of the plot to when the plot is actually visible on the page.
It is using the IntersectionObserver API for knowing if the plot is visible on the page or not
This fixes an issue when having bqplots in Tab widgets.
Fixes #1023
This is related to jupyter-widgets/ipywidgets#2605