From 828f57a47243959e5bef48fda56f0b3c41a5dd04 Mon Sep 17 00:00:00 2001 From: linagee Date: Wed, 23 Apr 2014 11:59:41 -0600 Subject: [PATCH] Track children() before/after .jqplot, responsize/resize Empty children before plotting, make sure plot created some children or retry, redraw on resize (needed for responsive web design layouts). --- src/chart.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/chart.js b/src/chart.js index 2840081..3cbe117 100644 --- a/src/chart.js +++ b/src/chart.js @@ -1,5 +1,5 @@ angular.module('ui.chart', []) - .directive('uiChart', function () { + .directive('uiChart', function ($window, $timeout) { return { restrict: 'EACM', template: '
', @@ -20,8 +20,14 @@ angular.module('ui.chart', []) } } + elem.empty(); //delete children elem.jqplot(data, opts); + //make sure there are children or maybe .jqplot didn't render + if (!elem.children().length) { $timeout(renderChart, 100); } }; + + //responsive friendly + angular.element($window).bind('resize', renderChart); scope.$watch(attrs.uiChart, function () { renderChart(); @@ -32,4 +38,4 @@ angular.module('ui.chart', []) }); } }; - }); \ No newline at end of file + });