Skip to content

Instantly share code, notes, and snippets.

@martinrusev
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinrusev/347b8693caf6e87f57c2 to your computer and use it in GitHub Desktop.
Save martinrusev/347b8693caf6e87f57c2 to your computer and use it in GitHub Desktop.
"use strict";
var app = angular.module('RickshawApp', [])
.factory('RickshawDataService', function($http){
return {
GetData: function() {
return $http.get('http://192.168.174.1:8080/data.json/?callback=JSON_CALLBACK')
.then(function(result) {
return result.data;
});
} // get_data
}
})
.controller('RickshawTimer', function($scope, $timeout){
$scope.when = function( booleanExpr, trueValue, falseValue) {
return booleanExpr ? trueValue : falseValue;
};
var isPaused = false;
$scope.pause = function() {
isPaused = true;
}
$scope.resume = function() {
isPaused = false;
$scope.runCounter();
}
$scope.runCounter = function() {
if (isPaused) return;
console.log('test');
$timeout($scope.runCounter, 1000);
}
$scope.toggleCounter = function() {
isPaused = !isPaused;
$scope.runCounter();
};
$scope.isPaused = function() {
return isPaused;
};
$scope.runCounter();
})
.directive('rickshawChart', function($window, $timeout) {
return {
restrict: 'EA',
controller: ['$scope', '$http', 'RickshawDataService',
function($scope, $http, RickshawDataService) {
$scope.get_initial_data = function() {
RickshawDataService.GetData().then(function(data){
$scope.data = data
})
}
}],
link: function(scope, element, attrs) {
scope.data = [{x: 0, y:0 }];
scope.get_initial_data();
var w = angular.element($window);
var el;
scope.get_window_width = function () {
return w[0].innerWidth
}
scope.$watch("data", function () {
scope.render();
});
scope.$watch(scope.get_window_width, function () {
scope.render();
});
w.bind('resize', function () {
scope.$apply();
});
scope.render = function() {
el = element[0]
el.innerHTML = '';
var graph = new Rickshaw.Graph( {
element: el,
renderer: 'bar',
width: element.parent()[0].offsetWidth,
height: el.clientHeight,
series: [{
name: 'test',
color: '#ccc',
data: scope.data
}]
});
graph.render();
}; // scope.render
} // link
}; // return
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment