Skip to content

Chart reflow on container dimension change instead of window resize #17924

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

Closed
Bartozzz opened this issue Nov 3, 2022 · 6 comments · Fixed by #17951
Closed

Chart reflow on container dimension change instead of window resize #17924

Bartozzz opened this issue Nov 3, 2022 · 6 comments · Fixed by #17951
Assignees
Labels
Type: Feature Request Used when a new feature is requested either directly or indirectly

Comments

@Bartozzz
Copy link

Bartozzz commented Nov 3, 2022

Related to #6707.

Description of the feature

Right now, charts gets reflowed on window resize. Because of that, there's no automatic reflow on layout shifts. It would be nice to get reflow on changes to the dimensions of a chart's container instead.

Library related to the feature

Highcharts

Proof of Concept/Live example for the feature

Instead of listening for window resize here:

public setReflow(reflow?: boolean): void {
const chart = this;
if (reflow !== false && !this.unbindReflow) {
this.unbindReflow = addEvent(win, 'resize', function (
e: Event
): void {
// a removed event listener still runs in Edge and IE if the
// listener was removed while the event runs, so check if the
// chart is not destroyed (#11609)
if (chart.options) {
chart.reflow(e);
}
});
addEvent(this, 'destroy', this.unbindReflow);
} else if (reflow === false && this.unbindReflow) {
// Unbind and unset
this.unbindReflow = this.unbindReflow();
}
// The following will add listeners to re-fit the chart before and after
// printing (#2284). However it only works in WebKit. Should have worked
// in Firefox, but not supported in IE.
/*
if (win.matchMedia) {
win.matchMedia('print').addListener(function reflow() {
chart.reflow();
});
}
//*/
}

We could use a ResizeObserver and listen for dimensions changes of the chart.renderTo element.


You can vote for this feature by adding a thumbs-up reaction to this post.

@Bartozzz Bartozzz added the Type: Feature Request Used when a new feature is requested either directly or indirectly label Nov 3, 2022
@karolkolodziej
Copy link
Contributor

Hi @Bartozzz!
Thank you for sharing your thoughts!

A similar idea has already been discussed and tested here: #6427 (comment)
Demo: https://jsfiddle.net/BlackLabel/tadcn975/

From what I can see, right now it is widely supported through multiple browsers.
Perhaps it is the right time to revisit this idea @TorsteinHonsi?

@TorsteinHonsi
Copy link
Collaborator

Perhaps it is the right time to revisit this idea @TorsteinHonsi?

Absolutely @karolkolodziej! Will you have a go?

@sszczep
Copy link

sszczep commented Nov 4, 2022

Stumbled upon the same issue. Would be great to have it fixed.

@Groszekk
Copy link

Groszekk commented Nov 4, 2022

I'm struggling with it as well...

@Bartozzz
Copy link
Author

Hey @karolkolodziej, this fix is quite important for us – when can we expect this feature to roll out? Is there an ETA? If not – what is the recommended hotfix? Should we use Highcharts.wrap(Highcharts.Chart.prototype, 'setReflow', …) or set-up a resize observer ourselves and call chart.reflow() in the callback?

@karolkolodziej
Copy link
Contributor

@Bartozzz There are some cavities of this solution that we have to discuss before proceeding with that fix and unfortunately there is no ETA for now.
For now, I would use chart.reflow() until we fully discover and test the observer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature Request Used when a new feature is requested either directly or indirectly
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants