Skip to content

Commit 97da221

Browse files
kurklesimonbrunel
authored andcommitted
Prevent infinite resize when vertical scrollbar appears (#6011)
If the container size shrank during chart resize, let's assume scrollbar appeared. So we resize again with the scrollbar visible effectively making chart smaller and the scrollbar hidden again. Because we are inside `throttled`, and currently `ticking`, scroll events are ignored during this whole 2 resize process. If we assumed wrong and something else happened, we are resizing twice in a frame (potential performance issue)
1 parent 29f7fa2 commit 97da221

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/core/core.controller.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,13 @@ helpers.extend(Chart.prototype, /** @lends Chart */ {
277277
plugins.notify(me, 'resize', [newSize]);
278278

279279
// Notify of resize
280-
if (me.options.onResize) {
281-
me.options.onResize(me, newSize);
280+
if (options.onResize) {
281+
options.onResize(me, newSize);
282282
}
283283

284284
me.stop();
285285
me.update({
286-
duration: me.options.responsiveAnimationDuration
286+
duration: options.responsiveAnimationDuration
287287
});
288288
}
289289
},

src/platforms/platform.dom.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,19 @@ function addResizeListener(node, listener, chart) {
273273
// Let's keep track of this added resizer and thus avoid DOM query when removing it.
274274
var resizer = expando.resizer = createResizer(throttled(function() {
275275
if (expando.resizer) {
276-
return listener(createEvent('resize', chart));
276+
var container = chart.options.maintainAspectRatio && node.parentNode;
277+
var w = container ? container.clientWidth : 0;
278+
listener(createEvent('resize', chart));
279+
if (container && container.clientWidth < w && chart.canvas) {
280+
// If the container size shrank during chart resize, let's assume
281+
// scrollbar appeared. So we resize again with the scrollbar visible -
282+
// effectively making chart smaller and the scrollbar hidden again.
283+
// Because we are inside `throttled`, and currently `ticking`, scroll
284+
// events are ignored during this whole 2 resize process.
285+
// If we assumed wrong and something else happened, we are resizing
286+
// twice in a frame (potential performance issue)
287+
listener(createEvent('resize', chart));
288+
}
277289
}
278290
}));
279291

0 commit comments

Comments
 (0)