From ea0a643f7d52b0e04c051e8add982008ed09b51f Mon Sep 17 00:00:00 2001 From: hansmaad Date: Thu, 25 Sep 2014 12:01:20 +0200 Subject: [PATCH 1/3] Handle jqplot events to update data. --- src/chart.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/chart.js b/src/chart.js index 2840081..f1283c4 100644 --- a/src/chart.js +++ b/src/chart.js @@ -21,6 +21,16 @@ angular.module('ui.chart', []) } elem.jqplot(data, opts); + elem.bind('jqplotSeriesPointChange', + function (e, series, point, values) { + data[series][point][0] = values[0]; + data[series][point][1] = values[1]; + }); + + elem.bind('jqplotDragStop', function () { + scope.$apply(); + }); + }; scope.$watch(attrs.uiChart, function () { @@ -32,4 +42,4 @@ angular.module('ui.chart', []) }); } }; - }); \ No newline at end of file + }); From 8a30072652be5bbd3c8f595fb6eb5282192d7be2 Mon Sep 17 00:00:00 2001 From: hansmaad Date: Thu, 25 Sep 2014 14:41:10 +0200 Subject: [PATCH 2/3] Added tests for jqplotSeriesPointChange event --- src/chart.js | 3 +-- test/chart.spec.js | 17 +++++++++++++++++ test/karma.conf.js | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/chart.js b/src/chart.js index f1283c4..da14c4f 100644 --- a/src/chart.js +++ b/src/chart.js @@ -28,9 +28,8 @@ angular.module('ui.chart', []) }); elem.bind('jqplotDragStop', function () { - scope.$apply(); + scope.$apply(); }); - }; scope.$watch(attrs.uiChart, function () { diff --git a/test/chart.spec.js b/test/chart.spec.js index aac4c4b..e33f8e1 100644 --- a/test/chart.spec.js +++ b/test/chart.spec.js @@ -130,4 +130,21 @@ describe('uiChart Directive', function () { expect(element.html()).toBe(''); expect(element[0].children.length).toBe(0); }); + + it('should update data', function () { + compile('data'); + scope.data = [ + [[1, 2], [3, 4]] + ]; + scope.$digest(); + + element.trigger('jqplotSeriesPointChange', [0, 0, [4, 5], [4, 5]]); + expect(scope.data[0][0][0]).toBe(4); + expect(scope.data[0][0][1]).toBe(5); + + spyOn(scope, '$apply'); + + element.trigger('jqplotDragStop'); + expect(scope.$apply).toHaveBeenCalled(); + }); }); \ No newline at end of file diff --git a/test/karma.conf.js b/test/karma.conf.js index 13e2490..aa76b3f 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -49,7 +49,7 @@ autoWatch = false; // - Safari (only Mac) // - PhantomJS // - IE (only Windows) -browsers = ['PhantomJS', 'Chrome', 'Firefox']; +browsers = ['Chrome']; // If browser does not capture in given timeout [ms], kill it From fc4c33db9d84b25248ede27aa5f0dc808e0a7017 Mon Sep 17 00:00:00 2001 From: hansmaad Date: Thu, 25 Sep 2014 14:44:34 +0200 Subject: [PATCH 3/3] Undo changes in karma.conf.js --- test/karma.conf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/karma.conf.js b/test/karma.conf.js index aa76b3f..13e2490 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -49,7 +49,7 @@ autoWatch = false; // - Safari (only Mac) // - PhantomJS // - IE (only Windows) -browsers = ['Chrome']; +browsers = ['PhantomJS', 'Chrome', 'Firefox']; // If browser does not capture in given timeout [ms], kill it