1 appDS2.controller('reportChartController', function ($scope, $rootScope, $timeout, $window, $modal, $http, $routeParams,modalService) {
2 $scope.showLoader = true;
3 $scope.commonOptionOpen = false;
4 $scope.additionalOptionOpen = false;
5 $scope.barChartOptionOpen = false;
6 $scope.timeSeriesChartOptionOpen = false;
7 $scope.selectedChartType = {value:""};
8 $scope.chartTypeOptions = [
9 {value: 'BarChart3D', text: 'Bar Chart'},
10 {value: 'TimeSeriesChart', text: 'Time Series/Area Chart'},
11 {value: 'PieChart', text: 'Pie Chart'},
12 {value: 'AnnotationChart', text: 'Annotation Chart'},
13 {value: 'FlexTimeChart', text: 'Flexible Time Chart'}
16 $scope.populateChrtWzdFields = function() {
17 $scope.reportRunJson = {};
18 $scope.showLoader=true;
19 $http.get("raptor.htm?action=chart.json&c_master="+$routeParams.reportId).then(function (response) {
20 $scope.showLoader=false;
21 $scope.reportRunJson = response.data;
23 if($scope.reportRunJson.commonChartOptions!=null){
24 $scope.reportRunJson.commonChartOptions.animateAnimatedChart = $scope.reportRunJson.commonChartOptions.animateAnimatedChart+"";
25 $scope.reportRunJson.commonChartOptions.hideLegend = $scope.reportRunJson.commonChartOptions.hideLegend + "";
28 $scope.reportRunJson.showTitle = $scope.reportRunJson.showTitle + "";
30 // if barChartOptions is not null
31 if ($scope.reportRunJson.barChartOptions) {
32 $scope.reportRunJson.barChartOptions.displayBarControls = $scope.reportRunJson.barChartOptions.displayBarControls+"";
33 $scope.reportRunJson.barChartOptions.minimizeXAxisTickers = $scope.reportRunJson.barChartOptions.minimizeXAxisTickers+"";
34 $scope.reportRunJson.barChartOptions.stackedChart = $scope.reportRunJson.barChartOptions.stackedChart+"";
35 $scope.reportRunJson.barChartOptions.timeAxis =$scope.reportRunJson.barChartOptions.timeAxis+"";
36 $scope.reportRunJson.barChartOptions.verticalOrientation = $scope.reportRunJson.barChartOptions.verticalOrientation +"";
37 $scope.reportRunJson.barChartOptions.xAxisDateType = $scope.reportRunJson.barChartOptions.xAxisDateType +"";
40 if ($scope.reportRunJson.chartTypeJSON) {
41 var chrtTypeValue = $scope.reportRunJson.chartType;
42 for(var i = 0; i < $scope.chartTypes.length; i++) {
43 if ($scope.chartTypes[i].value==chrtTypeValue) {
44 $scope.reportRunJson.chartTypeJSON.index=$scope.chartTypes[i].index;
45 $scope.reportRunJson.chartTypeJSON.value=$scope.chartTypes[i].value;
46 $scope.reportRunJson.chartTypeJSON.title=$scope.chartTypes[i].title;
53 if ($scope.reportRunJson.domainAxisJSON) {
54 var domaninAxisValue = $scope.reportRunJson.domainAxisJSON.value;
55 for(var i = 0; i < $scope.reportRunJson.chartColumnJSONList.length; i++) {
56 if ($scope.reportRunJson.chartColumnJSONList[i].value==domaninAxisValue) {
57 $scope.reportRunJson.domainAxisJSON.index=$scope.reportRunJson.chartColumnJSONList[i].index;
58 $scope.reportRunJson.domainAxisJSON.title=$scope.reportRunJson.chartColumnJSONList[i].title;
65 if ($scope.reportRunJson.categoryAxisJSON) {
66 var categoryAxisValue = $scope.reportRunJson.categoryAxisJSON.value;
67 for(var i = 0; i < $scope.reportRunJson.chartColumnJSONList.length; i++) {
68 if ($scope.reportRunJson.chartColumnJSONList[i].value==categoryAxisValue) {
69 $scope.reportRunJson.categoryAxisJSON.index=$scope.reportRunJson.chartColumnJSONList[i].index;
70 $scope.reportRunJson.categoryAxisJSON.title=$scope.reportRunJson.chartColumnJSONList[i].title;
75 //Set range axis label
76 if ($scope.reportRunJson.rangeAxisList) {
77 for(var j = 0; j < $scope.reportRunJson.rangeAxisList.length; j++) {
79 if ($scope.reportRunJson.rangeAxisList[j].rangeAxisLabelJSON) {
80 var rangeAxisLabelValue = $scope.reportRunJson.rangeAxisList[j].rangeAxisLabelJSON.value;
81 for(var i = 0; i < $scope.reportRunJson.chartColumnJSONList.length; i++) {
82 if ($scope.reportRunJson.chartColumnJSONList[i].value==rangeAxisLabelValue) {
83 $scope.reportRunJson.rangeAxisList[j].rangeAxisLabelJSON.index=$scope.reportRunJson.chartColumnJSONList[i].index;
84 $scope.reportRunJson.rangeAxisList[j].rangeAxisLabelJSON.title=$scope.reportRunJson.chartColumnJSONList[i].title;
93 if ($scope.reportRunJson.rangeAxisList) {
94 for(var j = 0; j < $scope.reportRunJson.rangeAxisList.length; j++) {
95 if ($scope.reportRunJson.rangeAxisList[j].rangeLineTypeJSON != null && $scope.reportRunJson.rangeAxisList[j].rangeLineTypeJSON.value != ""
96 && $scope.reportRunJson.rangeAxisList[j].rangeLineTypeJSON.value != null) {
97 var lineTypeValue = $scope.reportRunJson.rangeAxisList[j].rangeLineTypeJSON.value;
98 for(var i = 0; i < $scope.lineTypes.length; i++) {
99 if ($scope.lineTypes[i].value==lineTypeValue) {
100 $scope.reportRunJson.rangeAxisList[j].rangeLineTypeJSON.index=$scope.lineTypes[i].index;
101 $scope.reportRunJson.rangeAxisList[j].rangeLineTypeJSON.title=$scope.lineTypes[i].title;
105 $scope.reportRunJson.rangeAxisList[j].rangeLineTypeJSON = null;
110 if ($scope.reportRunJson.rangeAxisList) {
111 for(var j = 0; j < $scope.reportRunJson.rangeAxisList.length; j++) {
112 if ($scope.reportRunJson.rangeAxisList[j].rangeColorJSON != null && $scope.reportRunJson.rangeAxisList[j].rangeColorJSON.value != ""
113 && $scope.reportRunJson.rangeAxisList[j].rangeColorJSON.value != null) {
114 var colorValue = $scope.reportRunJson.rangeAxisList[j].rangeColorJSON.value;
115 for(var i = 0; i < $scope.rangeColors.length; i++) {
116 if ($scope.rangeColors[i].value==colorValue) {
117 $scope.reportRunJson.rangeAxisList[j].rangeColorJSON.index=$scope.rangeColors[i].index;
118 $scope.reportRunJson.rangeAxisList[j].rangeColorJSON.title=$scope.rangeColors[i].title;
122 $scope.reportRunJson.rangeAxisList[j].rangeColorJSON = null;
126 $scope.showLoader = false;
129 $scope.legend = "true";
132 $scope.saveChartData = function() {
133 $scope.showLoader = true;
134 if($scope.reportRunJson.commonChartOptions){
135 $scope.reportRunJson.commonChartOptions.animateAnimatedChart = ($scope.reportRunJson.commonChartOptions.animateAnimatedChart=="true")
136 $scope.reportRunJson.commonChartOptions.hideLegend = ($scope.reportRunJson.commonChartOptions.hideLegend=="true");
139 $scope.reportRunJson.showTitle = ($scope.reportRunJson.showTitle=="true");
141 $scope.reportRunJson.chartTypeJSON = {
142 'index':0,'title':'','value':''};
145 if (($scope.reportRunJson.chartType == "BarChart3D")&&($scope.reportRunJson.barChartOptions)) {
146 $scope.reportRunJson.barChartOptions.displayBarControls = ($scope.reportRunJson.barChartOptions.displayBarControls=="true") ;
147 $scope.reportRunJson.barChartOptions.minimizeXAxisTickers = ($scope.reportRunJson.barChartOptions.minimizeXAxisTickers=="true") ;
148 $scope.reportRunJson.barChartOptions.stackedChart = ($scope.reportRunJson.barChartOptions.stackedChart=="true") ;
149 $scope.reportRunJson.barChartOptions.timeAxis= ($scope.reportRunJson.barChartOptions.timeAxi=="true") ;
150 $scope.reportRunJson.barChartOptions.verticalOrientation = ($scope.reportRunJson.barChartOptions.verticalOrientation=="true") ;
151 $scope.reportRunJson.barChartOptions.xAxisDateType = ($scope.reportRunJson.barChartOptions.xAxisDateType=="true") ;
154 for (var i=0;i<$scope.chartTypes.length;i++) {
155 if ($scope.reportRunJson.chartType==$scope.chartTypes[i].value) {
156 $scope.reportRunJson.chartTypeJSON = {
157 'index':$scope.chartTypes[i].index,
158 'title':$scope.chartTypes[i].title,
159 'value':$scope.chartTypes[i].value
164 $scope.reportRunJson.domainAxisJSON = {
165 "index":0,"value":$scope.reportRunJson.domainAxis,"title": $scope.reportRunJson.domainAxis
167 $scope.reportRunJson.categoryAxisJSON = {
168 "index":0,"value":$scope.reportRunJson.categoryAxis,"title": $scope.reportRunJson.categoryAxis
171 // Specifically for DS2 for color
172 for (var i=0; i<$scope.reportRunJson.rangeAxisList.length; i ++) {
173 $scope.reportRunJson.rangeAxisList[i].rangeColorJSON =
174 {"index":0, "value": $scope.reportRunJson.rangeAxisList[i].rangeColor, "title": ""};
176 $scope.reportRunJson.rangeAxisList[i].rangeLineTypeJSON =
177 {"index":0, "value": "", "title": ""};
178 for (var j=0;j<$scope.lineTypes.length;j++) {
179 if ($scope.reportRunJson.rangeAxisList[i].rangeLineType ==$scope.lineTypes[j].value) {
180 $scope.reportRunJson.rangeAxisList[i].rangeLineTypeJSON =
181 {"index":$scope.lineTypes[j].index, "value": $scope.lineTypes[j].value, "title": $scope.lineTypes[j].title};
187 //Converting string variables to numbers
188 $scope.reportRunJson.commonChartOptions.rightMargin = Number($scope.reportRunJson.commonChartOptions.rightMargin);
189 $scope.reportRunJson.commonChartOptions.topMargin = Number($scope.reportRunJson.commonChartOptions.topMargin);
190 $scope.reportRunJson.commonChartOptions.bottomMargin = Number($scope.reportRunJson.commonChartOptions.bottomMargin);
191 $scope.reportRunJson.commonChartOptions.leftMargin = Number($scope.reportRunJson.commonChartOptions.leftMargin);
193 if ($scope.reportRunJson.categoryAxisJSON == "") {
194 $scope.reportRunJson.categoryAxisJSON = {};
195 $scope.reportRunJson.categoryAxisJSON.value = -1;
197 //add the remove list to the json
198 $scope.reportRunJson.rangeAxisRemoveList= $scope.rangeAxisRemoveList;
199 $http.post("save_chart", JSON.stringify($scope.reportRunJson)).success(function(data, status) {
200 $scope.successSubmit=true;
201 $scope.showLoader = false;
202 $scope.reportRunJson.commonChartOptions.animateAnimatedChart = $scope.reportRunJson.commonChartOptions.animateAnimatedChart+"";
203 $scope.reportRunJson.commonChartOptions.hideLegend = $scope.reportRunJson.commonChartOptions.hideLegend + "";
204 $scope.reportRunJson.showTitle = $scope.reportRunJson.showTitle + "";
205 if ($scope.reportRunJson.chartType == "BarChart3D" && $scope.reportRunJson.barChartOptions) {
206 $scope.reportRunJson.barChartOptions.displayBarControls = $scope.reportRunJson.barChartOptions.displayBarControls+"";
207 $scope.reportRunJson.barChartOptions.minimizeXAxisTickers = $scope.reportRunJson.barChartOptions.minimizeXAxisTickers+"";
208 $scope.reportRunJson.barChartOptions.stackedChart = $scope.reportRunJson.barChartOptions.stackedChart+"";
209 $scope.reportRunJson.barChartOptions.timeAxis =$scope.reportRunJson.barChartOptions.timeAxis+"";
210 $scope.reportRunJson.barChartOptions.verticalOrientation = $scope.reportRunJson.barChartOptions.verticalOrientation +"";
211 $scope.reportRunJson.barChartOptions.xAxisDateType = $scope.reportRunJson.barChartOptions.xAxisDateType +"";
213 $scope.successPopUp();
214 $scope.populateChrtWzdFields();
219 $scope.addRangeAxisRow = function (rangeaxisitem) {
220 $scope.reportRunJson.rangeAxisList.push({
224 $scope.rangeAxisRemoveList= [];
225 $scope.removeRangeAxisRow = function (index) {
226 $scope.rangeAxisRemoveList.push($scope.reportRunJson.rangeAxisList[index]);
227 $scope.reportRunJson.rangeAxisList[index].removed="true";
231 $scope.init = function () {
233 $scope.populateChrtWzdFields();
234 $scope.reportRunJson.rangeAxisRemoveList= [];
240 $scope.domainItems = [{title:"Domain Axis1", content:"Test1", open: false},{title:"Domain Axis2", content:"Test2", open: false}];
242 $scope.chartTypes = [
243 {index: 0, value: 'BarChart3D', title: 'Bar Chart'},
244 {index: 1, value: 'TimeSeriesChart', title: 'Time Series/Area Chart'},
245 {index: 2, value: 'PieChart', title: 'Pie Chart'},
246 {index: 3, value: 'AnnotationChart', title: 'Annotation Chart'},
247 {index: 4, value: 'FlexTimeChart', title: 'Flexible Time Chart'}
250 $scope.categories = [
251 {index: 0, value: 'scenario_name', title: 'scenario_name'},
252 {index: 1, value: 'total_traffic_in_PB', title: 'Total Traffic in PB'},
253 {index: 2, value: 'Avg Utilization Day', title: 'Avg Utilization Day'}
256 $scope.rangeColors = [
257 {index: 0, value: "#1f77b4",title: "Dodger Blue"},
258 {index: 1, value: "#ff7f0e",title: "Vivid orange"},
259 {index: 2, value: "#2ca02c",title: "Forest Green"},
260 {index: 3, value: "#8c864b",title: "Greenish Red"},
261 {index: 4, value: "#9467bd",title: "Desaturated violet"},
262 {index: 5, value: "#8c564b",title: "Dark moderate red"},
263 {index: 6, value: "#e377c2",title: "Soft pink"},
264 {index: 7, value: "#7f7f7f",title: "Dark gray"},
265 {index: 8, value: "#bcbd22",title: "Strong yellow"},
266 {index: 9, value: "#17becf",title: "Strong cyan"},
267 {index: 10, value: "#dc143c",title: "Vivid red"},
268 {index: 11, value: "#800080",title: "Dark magenta"},
269 {index: 12, value: "#0000FF",title: "Blue"},
270 {index: 13, value: "#008000",title: "Dark lime green"},
271 {index: 14, value: "#D2691E",title: "Reddish Orange"},
272 {index: 15, value: "#FF0000",title: "Red"},
273 {index: 16, value: "#000000",title: "Black"},
274 {index: 17, value: "#DB7093",title: "Pink"},
275 {index: 18, value: "#FF00FF",title: "Pure Magenta"},
276 {index: 19, value: "#7B68EE",title: "Soft blue"},
277 {index: 20, value: "#1f77b6",title: "Strong blue"},
278 {index: 21, value: "#9edae5",title: "Very soft cyan"},
279 {index: 22, value: "#393b79",title: "Dark Blue"},
280 {index: 23, value: "#5254a3",title: "Dark moderate Blue"},
281 {index: 24, value: "#6b6ecf",title: "Slightly desaturated blue"},
282 {index: 25, value: "#9c9ede",title: "Very soft blue"},
283 {index: 26, value: "#637939",title: "Dark Green"},
284 {index: 27, value: "#8ca252",title: "Dark moderate green"},
285 {index: 28, value: "#b5cf6b",title: "Slightly desaturated green"},
286 {index: 29, value: "#cedb9c",title: "Desaturated Green"},
289 {index: 30, value: "#00FFFF",title: "Aqua"},
290 {index: 31, value: "#000000",title: "Black"},
291 {index: 32, value: "#0000FF",title: "Blue"},
292 {index: 33, value: "#FF00FF",title: "Fuchsia"},
293 {index: 34, value: "#808080",title: "Gray"},
294 {index: 35, value: "#008000",title: "Green"},
295 {index: 36, value: "#00FF00",title: "Lime"},
296 {index: 37, value: "#800000",title: "Maroon"},
297 {index: 38, value: "#000080",title: "Navy"},
298 {index: 39, value: "#808000",title: "Olive"},
299 {index: 40, value: "#FF9900",title: "Orange"},
300 {index: 41, value: "#800080",title: "Purple"},
301 {index: 42, value: "#FF0000",title: "Red"},
302 {index: 43, value: "#C0C0C0",title: "Silver"},
303 {index: 44, value: "#008080",title: "Teal"},
304 {index: 45, value: "#FFFFFF",title: "White"},
305 {index: 46, value: "#FFFF00",title: "Yellow"}
310 {index: 0, value: 'default', title: 'Default'},
311 {index: 1, value: 'dotted_lines', title: 'Dotted Lines'},
312 {index: 2, value: 'dashed_lines', title: 'Dashed Lines'}
315 $scope.hardCodeReport= {
317 "reportName":"Test: Line Chart",
323 "chartColumnJSONList":[
327 "title":"traffic_date",
337 "formfield_comments":null,
339 "chartSqlWhole":"SELECT traffic_date tr0, traffic_date tr0_1,util_perc ut1, 1 FROM portal.demo_util_chart ORDER BY 1",
340 "chartAvailable":true,
341 "chartType":{"index": "", "value": "Bar Chart", "title": ""},
346 "staggerLabels":false,
351 "title":"traffic_date",
362 "hasCategoryAxis":false,
374 "value":"dotted_lines",
380 "title":"traffic_date",
395 "value":"dashed_lines",
404 "title":"traffic_date",
414 "primaryAxisLabel":"testlabel",
415 "secondaryAxisLabel":"testseclabel",
424 var colorValue = $scope.hardCodeReport.rangeAxisList[0].rangeColor.value;
426 $timeout(function() {
427 $rootScope.isViewRendering = false;
430 $scope.successPopUp = function (msg) {
431 var modalInstance = $modal.open({
432 templateUrl: 'app/fusion/scripts/DS2-modal/success_modal.html',
433 controller: ModalInstanceCtrl,
434 sizeClass: 'modal-small',
447 $scope.errorPopUp = function (msg) {
448 var modalInstance = $modal.open({
449 templateUrl: 'app/fusion/scripts/DS2-modal/error_modal.html',
450 controller: ModalInstanceCtrl,
451 sizeClass: 'modal-small',
459 var ModalInstanceCtrl = function ($scope, $modalInstance, msg,$rootScope) {
465 appDS2.directive('onlyDigits', function () {
470 link: function (scope, element, attrs, ngModel) {
471 if (!ngModel) return;
472 ngModel.$parsers.unshift(function (inputValue) {
473 var digits = inputValue.split('').filter(function (s) { return (!isNaN(s) && s != ' '); }).join('');
474 ngModel.$viewValue = digits;
482 appDS2.directive('onlyCharacters', function () {
486 link: function (scope, element, attrs, ngModel) {
487 if (!ngModel) return;
488 ngModel.$parsers.unshift(function (inputValue) {
489 var digits = inputValue.split('').filter(function (s) { return (isNaN(s) && s != ' '); }).join('');
490 ngModel.$viewValue = digits;