Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- angular.module('googlechart.directives', ['ui.event']).directive('googleChart', ['$timeout', '$window', function ($timeout, $window) {
- return {
- restrict: 'A',
- scope: {
- chart: '=chart'
- },
- link: function ($scope, $elm, $attr) {
- var eventNames="select ready onmouseover animationfinish error onmouseout";
- /* ... Set up the chart and chartwrapper. */
- google.visualization.events.addListener($scope.chartWrapper, 'ready', function () {
- bindChartEvents($scope, eventNames, $scope.chartWrapper.getChart(), $elm);
- });
- }
- };
- function bindChartEvents(scope, eventsStr, chart, element) {
- angular.forEach(eventsStr.split(' '), function (eventName) {
- google.visualization.events.addListener(chart, eventName, function (event) {
- var newEventName = 'chart-' + eventName;
- element.triggerHandler(newEventName, event);
- if (!scope.$$phase){
- scope.$apply();
- }
- });
- });
- }
- }]);
- function bindChartEvents(scope) {
- if(typeof $scope.chart.methods !== "undefined" && typeof $scope.chart.methods.select !== "undefined"){
- $scope.selectListener = google.visualization.events.addListener($scope.chartWrapper, "select", function (event) {
- $scope.chart.methods.select($scope.chartWrapper.getChart().getSelection(), event);
- });
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment