diff --git a/src/chart.js b/src/chart.js index 2840081..da14c4f 100644 --- a/src/chart.js +++ b/src/chart.js @@ -21,6 +21,15 @@ 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 +41,4 @@ angular.module('ui.chart', []) }); } }; - }); \ No newline at end of file + }); 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