multi_ng.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. angular.module('app', ['ui.bootstrap.datetimepicker', 'app.util'])
  2. .config(function($interpolateProvider) {
  3. $interpolateProvider.startSymbol('[[');
  4. $interpolateProvider.endSymbol(']]');
  5. })
  6. .controller('MultiCtrl', MultiCtrl)
  7. function MultiCtrl(FlotServ, $scope, $interval, $timeout) {
  8. var vm = this;
  9. // 全局的参数
  10. vm.defaultGlobalParam = {
  11. start: '',
  12. end: '',
  13. cf: 'AVERAGE', // MIN, MAX
  14. graph_type: 'h', // h Endpoint视角; k Counter视角
  15. sum: 'off' // off
  16. };
  17. vm.globalParam = angular.copy(vm.defaultGlobalParam);
  18. // var urlH = '/chart/h';
  19. // var urlK = '/chrt/k;
  20. var backendParam = FlotServ.getParam(); // 后端渲染出来的参数
  21. vm.globalParam.graph_type = backendParam.graph_type;
  22. vm.chart = {}; // 前端的图, 对应后端的返回
  23. vm.configs = []; // 绘图的数据, 多个
  24. vm.data = []; // 缓存的绘图数据, 不会改变
  25. // vm.param = angular.copy(defaultParam);
  26. vm.all = true; // 是否全选
  27. vm.reverse = false; // 是否反选
  28. vm.checkAll = checkAll;
  29. vm.checkReverse = checkReverse;
  30. vm.checkSearch = checkSearch;
  31. vm.reset = reset;
  32. vm.show = show;
  33. $scope.$watch('vm.globalParam.graph_type', function(newVal, oldVal) {
  34. if (newVal !== oldVal) {
  35. // change url
  36. var url = window.location.href;
  37. var newUrl;
  38. if (newVal === 'k') {
  39. newUrl = url.replace('graph_type=h', 'graph_type=k').replace('graph_type=a', 'graph_type=k');
  40. } else if (newVal === 'h') {
  41. newUrl = url.replace('graph_type=k', 'graph_type=h').replace('graph_type=a', 'graph_type=h');
  42. } else {
  43. newUrl = url.replace('graph_type=h', 'graph_type=a').replace('graph_type=k', 'graph_type=a');
  44. }
  45. window.location.href = newUrl;
  46. }
  47. });
  48. active(vm.globalParam);
  49. // reset 重置
  50. function reset() {
  51. vm.globalParam = angular.copy(vm.defaultGlobalParam);
  52. }
  53. // show 看图
  54. function show() {
  55. active(vm.globalParam);
  56. }
  57. // active
  58. function active(param) {
  59. // console.log(FlotServ.getUrls());
  60. var p = angular.copy(param);
  61. if (angular.isDate(p.start)) {
  62. p.start = +p.start/1000;
  63. }
  64. if (angular.isDate(p.end)) {
  65. p.end = +p.end/1000;
  66. }
  67. FlotServ.getMultiDataById(p).then(function(ret) {
  68. // [{data: {}}, {data: {}}, {data: {}}]
  69. // console.log(ret);
  70. var data;
  71. data = _.map(ret, function(i) {
  72. var o = {};
  73. o.config = FlotServ.parseData(i.data);
  74. o.title = i.data.title;
  75. return o;
  76. });
  77. // console.log(data);
  78. vm.configs = data;
  79. });
  80. }
  81. // 全选
  82. function checkAll() {
  83. if (vm.all) {
  84. _.each(vm.data, function(d) {
  85. d.check = true;
  86. });
  87. } else {
  88. _.each(vm.data, function(d) {
  89. d.check = false;
  90. });
  91. }
  92. // vm.config = vm.data;
  93. }
  94. // 反选
  95. function checkReverse () {
  96. if (vm.reverse) {
  97. vm.all = false;
  98. _.each(vm.data, function(d) {
  99. d.check = !d.check;
  100. });
  101. }
  102. // vm.config = vm.data;
  103. }
  104. // 确定
  105. function checkSearch() {
  106. var data2 = [];
  107. _.each(vm.data, function(d) {
  108. if (d.check) {
  109. data2.push(d);
  110. }
  111. });
  112. vm.config = data2;
  113. // vm.series = data2;
  114. // flot = $.plot(el, val, FlotServ.getConfig());
  115. }
  116. }