From 3f767c0b84f571ebf4d066f2e34d1221f395129d Mon Sep 17 00:00:00 2001 From: hamza zia Date: Fri, 25 Jan 2013 19:38:08 +0500 Subject: [PATCH] only draw graphs in angular when not collapsed, perf improvement --- js/directives/dgraph.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/js/directives/dgraph.js b/js/directives/dgraph.js index b024a27..ae6819a 100644 --- a/js/directives/dgraph.js +++ b/js/directives/dgraph.js @@ -43,6 +43,13 @@ app.directive('dgraph', ['$', '$filter', function($, filter) { elem.height(elem.width() / 2); + graph.setData([dconf, uconf]); + graph.resize(); + graph.setupGrid(); + graph.draw(); + }; + + function update() { var cnt = ((new Date - start)/1000).toFixed(0); dconf.data.push([cnt, dspeed]); @@ -51,10 +58,10 @@ app.directive('dgraph', ['$', '$filter', function($, filter) { uconf.data.push([cnt, uspeed]); if (uconf.data.length > graphSize) uconf.data.shift(); - graph.setData([dconf, uconf]); - graph.resize(); - graph.setupGrid(); - graph.draw(); + // if any parents is collapsable, then confirm if it isnt + var collapsable = elem.parents('.collapse'); + if (!collapsable.length || collapsable.hasClass('in')) + draw(); }; scope.$watch(attrs.dspeed, function(val) { @@ -65,7 +72,7 @@ app.directive('dgraph', ['$', '$filter', function($, filter) { uspeed = val; }); - var interval = setInterval(draw, 1000); + var interval = setInterval(update, 1000); elem.bind('$destroy', function() { clearInterval(interval);