Skip to content
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

Prevent infinite resize when vertical scrollbar appears #6011

Merged
merged 5 commits into from
Jan 30, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/core/core.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,13 @@ helpers.extend(Chart.prototype, /** @lends Chart */ {
plugins.notify(me, 'resize', [newSize]);

// Notify of resize
if (me.options.onResize) {
kurkle marked this conversation as resolved.
Show resolved Hide resolved
me.options.onResize(me, newSize);
if (options.onResize) {
options.onResize(me, newSize);
}

me.stop();
me.update({
duration: me.options.responsiveAnimationDuration
duration: options.responsiveAnimationDuration
});
}
},
Expand Down
13 changes: 11 additions & 2 deletions src/platforms/platform.dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,21 @@ function unwatchForRender(node) {
}

function addResizeListener(node, listener, chart) {
var expando = node[EXPANDO_KEY] || (node[EXPANDO_KEY] = {});
var expando = node[EXPANDO_KEY] = node[EXPANDO_KEY] || {};
kurkle marked this conversation as resolved.
Show resolved Hide resolved

// Let's keep track of this added resizer and thus avoid DOM query when removing it.
var resizer = expando.resizer = createResizer(throttled(function() {
if (expando.resizer) {
return listener(createEvent('resize', chart));
var aspectRatio = chart.options.maintainAspectRatio && chart.aspectRatio || null;
kurkle marked this conversation as resolved.
Show resolved Hide resolved
var container = aspectRatio && node.parentNode;
var w = container ? container.clientWidth : 0;
var ret = listener(createEvent('resize', chart));
kurkle marked this conversation as resolved.
Show resolved Hide resolved
if (container && container.clientWidth !== w && chart.canvas) {
kurkle marked this conversation as resolved.
Show resolved Hide resolved
// If the container size changed during chart resize, we can assume scrollbar appeared.
kurkle marked this conversation as resolved.
Show resolved Hide resolved
// So let's resize again, with the scrollbar visible
ret = listener(createEvent('resize', chart));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious how the 2nd resize doesn't cause the scrollbar to go away

Copy link
Member Author

@kurkle kurkle Jan 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I think happens: We are doing the resize in a onScroll event. We resize, notice it made scrollbars visible and resize again. Scrollbars are hidden in the end of this scroll event. And I suppose browsers won't fire another scroll until the previous is done.
And throttled() prevents multiple onScroll's in same frame.

Initially I was storing the width, but accidentally found out, it was not really needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, that's a good find. If throttled() can prevent the double event then I'm ok with testing this out further

}
return ret;
}
}));

Expand Down