f74928c354cfcd4608474e3318f3e406ca7b10a9
[usecase-ui.git] /
1 /*
2  Copyright (C) 2017 CMCC, Inc. and others. All rights reserved.
3
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7
8  http://www.apache.org/licenses/LICENSE-2.0
9
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15  */
16 app.controller('pertabCtrl', ['$scope', '$http', '$routeParams', function ($scope, $http, $routeParams) {
17     $scope.tabes = [
18         {title: 'one hour'},
19         {title: 'one day'},
20         {title: 'one month'},
21         {title: 'one year'}
22     ];
23     $scope.barChart = function (unit) {
24         $http.get(global_url + '/performance/diagram/' + unit + '/' + permanceId, {
25             headers: {
26                 'Access-Control-Allow-Origin': "*",
27                 "Content-Type": "application/json"
28             }
29         })
30             .success(function (data) {
31                 if (unit === "hour") {
32                     $scope.valuess = [];
33                     for(var i=0;i<4;i++){
34                         $scope.valuess[i] = [
35                             {"x": '15min', "y": 4}, {"x": '30min', "y": 4}, {"x": '45min', "y": 12},
36                             {"x": '60min', "y": 3.27}
37                         ];
38                     };
39                     var v = 0;
40                     var i = 0;
41                     angular.forEach(data, function (obj) {
42                         for (var j = 0; j < obj.length; j++, i++) {
43                             if (i >= 4) {
44                                 v++;
45                                 i = 0;
46                             }
47                             $scope.valuess[v][i].y = obj[j];
48                         }
49                     });
50                     console.info($scope.valuess);
51                     for (var i = 0; i < 5; i++) {
52                         window.setTimeout(function () {
53                             redraw("", $scope.valuess);
54                         }, 1500);
55                     };
56                 }
57                 if (unit === "day") {
58                     $scope.valuess = [];
59                     for(var i=0;i<4;i++){
60                         $scope.valuess[i] = [
61                             { "x":'1h' , "y":4}, { "x":'2h' , "y":4}, { "x":'3h' , "y":12},
62                             { "x":'4h' , "y":3.27}, { "x":'5h' , "y":34}, { "x":'6h' , "y":34}, { "x":'7h' , "y":34},
63                             { "x":'8h' , "y":34}, { "x":'9h' , "y":34}, { "x":'10h' , "y":34}, { "x":'11h' , "y":34},
64                             { "x":'12h' , "y":56}, { "x":'13h' , "y":34}, { "x":'14h' , "y":34}, { "x":'15h' , "y":34},
65                             { "x":'16h' , "y":12}, { "x":'17h' , "y":34}, { "x":'18h' , "y":50}, { "x":'19h' , "y":34},
66                             { "x":'20h' , "y":34}, { "x":'21h' , "y":54}, { "x":'22h' , "y":34}, { "x":'23h' , "y":34},
67                             { "x":'24h' , "y":36}
68                         ];
69                     };
70                     var v = 0;
71                     var i = 0;
72                     angular.forEach(data, function (obj) {
73                         for (var j = 0; j < obj.length; j++, i++) {
74                             if (i >= 24) {
75                                 v++;
76                                 i = 0;
77                             }
78                             $scope.valuess[v][i].y = obj[j];
79                         }
80                     });
81                     console.info($scope.valuess);
82                     for (var i = 0; i < 5; i++) {
83                         window.setTimeout(function () {
84                             redraw("1", $scope.valuess);
85                         }, 1500);
86                     };
87                 }
88                 if (unit === "month") {
89                     $scope.valuess = [];
90                     for(var i=0;i<4;i++){
91                         $scope.valuess[i] =  [
92                             { "x":'1d' , "y":4}, { "x":'2d' , "y":4}, { "x":'3d' , "y":12},
93                             { "x":'4d' , "y":3.27}, { "x":'5d' , "y":34},{ "x":'6d' , "y":4}, { "x":'7d' , "y":4}, { "x":'8d' , "y":12},
94                             { "x":'9d' , "y":3.27}, { "x":'10d' , "y":34}, { "x":'11d' , "y":34}, { "x":'12d' , "y":34},  { "x":'13d' , "y":4}, { "x":'14d' , "y":4}, { "x":'15' , "y":12},
95                             { "x":'16d' , "y":3.27}, { "x":'17d' , "y":34},{ "x":'18d' , "y":4}, { "x":'19d' , "y":4}, { "x":'20d' , "y":12},
96                             { "x":'21d' , "y":3.27}, { "x":'22d' , "y":34}, { "x":'23d' , "y":34}, { "x":'24d' , "y":34}, { "x":'25d' , "y":4}, { "x":'26d' , "y":12},
97                             { "x":'27d' , "y":3.27}, { "x":'28d' , "y":34}, { "x":'29d' , "y":34}, { "x":'30d' , "y":34}, { "x":'31d' , "y":34}
98                         ];
99                     };
100                     var v = 0;
101                     var i = 0;
102                     angular.forEach(data, function (obj) {
103                         for (var j = 0; j < obj.length; j++, i++) {
104                             if (i >= 31) {
105                                 v++;
106                                 i = 0;
107                             }
108                             $scope.valuess[v][i].y = obj[j];
109                         }
110                     });
111                     console.info($scope.valuess);
112                     for (var i = 0; i < 5; i++) {
113                         window.setTimeout(function () {
114                             redraw("2", $scope.valuess);
115                         }, 1500);
116                     };
117                 }
118                 if (unit === "year") {
119                     $scope.valuess = [];
120                     for(var i=0;i<12;i++){
121                         $scope.valuess[i] = [
122                             {"x": 'Jan', "y": 4}, {"x": 'Feb', "y": 4}, {"x": 'Mar', "y": 12},
123                             {"x": 'Apr', "y": 3.27},  {"x": 'May', "y": 4}, {"x": 'June', "y": 4}, {"x": 'July', "y": 12},
124                             {"x": 'Aug', "y": 3.27},  {"x": 'Sept', "y": 4}, {"x": 'Oct', "y": 4}, {"x": 'Nov', "y": 12},
125                             {"x": 'Jan', "y": 3.27}
126                         ];
127                     };
128                     var v = 0;
129                     var i = 0;
130                     angular.forEach(data, function (obj) {
131                         for (var j = 0; j < obj.length; j++, i++) {
132                             if (i >= 12) {
133                                 v++;
134                                 i = 0;
135                             }
136                             $scope.valuess[v][i].y = obj[j];
137                         }
138                     });
139                     console.info($scope.valuess);
140                     for (var i = 0; i < 5; i++) {
141                         window.setTimeout(function () {
142                             redraw("3", $scope.valuess);
143                         }, 1500);
144                     };
145                 }
146             });
147     };
148     $scope.oneHour = function () {
149         changerotate(0);
150         $scope.barChart('hour');
151
152     };
153     $scope.oneHour();
154     $scope.oneDay = function () {
155         changerotate(90);
156         $scope.barChart('day');
157     };
158     $scope.oneMonth = function () {
159         changerotate(80);
160         $scope.barChart('month');
161
162     };
163     $scope.oneYear = function () {
164         changerotate(0);
165         $scope.barChart('year');
166     };
167 }]);