1 app.controller('ChartController', function ($scope, $rootScope, $timeout, $window, $http, $routeParams,modalService) {
3 //alert($scope.chartType.value);
5 $scope.populateChrtWzdFields = function() {
7 $scope.reportRunJson = {};
8 // console.log($routeParams.reportId);
9 $http.get("raptor.htm?action=chart.json&c_master="+$routeParams.reportId).then(function (response) {
10 //$scope.myData = JSON.stringify(response.data);
11 // response.data.rangeAxisList[0].rangeColorJSON = {};
12 $scope.reportRunJson = response.data;
13 // $scope.chrtheight = $scope.reportRunJson.height;
14 // console.log(JSON.stringify($scope.reportRunJson));
15 /* if ($scope.reportRunJson.showTitle==false)
16 $scope.reportRunJson.showTitle="false";
18 $scope.reportRunJson.showTitle="true"; */
20 console.log($scope.reportRunJson);
27 if ($scope.reportRunJson.chartTypeJSON) {
28 var chrtTypeValue = $scope.reportRunJson.chartTypeJSON.value;
29 for(var i = 0; i < $scope.chartTypes.length; i++) {
30 var obj = $scope.chartTypes[i];
31 //console.log(obj.id);
32 if ($scope.chartTypes[i].value==chrtTypeValue) {
33 $scope.reportRunJson.chartTypeJSON.index=$scope.chartTypes[i].index;
34 $scope.reportRunJson.chartTypeJSON.title=$scope.chartTypes[i].title;
41 if ($scope.reportRunJson.domainAxisJSON) {
42 var domaninAxisValue = $scope.reportRunJson.domainAxisJSON.value;
43 for(var i = 0; i < $scope.reportRunJson.chartColumnJSONList.length; i++) {
44 if ($scope.reportRunJson.chartColumnJSONList[i].value==domaninAxisValue) {
45 $scope.reportRunJson.domainAxisJSON.index=$scope.reportRunJson.chartColumnJSONList[i].index;
46 $scope.reportRunJson.domainAxisJSON.title=$scope.reportRunJson.chartColumnJSONList[i].title;
53 if ($scope.reportRunJson.categoryAxisJSON) {
54 var categoryAxisValue = $scope.reportRunJson.categoryAxisJSON.value;
55 for(var i = 0; i < $scope.reportRunJson.chartColumnJSONList.length; i++) {
56 if ($scope.reportRunJson.chartColumnJSONList[i].value==categoryAxisValue) {
57 $scope.reportRunJson.categoryAxisJSON.index=$scope.reportRunJson.chartColumnJSONList[i].index;
58 $scope.reportRunJson.categoryAxisJSON.title=$scope.reportRunJson.chartColumnJSONList[i].title;
64 //Set range axis label
65 if ($scope.reportRunJson.rangeAxisList) {
66 for(var j = 0; j < $scope.reportRunJson.rangeAxisList.length; j++) {
68 if ($scope.reportRunJson.rangeAxisList[j].rangeAxisLabelJSON) {
69 var rangeAxisLabelValue = $scope.reportRunJson.rangeAxisList[j].rangeAxisLabelJSON.value;
70 for(var i = 0; i < $scope.reportRunJson.chartColumnJSONList.length; i++) {
71 if ($scope.reportRunJson.chartColumnJSONList[i].value==rangeAxisLabelValue) {
72 $scope.reportRunJson.rangeAxisList[j].rangeAxisLabelJSON.index=$scope.reportRunJson.chartColumnJSONList[i].index;
73 $scope.reportRunJson.rangeAxisList[j].rangeAxisLabelJSON.title=$scope.reportRunJson.chartColumnJSONList[i].title;
83 if ($scope.reportRunJson.rangeAxisList) {
84 for(var j = 0; j < $scope.reportRunJson.rangeAxisList.length; j++) {
85 if ($scope.reportRunJson.rangeAxisList[j].rangeLineTypeJSON != null && $scope.reportRunJson.rangeAxisList[j].rangeLineTypeJSON.value != ""
86 && $scope.reportRunJson.rangeAxisList[j].rangeLineTypeJSON.value != null) {
87 var lineTypeValue = $scope.reportRunJson.rangeAxisList[j].rangeLineTypeJSON.value;
88 for(var i = 0; i < $scope.lineTypes.length; i++) {
89 if ($scope.lineTypes[i].value==lineTypeValue) {
90 $scope.reportRunJson.rangeAxisList[j].rangeLineTypeJSON.index=$scope.lineTypes[i].index;
91 $scope.reportRunJson.rangeAxisList[j].rangeLineTypeJSON.title=$scope.lineTypes[i].title;
96 $scope.reportRunJson.rangeAxisList[j].rangeLineTypeJSON = null;
102 if ($scope.reportRunJson.rangeAxisList) {
103 for(var j = 0; j < $scope.reportRunJson.rangeAxisList.length; j++) {
104 if ($scope.reportRunJson.rangeAxisList[j].rangeColorJSON != null && $scope.reportRunJson.rangeAxisList[j].rangeColorJSON.value != ""
105 && $scope.reportRunJson.rangeAxisList[j].rangeColorJSON.value != null) {
106 var colorValue = $scope.reportRunJson.rangeAxisList[j].rangeColorJSON.value;
108 for(var i = 0; i < $scope.rangeColors.length; i++) {
110 if ($scope.rangeColors[i].value==colorValue) {
111 $scope.reportRunJson.rangeAxisList[j].rangeColorJSON.index=$scope.rangeColors[i].index;
112 $scope.reportRunJson.rangeAxisList[j].rangeColorJSON.title=$scope.rangeColors[i].title;
116 $scope.reportRunJson.rangeAxisList[j].rangeColorJSON = null;
124 /* var data = $.param({
125 json: JSON.stringify($scope.reportRunJson)
128 $http.post("/ecomp-sdk-app/testraptorchart", JSON.stringify($scope.reportRunJson)).success(function(data, status) {
137 /* $scope.chrtwidth = $scope.reportRunJson.width;
139 $scope.chrtheight = $scope.reportRunJson.height;
140 $scope.title="false";
141 $scope.domainAxes = $scope.reportRunJson.chartColumnJSONList;
142 $scope.categories = $scope.reportRunJson.chartColumnJSONList;
143 $scope.rangeAxes = $scope.reportRunJson.chartColumnJSONList; */
145 // $scope.Color = $scope.rangeColors;
146 // $scope.lineType = $scope.lineTypes;
147 // $scope.praxis = $scope.reportRunJson.primaryAxisLabel;
148 // $scope.secaxis = $scope.reportRunJson.secondaryAxisLabel;
149 // $scope.raxisminrange = $scope.reportRunJson.minRange;
150 // $scope.raxismaxrange = $scope.reportRunJson.maxRange;
151 // $scope.reportRunJson.legendangle = "up_45";
152 $scope.legend = "true";
153 // $scope.animate = "true";
154 // $scope.topmargin = $scope.reportRunJson.topMargin;
155 // $scope.bottommargin = $scope.reportRunJson.bottomMargin;
156 // $scope.leftmargin = $scope.reportRunJson.leftMargin;
157 // $scope.rightmargin = $scope.reportRunJson.rightMargin;
164 $scope.saveChartData = function() {
165 //console.log(JSON.stringify($scope.reportRunJson));
167 //Converting string variables to numbers
168 $scope.reportRunJson.commonChartOptions.rightMargin = Number($scope.reportRunJson.commonChartOptions.rightMargin);
169 $scope.reportRunJson.commonChartOptions.topMargin = Number($scope.reportRunJson.commonChartOptions.topMargin);
170 $scope.reportRunJson.commonChartOptions.bottomMargin = Number($scope.reportRunJson.commonChartOptions.bottomMargin);
171 $scope.reportRunJson.commonChartOptions.leftMargin = Number($scope.reportRunJson.commonChartOptions.leftMargin);
173 //Concatenate range Y axis with range label with pipe delimiter
174 /* if ($scope.reportRunJson.rangeAxisList) {
176 for(var j = 0; j < $scope.reportRunJson.rangeAxisList.length; j++) {
178 if ($scope.reportRunJson.rangeAxisList[j].rangeYAxis) {
179 if ($scope.reportRunJson.rangeAxisList[j].rangeAxisLabelJSON != "" && $scope.reportRunJson.rangeAxisList[j].rangeAxisLabelJSON != null) {
180 $scope.reportRunJson.rangeAxisList[j].rangeYAxis =
181 $scope.reportRunJson.rangeAxisList[j].rangeYAxis + "|"+ $scope.reportRunJson.rangeAxisList[j].rangeAxisLabelJSON.value;
183 //document.getElementById('yaxs').value = $scope.reportRunJson.rangeAxisList[j].rangeYAxis.substring(0,$scope.reportRunJson.rangeAxisList[j].rangeYAxis.indexOf('|'));
186 if ($scope.reportRunJson.rangeAxisList[j].rangeAxisLabelJSON != "" && $scope.reportRunJson.rangeAxisList[j].rangeAxisLabelJSON != null)
187 $scope.reportRunJson.rangeAxisList[j].rangeYAxis = "|"+ $scope.reportRunJson.rangeAxisList[j].rangeAxisLabelJSON.value;
195 if ($scope.reportRunJson.categoryAxisJSON == "") {
196 console.log('Inside categoryAxisJSON value');
197 $scope.reportRunJson.categoryAxisJSON = {};
198 $scope.reportRunJson.categoryAxisJSON.value = -1;
199 console.log('$scope.reportRunJson.categoryAxisJSON',$scope.reportRunJson.categoryAxisJSON);
203 $http.post("save_chart", JSON.stringify($scope.reportRunJson)).success(function(data, status) {
204 // console.log(data);
205 // console.log(status);
206 $scope.successSubmit=true;
207 // modalService.showSuccess("Success","Chart Wizard details have been successfully submitted.");
213 /* $http.post("/ecomp-sdk-app/testraptorchart", $scope.reportRunJson).then(function(response) {
214 console.log(response.data);
215 console.log(response.status);
220 //$scope.samplearray = ["abc","test"];
223 $scope.addRangeAxisRow = function (rangeaxisitem) {
228 $scope.reportRunJson.rangeAxisList.push({
232 "value":rangeaxisitem.rangeColor.value,
233 "title":rangeaxisitem.rangeColor.title
238 "value":rangeaxisitem.rangeLineType.value,
239 "title":rangeaxisitem.rangeLineType.title
244 "value":rangeaxisitem.rangeaxisLabel.value,
245 "title":rangeaxisitem.rangeaxisLabel.value
251 // alert($scope.reportRunJson.rangeAxisList.length);
252 console.log($scope.reportRunJson.rangeAxisList);
256 $scope.removeRangeAxisRow = function (index) {
257 $scope.reportRunJson.rangeAxisList.splice(index, 1);
258 //console.log($scope.hardCodeReport.rangeAxisList)
263 /*$scope.saveProfile = function() {
264 var uuu = "profile/saveProfile?profile_id=" + $scope.profileId;;
265 var postData={profile: $scope.profile,
266 selectedCountry:$scope.selectedCountry!=null?$scope.selectedCountry.value:"",
267 selectedState:$scope.stateList.selected!=null?$scope.stateList.selected.value:"",
268 selectedTimeZone:$scope.selectedTimeZone!=null?$scope.selectedTimeZone.value:""
274 contentType: 'application/json',
275 data: JSON.stringify(postData),
276 success : function(data){
277 modalService.showSuccess("Success","Update Successful.");
279 error : function(data){
280 modalService.showFailure("Fail","Error while saving.");
286 /* $scope.actionClicked = function(){
288 if ($scope.chartType=="Bar Chart") {
290 } else if ($scope.chartType=="Time Series/Area Chart") {
296 $scope.init = function () {
297 // console.time("In init");
299 $scope.populateChrtWzdFields();
300 // $scope.saveChartData();
306 /*$scope.accgroups = [
308 title: "Accordion Item #1",
309 content:"Unit test me bro! Proin eu quam malesuada, accumsan velit eu, tristique orci. Donec neque nisl, dignissim ut hendrerit sit amet, tempor id erat. Donec fermentum commodo semper. Sed lectus odio, egestas non volutpat eu, venenatis eu turpis. Donec eget fringilla lorem. Fusce sit amet semper velit. ",
313 title: "Accordion Item #2",
314 content: "Lint me too! Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi eleifend aliquam eros quis fringilla. Integer eu justo turpis. Nam mauris augue, posuere interdum dignissim sed, tempor sit amet neque. In nec tortor id nibh sollicitudin aliquam sit amet ac augue",
318 title: "Accordion Item #3",
319 content: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi eleifend aliquam eros quis fringilla. Integer eu justo turpis. Nam mauris augue, posuere interdum dignissim sed, tempor sit amet neque. In nec tortor id nibh sollicitudin aliquam sit amet ac augue",
324 $scope.domainItems = [{title:"Domain Axis1", content:"Test1", open: false},{title:"Domain Axis2", content:"Test2", open: false}];
326 $scope.chartTypes = [
327 {index: 0, value: 'BarChart3D', title: 'Bar Chart'},
328 {index: 1, value: 'TimeSeriesChart', title: 'Time Series/Area Chart'},
329 {index: 2, value: 'PieChart', title: 'Pie Chart'},
330 {index: 3, value: 'AnnotationChart', title: 'Annotation Chart'},
331 {index: 4, value: 'FlexTimeChart', title: 'Flexible Time Chart'}
334 /* $scope.domainAxes = [
335 {index: 0, value: 'scenario_name', title: 'scenario_name'},
336 {index: 1, value: 'total_traffic_in_PB', title: 'Total Traffic in PB'},
337 {index: 2, value: 'Avg Utilization Day', title: 'Avg Utilization Day'}
341 $scope.categories = [
342 {index: 0, value: 'scenario_name', title: 'scenario_name'},
343 {index: 1, value: 'total_traffic_in_PB', title: 'Total Traffic in PB'},
344 {index: 2, value: 'Avg Utilization Day', title: 'Avg Utilization Day'}
348 $scope.rangeColors = [
350 {index: 0, value: "#1f77b4",title: "Dodger Blue"},
351 {index: 1, value: "#ff7f0e",title: "Vivid orange"},
352 {index: 2, value: "#2ca02c",title: "Forest Green"},
353 {index: 3, value: "#8c864b",title: "Greenish Red"},
354 {index: 4, value: "#9467bd",title: "Desaturated violet"},
355 {index: 5, value: "#8c564b",title: "Dark moderate red"},
356 {index: 6, value: "#e377c2",title: "Soft pink"},
357 {index: 7, value: "#7f7f7f",title: "Dark gray"},
358 {index: 8, value: "#bcbd22",title: "Strong yellow"},
359 {index: 9, value: "#17becf",title: "Strong cyan"},
360 {index: 10, value: "#dc143c",title: "Vivid red"},
361 {index: 11, value: "#800080",title: "Dark magenta"},
362 {index: 12, value: "#0000FF",title: "Blue"},
363 {index: 13, value: "#008000",title: "Dark lime green"},
364 {index: 14, value: "#D2691E",title: "Reddish Orange"},
365 {index: 15, value: "#FF0000",title: "Red"},
366 {index: 16, value: "#000000",title: "Black"},
367 {index: 17, value: "#DB7093",title: "Pink"},
368 {index: 18, value: "#FF00FF",title: "Pure Magenta"},
369 {index: 19, value: "#7B68EE",title: "Soft blue"},
370 {index: 20, value: "#1f77b6",title: "Strong blue"},
371 {index: 21, value: "#9edae5",title: "Very soft cyan"},
372 {index: 22, value: "#393b79",title: "Dark Blue"},
373 {index: 23, value: "#5254a3",title: "Dark moderate Blue"},
374 {index: 24, value: "#6b6ecf",title: "Slightly desaturated blue"},
375 {index: 25, value: "#9c9ede",title: "Very soft blue"},
376 {index: 26, value: "#637939",title: "Dark Green"},
377 {index: 27, value: "#8ca252",title: "Dark moderate green"},
378 {index: 28, value: "#b5cf6b",title: "Slightly desaturated green"},
379 {index: 29, value: "#cedb9c",title: "Desaturated Green"},
382 {index: 30, value: "#00FFFF",title: "Aqua"},
383 {index: 31, value: "#000000",title: "Black"},
384 {index: 32, value: "#0000FF",title: "Blue"},
385 {index: 33, value: "#FF00FF",title: "Fuchsia"},
386 {index: 34, value: "#808080",title: "Gray"},
387 {index: 35, value: "#008000",title: "Green"},
388 {index: 36, value: "#00FF00",title: "Lime"},
389 {index: 37, value: "#800000",title: "Maroon"},
390 {index: 38, value: "#000080",title: "Navy"},
391 {index: 39, value: "#808000",title: "Olive"},
392 {index: 40, value: "#FF9900",title: "Orange"},
393 {index: 41, value: "#800080",title: "Purple"},
394 {index: 42, value: "#FF0000",title: "Red"},
395 {index: 43, value: "#C0C0C0",title: "Silver"},
396 {index: 44, value: "#008080",title: "Teal"},
397 {index: 45, value: "#FFFFFF",title: "White"},
398 {index: 46, value: "#FFFF00",title: "Yellow"}
403 {index: 0, value: 'default', title: 'Default'},
404 {index: 1, value: 'dotted_lines', title: 'Dotted Lines'},
405 {index: 2, value: 'dashed_lines', title: 'Dashed Lines'}
410 $scope.hardCodeReport= {
412 "reportName":"Test: Line Chart",
419 "chartColumnJSONList":[
423 "title":"traffic_date",
433 "formfield_comments":null,
435 "chartSqlWhole":"SELECT traffic_date tr0, traffic_date tr0_1,util_perc ut1, 1 FROM portal.demo_util_chart ORDER BY 1",
436 "chartAvailable":true,
437 "chartType":{"index": "", "value": "Bar Chart", "title": ""},
442 "staggerLabels":false,
447 "title":"traffic_date",
458 "hasCategoryAxis":false,
471 "value":"dotted_lines",
480 "title":"traffic_date",
497 "value":"dashed_lines",
506 "title":"traffic_date",
516 "primaryAxisLabel":"testlabel",
517 "secondaryAxisLabel":"testseclabel",
526 var colorValue = $scope.hardCodeReport.rangeAxisList[0].rangeColor.value;
528 //console.log($scope.hardCodeReport.chartType);
530 // prefill range color
531 /* for(var i = 0; i < $scope.rangeColors.length; i++) {
532 var obj = $scope.rangeColors[i];
533 //console.log(obj.id);
534 if ($scope.rangeColors[i].value==colorValue) {
535 $scope.hardCodeReport.rangeAxisList[0].rangeColor.index=$scope.rangeColors[i].index;
536 $scope.hardCodeReport.rangeAxisList[0].rangeColor.title=$scope.rangeColors[i].title;
543 // console.log($scope.hardCodeReport.chartType);
545 // console.log($scope.hardCodeReport.chartType);
547 // console.log($scope.hardCodeReport.rangeAxisList);
548 //prefill rangle line type
549 /* for(var j = 0; j < $scope.hardCodeReport.rangeAxisList.length; j++) {
551 var lineTypeValue = $scope.hardCodeReport.rangeAxisList[j].rangeLineType.value;
552 for(var i = 0; i < $scope.lineTypes.length; i++) {
553 var obj = $scope.lineTypes[i];
554 //console.log(obj.id);
555 if ($scope.lineTypes[i].value==lineTypeValue) {
556 $scope.hardCodeReport.rangeAxisList[j].rangeLineType.index=$scope.lineTypes[i].index;
557 $scope.hardCodeReport.rangeAxisList[j].rangeLineType.title=$scope.lineTypes[i].title;
562 // console.log($scope.hardCodeReport.rangeAxisList);
567 // console.log($scope.hardCodeReport.rangeAxisList[0].rangeColor);
568 /* $scope.hardCodeReport.rangeAxisList[0].rangeColor.index=4;
569 $scope.hardCodeReport.rangeAxisList[0].rangeColor.title="Desaturated violet";*/
572 //console.log($scope.hardCodeReport);
578 /*$scope.reportRunJson =
581 "reportName":"Test: Line Chart",
588 "chartColumnJSONList":[
592 "title":"traffic_date"
600 "formfield_comments":null,
602 "chartSqlWhole":"SELECT traffic_date tr0, traffic_date tr0_1,util_perc ut1, 1 FROM portal.demo_util_chart ORDER BY 1",
603 "chartAvailable":true,
604 "chartType":"TimeSeriesChart",
609 "staggerLabels":false,
613 "hasCategoryAxis":false,
620 "primaryAxisLabel":"",
621 "secondaryAxisLabel":"",
629 $timeout(function() {
630 $rootScope.isViewRendering = false;
636 app.directive('onlyDigits', function () {
641 link: function (scope, element, attrs, ngModel) {
642 if (!ngModel) return;
643 ngModel.$parsers.unshift(function (inputValue) {
644 var digits = inputValue.split('').filter(function (s) { return (!isNaN(s) && s != ' '); }).join('');
645 ngModel.$viewValue = digits;
653 app.directive('onlyCharacters', function () {
658 link: function (scope, element, attrs, ngModel) {
659 if (!ngModel) return;
660 ngModel.$parsers.unshift(function (inputValue) {
661 var digits = inputValue.split('').filter(function (s) { return (isNaN(s) && s != ' '); }).join('');
662 ngModel.$viewValue = digits;