Browse Source

Call resize handlers only if chart is displayed (#2164)

pull/2176/head
Corneliu Sugar 7 years ago committed by Yoshiya Hinosawa
parent
commit
7e5c20c0ff
  1. 22
      src/core.js

22
src/core.js

@ -937,11 +937,20 @@ c3_chart_internal_fn.bindResize = function () {
$$.resizeFunction.add(function () {
config.onresized.call($$);
});
var resizeIfElementDisplayed = function() {
// if element not displayed skip it
if (!$$.api.element.offsetParent) {
return;
}
$$.resizeFunction();
};
if (window.attachEvent) {
window.attachEvent('onresize', $$.resizeFunction);
window.attachEvent('onresize', resizeIfElementDisplayed);
} else if (window.addEventListener) {
window.addEventListener('resize', $$.resizeFunction, false);
window.addEventListener('resize', resizeIfElementDisplayed, false);
} else {
// fallback to this, if this is a very old browser
var wrapper = window.onresize;
@ -955,7 +964,14 @@ c3_chart_internal_fn.bindResize = function () {
}
// add this graph to the wrapper, we will be removed if the user calls destroy
wrapper.add($$.resizeFunction);
window.onresize = wrapper;
window.onresize = function() {
// if element not displayed skip it
if (!$$.api.element.offsetParent) {
return;
}
wrapper();
};
}
};

Loading…
Cancel
Save