Guest User

Untitled

a guest
Dec 7th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. angular.module('googlechart.directives', ['ui.event']).directive('googleChart', ['$timeout', '$window', function ($timeout, $window) {
  2. return {
  3. restrict: 'A',
  4. scope: {
  5. chart: '=chart'
  6. },
  7. link: function ($scope, $elm, $attr) {
  8. var eventNames="select ready onmouseover animationfinish error onmouseout";
  9.  
  10. /* ... Set up the chart and chartwrapper. */
  11.  
  12. google.visualization.events.addListener($scope.chartWrapper, 'ready', function () {
  13. bindChartEvents($scope, eventNames, $scope.chartWrapper.getChart(), $elm);
  14. });
  15.  
  16. }
  17. };
  18. function bindChartEvents(scope, eventsStr, chart, element) {
  19. angular.forEach(eventsStr.split(' '), function (eventName) {
  20. google.visualization.events.addListener(chart, eventName, function (event) {
  21. var newEventName = 'chart-' + eventName;
  22. element.triggerHandler(newEventName, event);
  23. if (!scope.$$phase){
  24. scope.$apply();
  25. }
  26. });
  27. });
  28. }
  29. }]);
  30.  
  31. function bindChartEvents(scope) {
  32. if(typeof $scope.chart.methods !== "undefined" && typeof $scope.chart.methods.select !== "undefined"){
  33. $scope.selectListener = google.visualization.events.addListener($scope.chartWrapper, "select", function (event) {
  34. $scope.chart.methods.select($scope.chartWrapper.getChart().getSelection(), event);
  35. });
  36. }
  37. });
Advertisement
Add Comment
Please, Sign In to add comment