Skip to content

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

Description

@Bartozzz

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.

Metadata

Metadata

Labels

Type: Feature RequestUsed when a new feature is requested either directly or indirectly

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions