From 95e59da8a981434bb9eb810bedd17dd575549e4f Mon Sep 17 00:00:00 2001 From: Guntars Simanskis Date: Fri, 23 Sep 2016 09:35:08 +0100 Subject: [PATCH] Added option addResizeListener for responsive iframe. Reason, on the tests, when draw 10 or more charts on one page is serious perfomance killer. --- samples/bar.html | 1 + src/core/core.js | 16 +++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/samples/bar.html b/samples/bar.html index d595bae49d9..cf211e413f1 100644 --- a/samples/bar.html +++ b/samples/bar.html @@ -71,6 +71,7 @@ } }, responsive: true, + addResizeListener: false, legend: { position: 'top', }, diff --git a/src/core/core.js b/src/core/core.js index 577db878e16..09887e5b4e2 100755 --- a/src/core/core.js +++ b/src/core/core.js @@ -50,13 +50,14 @@ module.exports = function() { // High pixel density displays - multiply the size of the canvas height/width by the device pixel ratio, then scale. helpers.retinaScale(me); me.controller = new Chart.Controller(me); - - // Always bind this so that if the responsive state changes we still work - helpers.addResizeListener(context.canvas.parentNode, function() { - if (me.controller && me.controller.config.options.responsive) { - me.controller.resize(); - } - }); + if(me.config && me.config.options && me.config.options.addResizeListener === true) { + // Bind this if option addResizeListener is true (default true) so that if the responsive state changes we still work + helpers.addResizeListener(context.canvas.parentNode, function() { + if (me.controller && me.controller.config.options.responsive) { + me.controller.resize(); + } + }); + } return me.controller ? me.controller : me; @@ -66,6 +67,7 @@ module.exports = function() { Chart.defaults = { global: { responsive: true, + addResizeListener: true, responsiveAnimationDuration: 0, maintainAspectRatio: true, events: ['mousemove', 'mouseout', 'click', 'touchstart', 'touchmove'],