Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ecgApp.controller('EcgController', ['$scope', 'chartDataFactory', 'bucketDataFactory', 'dataFactory', function($scope, chartDataFactory, bucketDataFactory, dataFactory){
- $scope.init = function() {
- $scope.loadBuckets();
- $scope.loadChart();
- $scope.loadClients();
- };
- $scope.loadChart = function(clientId) {
- chartDataFactory.getChartData(clientId)
- .then(function (response){
- var data = response.data;
- $scope.clientName = data.clientName;
- $scope.clientId = data.clientId;
- $scope.chartInterval = data.interval;
- $scope.chartData = data.dataPoints;
- $scope.chartPeriod = data.period;
- var ticks = 7;
- if ($scope.chartInterval == 'minute') {
- ticks = 24;
- }
- $scope.chart = c3.generate({
- bindto: '#chart',
- data: {
- json: $scope.chartData,
- types: {
- 'value': 'spline',
- 'standardDeviationMin': 'area',
- 'standardDeviationMax': 'area'
- },
- keys: {
- x: 'timestamp',
- value: ['standardDeviationMax', 'standardDeviationMin', 'value']
- },
- names: {
- value: 'impressions per ' + $scope.chartInterval + ' (last ' + $scope.chartPeriod + ')',
- standardDeviationMax: 'zone of normality',
- standardDeviationMin: ''
- },
- colors: {
- 'standardDeviationMin': '#f5f5f5',
- 'standardDeviationMax': 'rgb(215, 248, 232)'
- }
- },
- point: {
- show: false
- },
- tooltip: {
- show: false
- },
- axis: {
- x: {
- type: 'timeseries',
- tick: {
- format: function(d){
- if ($scope.chartInterval == 'minute'){
- return moment.unix(d).format('Do MMM HH:mm:ss');
- }
- else {
- return moment.unix(d).format('Do MMM');
- }
- },
- count: ticks
- }
- }
- }
- });
- }, function(error) {
- $scope.status = 'Unable to retrieve chart data ' + error.message;
- });
- };
- $scope.loadBuckets = function() {
- bucketDataFactory.getBucketData()
- .then(function (response){
- $scope.criticalLowClients = response.data.criticalLowClients;
- $scope.warningLowClients = response.data.warningLowClients;
- $scope.warningHighClients = response.data.warningHighClients;
- $scope.criticalHighClients = response.data.criticalHighClients;
- }, function(error) {
- $scope.status = 'Unable to retrieve bucket data ' + error.message;
- });
- };
- $scope.loadClients = function() {
- dataFactory.getClientData()
- .then(function (response){
- data = response.data
- $scope.clients = data;
- $scope.name = '';
- $scope.onItemSelected = function() {
- console.log('selected=' + $scope.name);
- };
- }, function(error) {
- $scope.status = 'Unable to retrieve clients data ' + error.message;
- });
- };
- $scope.foo = "Foo";
- $scope.eb = new EventBus(window.location.protocol + '//' + window.location.hostname + ':' + window.location.port + '/eventbus');
- $scope.eb.onopen = function() {
- $scope.eb.registerHandler('buckets', function(err, msg) {
- if (err == null) {
- $scope.criticalLowClients = msg.body.criticalLowClients;
- $scope.warningLowClients = msg.body.warningLowClients;
- $scope.warningHighClients = msg.body.warningHighClients;
- $scope.criticalHighClients = msg.body.criticalHighClients;
- $scope.$apply();
- $scope.loadChart($scope.clientId);
- }
- });
- };
- }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement