1 appDS2.controller('reportChartController', function ($scope, $rootScope, $timeout, $window, $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 $http.get("raptor.htm?action=chart.json&c_master="+$routeParams.reportId).then(function (response) {
19 $scope.reportRunJson = response.data;
21 $scope.reportRunJson.commonChartOptions.animateAnimatedChart = $scope.reportRunJson.commonChartOptions.animateAnimatedChart+"";
22 $scope.reportRunJson.commonChartOptions.hideLegend = $scope.reportRunJson.commonChartOptions.hideLegend + "";
23 $scope.reportRunJson.showTitle = $scope.reportRunJson.showTitle + "";
25 // if barChartOptions is not null
26 if ($scope.reportRunJson.barChartOptions) {
27 $scope.reportRunJson.barChartOptions.displayBarControls = $scope.reportRunJson.barChartOptions.displayBarControls+"";
28 $scope.reportRunJson.barChartOptions.minimizeXAxisTickers = $scope.reportRunJson.barChartOptions.minimizeXAxisTickers+"";
29 $scope.reportRunJson.barChartOptions.stackedChart = $scope.reportRunJson.barChartOptions.stackedChart+"";
30 $scope.reportRunJson.barChartOptions.timeAxis =$scope.reportRunJson.barChartOptions.timeAxis+"";
31 $scope.reportRunJson.barChartOptions.verticalOrientation = $scope.reportRunJson.barChartOptions.verticalOrientation +"";
32 $scope.reportRunJson.barChartOptions.xAxisDateType = $scope.reportRunJson.barChartOptions.xAxisDateType +"";
35 if ($scope.reportRunJson.chartTypeJSON) {
36 var chrtTypeValue = $scope.reportRunJson.chartType;
37 for(var i = 0; i < $scope.chartTypes.length; i++) {
38 if ($scope.chartTypes[i].value==chrtTypeValue) {
39 $scope.reportRunJson.chartTypeJSON.index=$scope.chartTypes[i].index;
40 $scope.reportRunJson.chartTypeJSON.value=$scope.chartTypes[i].value;
41 $scope.reportRunJson.chartTypeJSON.title=$scope.chartTypes[i].title;
48 if ($scope.reportRunJson.domainAxisJSON) {
49 var domaninAxisValue = $scope.reportRunJson.domainAxisJSON.value;
50 for(var i = 0; i < $scope.reportRunJson.chartColumnJSONList.length; i++) {
51 if ($scope.reportRunJson.chartColumnJSONList[i].value==domaninAxisValue) {
52 $scope.reportRunJson.domainAxisJSON.index=$scope.reportRunJson.chartColumnJSONList[i].index;
53 $scope.reportRunJson.domainAxisJSON.title=$scope.reportRunJson.chartColumnJSONList[i].title;
60 if ($scope.reportRunJson.categoryAxisJSON) {
61 var categoryAxisValue = $scope.reportRunJson.categoryAxisJSON.value;
62 for(var i = 0; i < $scope.reportRunJson.chartColumnJSONList.length; i++) {
63 if ($scope.reportRunJson.chartColumnJSONList[i].value==categoryAxisValue) {
64 $scope.reportRunJson.categoryAxisJSON.index=$scope.reportRunJson.chartColumnJSONList[i].index;
65 $scope.reportRunJson.categoryAxisJSON.title=$scope.reportRunJson.chartColumnJSONList[i].title;
70 //Set range axis label
71 if ($scope.reportRunJson.rangeAxisList) {
72 for(var j = 0; j < $scope.reportRunJson.rangeAxisList.length; j++) {
74 if ($scope.reportRunJson.rangeAxisList[j].rangeAxisLabelJSON) {
75 var rangeAxisLabelValue = $scope.reportRunJson.rangeAxisList[j].rangeAxisLabelJSON.value;
76 for(var i = 0; i < $scope.reportRunJson.chartColumnJSONList.length; i++) {
77 if ($scope.reportRunJson.chartColumnJSONList[i].value==rangeAxisLabelValue) {
78 $scope.reportRunJson.rangeAxisList[j].rangeAxisLabelJSON.index=$scope.reportRunJson.chartColumnJSONList[i].index;
79 $scope.reportRunJson.rangeAxisList[j].rangeAxisLabelJSON.title=$scope.reportRunJson.chartColumnJSONList[i].title;
88 if ($scope.reportRunJson.rangeAxisList) {
89 for(var j = 0; j < $scope.reportRunJson.rangeAxisList.length; j++) {
90 if ($scope.reportRunJson.rangeAxisList[j].rangeLineTypeJSON != null && $scope.reportRunJson.rangeAxisList[j].rangeLineTypeJSON.value != ""
91 && $scope.reportRunJson.rangeAxisList[j].rangeLineTypeJSON.value != null) {
92 var lineTypeValue = $scope.reportRunJson.rangeAxisList[j].rangeLineTypeJSON.value;
93 for(var i = 0; i < $scope.lineTypes.length; i++) {
94 if ($scope.lineTypes[i].value==lineTypeValue) {
95 $scope.reportRunJson.rangeAxisList[j].rangeLineTypeJSON.index=$scope.lineTypes[i].index;
96 $scope.reportRunJson.rangeAxisList[j].rangeLineTypeJSON.title=$scope.lineTypes[i].title;
100 $scope.reportRunJson.rangeAxisList[j].rangeLineTypeJSON = null;
105 if ($scope.reportRunJson.rangeAxisList) {
106 for(var j = 0; j < $scope.reportRunJson.rangeAxisList.length; j++) {
107 if ($scope.reportRunJson.rangeAxisList[j].rangeColorJSON != null && $scope.reportRunJson.rangeAxisList[j].rangeColorJSON.value != ""
108 && $scope.reportRunJson.rangeAxisList[j].rangeColorJSON.value != null) {
109 var colorValue = $scope.reportRunJson.rangeAxisList[j].rangeColorJSON.value;
110 for(var i = 0; i < $scope.rangeColors.length; i++) {
111 if ($scope.rangeColors[i].value==colorValue) {
112 $scope.reportRunJson.rangeAxisList[j].rangeColorJSON.index=$scope.rangeColors[i].index;
113 $scope.reportRunJson.rangeAxisList[j].rangeColorJSON.title=$scope.rangeColors[i].title;
117 $scope.reportRunJson.rangeAxisList[j].rangeColorJSON = null;
121 $scope.showLoader = false;
124 $scope.legend = "true";
127 $scope.saveChartData = function() {
128 $scope.showLoader = true;
130 $scope.reportRunJson.commonChartOptions.animateAnimatedChart = ($scope.reportRunJson.commonChartOptions.animateAnimatedChart=="true")
131 $scope.reportRunJson.commonChartOptions.hideLegend = ($scope.reportRunJson.commonChartOptions.hideLegend=="true");
132 $scope.reportRunJson.showTitle = ($scope.reportRunJson.showTitle=="true");
134 $scope.reportRunJson.chartTypeJSON = {
135 'index':0,'title':'','value':''};
138 if (($scope.reportRunJson.chartType == "BarChart3D")&&($scope.reportRunJson.barChartOptions)) {
139 $scope.reportRunJson.barChartOptions.displayBarControls = ($scope.reportRunJson.barChartOptions.displayBarControls=="true") ;
140 $scope.reportRunJson.barChartOptions.minimizeXAxisTickers = ($scope.reportRunJson.barChartOptions.minimizeXAxisTickers=="true") ;
141 $scope.reportRunJson.barChartOptions.stackedChart = ($scope.reportRunJson.barChartOptions.stackedChart=="true") ;
142 $scope.reportRunJson.barChartOptions.timeAxis= ($scope.reportRunJson.barChartOptions.timeAxi=="true") ;
143 $scope.reportRunJson.barChartOptions.verticalOrientation = ($scope.reportRunJson.barChartOptions.verticalOrientation=="true") ;
144 $scope.reportRunJson.barChartOptions.xAxisDateType = ($scope.reportRunJson.barChartOptions.xAxisDateType=="true") ;
147 for (var i=0;i<$scope.chartTypes.length;i++) {
148 if ($scope.reportRunJson.chartType==$scope.chartTypes[i].value) {
149 $scope.reportRunJson.chartTypeJSON = {
150 'index':$scope.chartTypes[i].index,
151 'title':$scope.chartTypes[i].title,
152 'value':$scope.chartTypes[i].value
157 $scope.reportRunJson.domainAxisJSON = {
158 "index":0,"value":$scope.reportRunJson.domainAxis,"title": $scope.reportRunJson.domainAxis
160 $scope.reportRunJson.categoryAxisJSON = {
161 "index":0,"value":$scope.reportRunJson.categoryAxis,"title": $scope.reportRunJson.categoryAxis
164 // Specifically for DS2 for color
165 for (var i=0; i<$scope.reportRunJson.rangeAxisList.length; i ++) {
166 $scope.reportRunJson.rangeAxisList[i].rangeColorJSON =
167 {"index":0, "value": $scope.reportRunJson.rangeAxisList[i].rangeColor, "title": ""};
169 $scope.reportRunJson.rangeAxisList[i].rangeLineTypeJSON =
170 {"index":0, "value": "", "title": ""};
171 for (var j=0;j<$scope.lineTypes.length;j++) {
172 if ($scope.reportRunJson.rangeAxisList[i].rangeLineType ==$scope.lineTypes[j].value) {
173 $scope.reportRunJson.rangeAxisList[i].rangeLineTypeJSON =
174 {"index":$scope.lineTypes[j].index, "value": $scope.lineTypes[j].value, "title": $scope.lineTypes[j].title};
180 //Converting string variables to numbers
181 $scope.reportRunJson.commonChartOptions.rightMargin = Number($scope.reportRunJson.commonChartOptions.rightMargin);
182 $scope.reportRunJson.commonChartOptions.topMargin = Number($scope.reportRunJson.commonChartOptions.topMargin);
183 $scope.reportRunJson.commonChartOptions.bottomMargin = Number($scope.reportRunJson.commonChartOptions.bottomMargin);
184 $scope.reportRunJson.commonChartOptions.leftMargin = Number($scope.reportRunJson.commonChartOptions.leftMargin);
186 if ($scope.reportRunJson.categoryAxisJSON == "") {
187 $scope.reportRunJson.categoryAxisJSON = {};
188 $scope.reportRunJson.categoryAxisJSON.value = -1;
191 $http.post("save_chart", JSON.stringify($scope.reportRunJson)).success(function(data, status) {
192 $scope.successSubmit=true;
193 $scope.showLoader = false;
194 $scope.reportRunJson.commonChartOptions.animateAnimatedChart = $scope.reportRunJson.commonChartOptions.animateAnimatedChart+"";
195 $scope.reportRunJson.commonChartOptions.hideLegend = $scope.reportRunJson.commonChartOptions.hideLegend + "";
196 $scope.reportRunJson.showTitle = $scope.reportRunJson.showTitle + "";
197 if ($scope.reportRunJson.chartType == "BarChart3D") {
198 $scope.reportRunJson.barChartOptions.displayBarControls = $scope.reportRunJson.barChartOptions.displayBarControls+"";
199 $scope.reportRunJson.barChartOptions.minimizeXAxisTickers = $scope.reportRunJson.barChartOptions.minimizeXAxisTickers+"";
200 $scope.reportRunJson.barChartOptions.stackedChart = $scope.reportRunJson.barChartOptions.stackedChart+"";
201 $scope.reportRunJson.barChartOptions.timeAxis =$scope.reportRunJson.barChartOptions.timeAxis+"";
202 $scope.reportRunJson.barChartOptions.verticalOrientation = $scope.reportRunJson.barChartOptions.verticalOrientation +"";
203 $scope.reportRunJson.barChartOptions.xAxisDateType = $scope.reportRunJson.barChartOptions.xAxisDateType +"";
209 $scope.addRangeAxisRow = function (rangeaxisitem) {
210 $scope.reportRunJson.rangeAxisList.push({
214 $scope.removeRangeAxisRow = function (index) {
215 $scope.reportRunJson.rangeAxisList.splice(index, 1);
219 $scope.init = function () {
221 $scope.populateChrtWzdFields();
227 $scope.domainItems = [{title:"Domain Axis1", content:"Test1", open: false},{title:"Domain Axis2", content:"Test2", open: false}];
229 $scope.chartTypes = [
230 {index: 0, value: 'BarChart3D', title: 'Bar Chart'},
231 {index: 1, value: 'TimeSeriesChart', title: 'Time Series/Area Chart'},
232 {index: 2, value: 'PieChart', title: 'Pie Chart'},
233 {index: 3, value: 'AnnotationChart', title: 'Annotation Chart'},
234 {index: 4, value: 'FlexTimeChart', title: 'Flexible Time Chart'}
237 $scope.categories = [
238 {index: 0, value: 'scenario_name', title: 'scenario_name'},
239 {index: 1, value: 'total_traffic_in_PB', title: 'Total Traffic in PB'},
240 {index: 2, value: 'Avg Utilization Day', title: 'Avg Utilization Day'}
243 $scope.rangeColors = [
244 {index: 0, value: "#1f77b4",title: "Dodger Blue"},
245 {index: 1, value: "#ff7f0e",title: "Vivid orange"},
246 {index: 2, value: "#2ca02c",title: "Forest Green"},
247 {index: 3, value: "#8c864b",title: "Greenish Red"},
248 {index: 4, value: "#9467bd",title: "Desaturated violet"},
249 {index: 5, value: "#8c564b",title: "Dark moderate red"},
250 {index: 6, value: "#e377c2",title: "Soft pink"},
251 {index: 7, value: "#7f7f7f",title: "Dark gray"},
252 {index: 8, value: "#bcbd22",title: "Strong yellow"},
253 {index: 9, value: "#17becf",title: "Strong cyan"},
254 {index: 10, value: "#dc143c",title: "Vivid red"},
255 {index: 11, value: "#800080",title: "Dark magenta"},
256 {index: 12, value: "#0000FF",title: "Blue"},
257 {index: 13, value: "#008000",title: "Dark lime green"},
258 {index: 14, value: "#D2691E",title: "Reddish Orange"},
259 {index: 15, value: "#FF0000",title: "Red"},
260 {index: 16, value: "#000000",title: "Black"},
261 {index: 17, value: "#DB7093",title: "Pink"},
262 {index: 18, value: "#FF00FF",title: "Pure Magenta"},
263 {index: 19, value: "#7B68EE",title: "Soft blue"},
264 {index: 20, value: "#1f77b6",title: "Strong blue"},
265 {index: 21, value: "#9edae5",title: "Very soft cyan"},
266 {index: 22, value: "#393b79",title: "Dark Blue"},
267 {index: 23, value: "#5254a3",title: "Dark moderate Blue"},
268 {index: 24, value: "#6b6ecf",title: "Slightly desaturated blue"},
269 {index: 25, value: "#9c9ede",title: "Very soft blue"},
270 {index: 26, value: "#637939",title: "Dark Green"},
271 {index: 27, value: "#8ca252",title: "Dark moderate green"},
272 {index: 28, value: "#b5cf6b",title: "Slightly desaturated green"},
273 {index: 29, value: "#cedb9c",title: "Desaturated Green"},
276 {index: 30, value: "#00FFFF",title: "Aqua"},
277 {index: 31, value: "#000000",title: "Black"},
278 {index: 32, value: "#0000FF",title: "Blue"},
279 {index: 33, value: "#FF00FF",title: "Fuchsia"},
280 {index: 34, value: "#808080",title: "Gray"},
281 {index: 35, value: "#008000",title: "Green"},
282 {index: 36, value: "#00FF00",title: "Lime"},
283 {index: 37, value: "#800000",title: "Maroon"},
284 {index: 38, value: "#000080",title: "Navy"},
285 {index: 39, value: "#808000",title: "Olive"},
286 {index: 40, value: "#FF9900",title: "Orange"},
287 {index: 41, value: "#800080",title: "Purple"},
288 {index: 42, value: "#FF0000",title: "Red"},
289 {index: 43, value: "#C0C0C0",title: "Silver"},
290 {index: 44, value: "#008080",title: "Teal"},
291 {index: 45, value: "#FFFFFF",title: "White"},
292 {index: 46, value: "#FFFF00",title: "Yellow"}
297 {index: 0, value: 'default', title: 'Default'},
298 {index: 1, value: 'dotted_lines', title: 'Dotted Lines'},
299 {index: 2, value: 'dashed_lines', title: 'Dashed Lines'}
302 $scope.hardCodeReport= {
304 "reportName":"Test: Line Chart",
310 "chartColumnJSONList":[
314 "title":"traffic_date",
324 "formfield_comments":null,
326 "chartSqlWhole":"SELECT traffic_date tr0, traffic_date tr0_1,util_perc ut1, 1 FROM portal.demo_util_chart ORDER BY 1",
327 "chartAvailable":true,
328 "chartType":{"index": "", "value": "Bar Chart", "title": ""},
333 "staggerLabels":false,
338 "title":"traffic_date",
349 "hasCategoryAxis":false,
361 "value":"dotted_lines",
367 "title":"traffic_date",
382 "value":"dashed_lines",
391 "title":"traffic_date",
401 "primaryAxisLabel":"testlabel",
402 "secondaryAxisLabel":"testseclabel",
411 var colorValue = $scope.hardCodeReport.rangeAxisList[0].rangeColor.value;
413 $timeout(function() {
414 $rootScope.isViewRendering = false;
420 appDS2.directive('onlyDigits', function () {
425 link: function (scope, element, attrs, ngModel) {
426 if (!ngModel) return;
427 ngModel.$parsers.unshift(function (inputValue) {
428 var digits = inputValue.split('').filter(function (s) { return (!isNaN(s) && s != ' '); }).join('');
429 ngModel.$viewValue = digits;
437 appDS2.directive('onlyCharacters', function () {
441 link: function (scope, element, attrs, ngModel) {
442 if (!ngModel) return;
443 ngModel.$parsers.unshift(function (inputValue) {
444 var digits = inputValue.split('').filter(function (s) { return (isNaN(s) && s != ' '); }).join('');
445 ngModel.$viewValue = digits;