Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.64 KB | None | 0 0
  1. ecgApp.controller('EcgController', ['$scope', 'chartDataFactory', 'bucketDataFactory', 'dataFactory', function($scope, chartDataFactory, bucketDataFactory, dataFactory){
  2.  
  3. $scope.init = function() {
  4. $scope.loadBuckets();
  5. $scope.loadChart();
  6. $scope.loadClients();
  7. };
  8.  
  9. $scope.loadChart = function(clientId) {
  10. chartDataFactory.getChartData(clientId)
  11. .then(function (response){
  12. var data = response.data;
  13. $scope.clientName = data.clientName;
  14. $scope.clientId = data.clientId;
  15. $scope.chartInterval = data.interval;
  16. $scope.chartData = data.dataPoints;
  17. $scope.chartPeriod = data.period;
  18. var ticks = 7;
  19. if ($scope.chartInterval == 'minute') {
  20. ticks = 24;
  21. }
  22. $scope.chart = c3.generate({
  23. bindto: '#chart',
  24. data: {
  25. json: $scope.chartData,
  26. types: {
  27. 'value': 'spline',
  28. 'standardDeviationMin': 'area',
  29. 'standardDeviationMax': 'area'
  30. },
  31. keys: {
  32. x: 'timestamp',
  33. value: ['standardDeviationMax', 'standardDeviationMin', 'value']
  34. },
  35. names: {
  36. value: 'impressions per ' + $scope.chartInterval + ' (last ' + $scope.chartPeriod + ')',
  37. standardDeviationMax: 'zone of normality',
  38. standardDeviationMin: ''
  39. },
  40. colors: {
  41. 'standardDeviationMin': '#f5f5f5',
  42. 'standardDeviationMax': 'rgb(215, 248, 232)'
  43. }
  44. },
  45. point: {
  46. show: false
  47. },
  48. tooltip: {
  49. show: false
  50. },
  51. axis: {
  52. x: {
  53. type: 'timeseries',
  54. tick: {
  55. format: function(d){
  56. if ($scope.chartInterval == 'minute'){
  57. return moment.unix(d).format('Do MMM HH:mm:ss');
  58. }
  59. else {
  60. return moment.unix(d).format('Do MMM');
  61. }
  62. },
  63. count: ticks
  64. }
  65. }
  66. }
  67. });
  68. }, function(error) {
  69. $scope.status = 'Unable to retrieve chart data ' + error.message;
  70. });
  71. };
  72.  
  73. $scope.loadBuckets = function() {
  74. bucketDataFactory.getBucketData()
  75. .then(function (response){
  76. $scope.criticalLowClients = response.data.criticalLowClients;
  77. $scope.warningLowClients = response.data.warningLowClients;
  78. $scope.warningHighClients = response.data.warningHighClients;
  79. $scope.criticalHighClients = response.data.criticalHighClients;
  80. }, function(error) {
  81. $scope.status = 'Unable to retrieve bucket data ' + error.message;
  82. });
  83. };
  84.  
  85. $scope.loadClients = function() {
  86. dataFactory.getClientData()
  87. .then(function (response){
  88. data = response.data
  89. $scope.clients = data;
  90. $scope.name = '';
  91. $scope.onItemSelected = function() {
  92. console.log('selected=' + $scope.name);
  93. };
  94. }, function(error) {
  95. $scope.status = 'Unable to retrieve clients data ' + error.message;
  96. });
  97. };
  98. $scope.foo = "Foo";
  99.  
  100.  
  101. $scope.eb = new EventBus(window.location.protocol + '//' + window.location.hostname + ':' + window.location.port + '/eventbus');
  102.  
  103. $scope.eb.onopen = function() {
  104. $scope.eb.registerHandler('buckets', function(err, msg) {
  105. if (err == null) {
  106. $scope.criticalLowClients = msg.body.criticalLowClients;
  107. $scope.warningLowClients = msg.body.warningLowClients;
  108. $scope.warningHighClients = msg.body.warningHighClients;
  109. $scope.criticalHighClients = msg.body.criticalHighClients;
  110. $scope.$apply();
  111. $scope.loadChart($scope.clientId);
  112. }
  113. });
  114. };
  115.  
  116. }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement