-
Notifications
You must be signed in to change notification settings - Fork 60
Fixes for id attar + add click attr for callback. #8
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,11 +7,16 @@ angular.module('ui.chart', []) | |
| link: function (scope, elem, attrs) { | ||
| var renderChart = function () { | ||
| var data = scope.$eval(attrs.uiChart); | ||
| elem.html(''); | ||
|
|
||
| if (!angular.isArray(data)) { | ||
| return; | ||
| } | ||
|
|
||
| var id = elem.attr('id'); | ||
| if (angular.isUndefined(id)) { | ||
| throw 'Invalid ui.graph id attribute'; | ||
| } | ||
|
|
||
| var opts = {}; | ||
| if (!angular.isUndefined(attrs.chartOptions)) { | ||
| opts = scope.$eval(attrs.chartOptions); | ||
|
|
@@ -20,7 +25,18 @@ angular.module('ui.chart', []) | |
| } | ||
| } | ||
|
|
||
| elem.jqplot(data, opts); | ||
| $(elem).unbind("jqplotDataClick"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should be able to just do elem.unbind - |
||
| $.jqplot(id, data, opts).destroy(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be a good idea to keep a reference to |
||
| $(elem).html(''); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above on |
||
| $.jqplot(id, data, opts); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to see this cached, i.e.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, ignore my comment about |
||
|
|
||
| var click_callback = scope.$eval(attrs.chartClick); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if (angular.isFunction(click_callback)) { | ||
| return $(elem).bind('jqplotDataClick', function(ev, seriesIndex, pointIndex, data) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto here as well. |
||
| return click_callback(ev, seriesIndex, pointIndex, data); | ||
| }); | ||
| } | ||
|
|
||
| }; | ||
|
|
||
| scope.$watch(attrs.uiChart, function () { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a little ungraceful - perhaps create an internal counter before the return block in the directive definition, i.e.
.directive('uiChart', function() { var id = 0; return { ... link: function (scope, elem, attrs) { ... var chartId = attrs.id; if (angular.isUndefined(chartId)) { chartId = 'chart-' + id++; } ... }; });