PluginProbe
Survey Maker by AYS / 5.2.1.8
Survey Maker by AYS v5.2.1.8
5.2.4.1 5.2.4.0 5.2.3.9 5.2.3.8 5.2.3.7 5.2.3.6 5.2.3.5 5.2.3.4 5.2.3.3 5.2.3.2 5.2.3.1 5.2.3.0 5.2.2.9 5.2.2.8 5.2.2.7 5.2.2.6 5.2.2.5 5.2.2.4 5.2.2.3 5.2.2.2 5.2.2.1 5.2.2.0 5.2.1.9 5.2.1.8 5.2.0.8 All 154 releases
survey-maker / admin / js / partials / survey-maker-admin-submissions-charts.js

survey-maker-admin-submissions-charts.js in Survey Maker by AYS 5.2.1.8, at admin/js/partials/survey-maker-admin-submissions-charts.js

438 lines 17.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function($){
2 'use strict';
3 $(document).ready(function(){
4
5
6
7 // Survey per answer count
8 var perAnswerData = SurveyChartData.perAnswerCount;
9
10 $.each(perAnswerData, function(){
11 switch( this.question_type ){
12 case "radio":
13 case "yesorno":
14 forRadioType( this );
15 break;
16 case "checkbox":
17 forCheckboxType( this );
18 break;
19 case 'star':
20 forStarTypeCustom( this );
21 break;
22 case "select":
23 forRadioType( this );
24 break;
25 }
26 });
27
28
29 function forRadioType( item ){
30 var questionId = item.question_id;
31 var dataTypes = [['Answers', 'Percent']];
32 for (var key in item.answers) {
33 dataTypes.push([
34 item.answerTitles[key] + '', item.answers[key]
35 ]);
36 }
37 google.charts.load('current', {'packages':['corechart']});
38 google.charts.setOnLoadCallback(drawChart);
39
40 function drawChart() {
41
42 var data = google.visualization.arrayToDataTable(dataTypes);
43 var options = {
44 height: 250,
45 fontSize: 16,
46 chartArea: {
47 width: '80%',
48 height: '80%'
49 }
50 };
51
52 var chart = new google.visualization.PieChart( document.getElementById( 'survey_answer_chart_' + questionId ) );
53
54 chart.draw(data, options);
55 resizeChart(chart, data, options);
56 }
57 }
58
59 function forCheckboxType( item ){
60 var questionId = item.question_id;
61 var dataTypes = [['Answers', 'Count']];
62 var sum_of_answers_count = item.sum_of_answers_count;
63
64 if( ! $.isEmptyObject( item.answers ) ){
65 for (var key in item.answers) {
66 dataTypes.push([
67 item.answerTitles[key] + '', item.answers[key]
68 ]);
69 }
70 }else{
71 dataTypes.push([
72 '', 0
73 ]);
74 }
75
76 google.charts.load('current', {packages: ['corechart', 'bar']});
77 google.charts.setOnLoadCallback(drawBasic);
78
79 function drawBasic() {
80
81 var data = google.visualization.arrayToDataTable(dataTypes);
82 var groupData = google.visualization.data.group(
83 data,
84 [{column: 0, modifier: function () {return 'total'}, type:'string'}],
85 [{column: 1, aggregation: google.visualization.data.sum, type: 'number'}]
86 );
87
88 var formatPercent = new google.visualization.NumberFormat({
89 pattern: '#%'
90 });
91
92 var formatShort = new google.visualization.NumberFormat({
93 pattern: 'short'
94 });
95
96 var view = new google.visualization.DataView(data);
97 view.setColumns([0, 1, {
98 calc: function (dt, row) {
99 if( $.isEmptyObject( item.answers ) ){
100 return amount;
101 }
102 var amount = formatShort.formatValue(dt.getValue(row, 1));
103
104 if( sum_of_answers_count == 0 ){
105 var percent = 0;
106 } else {
107 var percent = formatPercent.formatValue(dt.getValue(row, 1) / sum_of_answers_count);
108 }
109
110 return amount + ' (' + percent + ')';
111 },
112 type: 'string',
113 role: 'annotation'
114 }]);
115
116 var options = {
117 // width: 700,
118 height: 300,
119 fontSize: 14,
120 chartArea: {
121 width: '55%',
122 height: '80%'
123 },
124 annotations: {
125 alwaysOutside: true
126 },
127 bars: 'horizontal',
128 bar: { groupWidth: "50%" },
129 colors: [ SurveyChartData.chartColor ]
130 };
131
132 var chart = new google.visualization.BarChart( document.getElementById( 'survey_answer_chart_' + questionId ) );
133
134 chart.draw(view, options);
135 resizeChart(chart, view, options);
136 }
137 }
138
139 function forStarTypeCustom( item ){
140 var _this = this;
141 var questionId = item.question_id;
142 var starsLengthMax = "";
143 var starsLength = 5;
144 var dataValues = {};
145 var sumOfAnswers = 0;
146
147 if (typeof item.labels != "undefined") {
148 starsLengthMax = typeof item.labels.length != "undefined" && item.labels.length != "" ? item.labels.length : "";
149 }
150 if (starsLengthMax !== "") {
151 starsLength = parseInt(starsLengthMax);
152 }
153
154 for (var i=1; i <= starsLength; i++) {
155 dataValues[i] = 0;
156 }
157
158 for (var key in item.answers[questionId]) {
159 dataValues[ item.answers[questionId][key] ]++;
160 }
161
162 for (var key in dataValues) {
163 sumOfAnswers += key * dataValues[key];
164 }
165
166 var avgOfAnswers = ( sumOfAnswers > 0 && (item.sum_of_answers_count && item.sum_of_answers_count > 0) ) ? sumOfAnswers / item.sum_of_answers_count : 0;
167 avgOfAnswers = avgOfAnswers.toFixed(2);
168
169 var content = '<div>';
170 content += '<div class="ays-survey-answer-star-list-main ays-survey-answer-star-list-main-chart">';
171 content += '<div class="ays-survey-answer-star-list-container">';
172 content += '<div class="ays-survey-answer-star-list-row ays-survey-answer-star-list-row-chart-columns">';
173 content += '<div class="ays-survey-answer-star-list-column" title="">' + SurveyMakerAdmin.rating + '</div>';
174 content += '<div class="ays-survey-answer-star-list-column" title="">' + SurveyMakerAdmin.stars_count + '</div>';
175 content += '</div>';
176 content += '<div class="ays-survey-answer-star-list-row ays-survey-answer-star-list-row-chart">';
177 content += '<div class="ays-survey-answer-star-list-row-content">';
178 content += '<div class="ays-survey-answer-star-list-column ays-survey-answer-star-list-column-chart" style="box-shadow:inset 0px 0px 7px 0 #e9e4e4;font-weight: 600; font-size: 17px;">' + avgOfAnswers + '</div>';
179 content += '<div class="ays-survey-answer-star-list-column ays-survey-answer-star-list-column-chart" style="box-shadow:inset 0px 0px 7px 0 #e9e4e4;position:relative;width:15%;text-align:initial;padding: 0 18px;">';
180 var starsAverageSum = (avgOfAnswers * 100) / starsLength;
181 content += getStars(starsLength, starsAverageSum);
182 content += '</div>';
183 content += '</div>';
184 content += '</div>';
185 content += '<div class="ays-survey-answer-star-list-row-spacer"></div>';
186 content += '</div>';
187 content += '</div>';
188 content += '</div>';
189
190 $(document).find('#survey_answer_chart_' + questionId).html(content);
191 }
192
193 // AV Google charts
194 $(document).find('.nav-tab').on('click', function(e) {
195 var contValue = $('div#statistics').css('display');
196 if (this.getAttribute('href') == '#statistics' || contValue == 'block') {
197
198 //Reports count per day
199 var perData = [
200 [0, 0], [1, 10], [2, 23], [3, 17], [4, 18], [5, 9],
201 [6, 11], [7, 27], [8, 33], [9, 40], [10, 32], [11, 35],
202 [12, 30], [13, 40], [14, 42], [15, 47], [16, 44], [17, 48],
203 [18, 52], [19, 54], [20, 42], [21, 55], [22, 56], [23, 57],
204 [24, 60], [25, 50], [26, 52], [27, 51], [28, 49], [29, 53],
205 [30, 55], [31, 60], [32, 61], [33, 59], [34, 62], [35, 65],
206 [36, 62], [37, 58], [38, 55], [39, 61], [40, 64], [41, 65],
207 [42, 63], [43, 66], [44, 67], [45, 69], [46, 69], [47, 70],
208 [48, 72], [49, 68], [50, 66], [51, 65], [52, 67], [53, 70],
209 [54, 71], [55, 72], [56, 73], [57, 75], [58, 70], [59, 68],
210 [60, 64], [61, 60], [62, 65], [63, 67], [64, 68], [65, 69],
211 [66, 70], [67, 72], [68, 75], [69, 80]
212 ];
213
214 // for (var l = 0; l < perData.length; l++) {
215 // perData[l] = new Array(
216 // new Date(
217 // perData[l][0]
218 // ),
219 // perData[l][1]
220 // );
221 // }
222
223 google.charts.load('current', {
224 packages: ['corechart']
225 }).then(function () {
226 var data = new google.visualization.DataTable();
227 data.addColumn('number', 'Date');
228 data.addColumn('number', 'Count');
229
230 data.addRows(perData);
231
232 var populationRange = data.getColumnRange(1);
233
234 var logOptions = {
235 // title: '',
236 // legend: 'none',
237 width: 700,
238 height: 300,
239 fontSize: 14,
240 hAxis: {
241 title: 'Date',
242 gridlines: {count: 15}
243 },
244 vAxis: {
245 title: 'Count'
246 }
247 };
248
249 var logChart = new google.visualization.LineChart(document.getElementById('survey_chart1_div'));
250 logChart.draw(data, logOptions);
251 });
252
253 // Survey passed users
254 var userCount = [
255 ['Administrator', 11],
256 ['Author', 2],
257 ['Editor', 5],
258 ['Guest', 2],
259 ['Subscriber', 7]
260 ];
261 var dataTypes = [['Users', 'Percent']];
262
263 for (var i = 0; i < userCount.length; i++) {
264 dataTypes.push([
265 userCount[i][0], userCount[i][1]
266 ]);
267 }
268
269 google.charts.load('current', {'packages':['corechart']});
270 google.charts.setOnLoadCallback(drawChart);
271
272 function drawChart() {
273
274 var data = google.visualization.arrayToDataTable(dataTypes);
275
276 var options = {
277 // title: 'My Daily Activities'
278 width: 700,
279 height: 300,
280 fontSize: 16,
281 chartArea: {
282 width: '80%',
283 height: '80%',
284 }
285 };
286
287 var chart = new google.visualization.PieChart(document.getElementById('survey_chart2_div'));
288
289 chart.draw(data, options);
290 }
291
292 // Device chart
293 var devicesCount = {
294 "Desktop": 6,
295 "Mobile": 2,
296 "Tablet": 3,
297 };
298
299 var aysDevicesBarChartData = new Array(['', '']);
300 for (var count in devicesCount) {
301 aysDevicesBarChartData.push([
302 count,
303 parseInt(devicesCount[count])
304 ]);
305 }
306
307 google.charts.load('current', {packages: ['corechart', 'bar']});
308 google.charts.setOnLoadCallback(drawBasic);
309
310 function drawBasic() {
311
312 var data = google.visualization.arrayToDataTable(aysDevicesBarChartData);
313 var groupData = google.visualization.data.group(
314 data,
315 [{column: 0, modifier: function () {return 'total'}, type:'string'}],
316 [{column: 1, aggregation: google.visualization.data.sum, type: 'number'}]
317 );
318
319 var formatPercent = new google.visualization.NumberFormat({
320 pattern: '#%'
321 });
322
323 var formatShort = new google.visualization.NumberFormat({
324 pattern: 'short'
325 });
326 var view = new google.visualization.DataView(data);
327 view.setColumns([0, 1, {
328 calc: function (dt, row) {
329 if( groupData.getValue(0, 1) == 0 ){
330 return amount;
331 }
332 var amount = formatShort.formatValue(dt.getValue(row, 1));
333 var percent = formatPercent.formatValue(dt.getValue(row, 1) / groupData.getValue(0, 1));
334 return amount + ' (' + percent + ')';
335 },
336 type: 'string',
337 role: 'annotation'
338 }]);
339
340 var options = {
341 width: 700,
342 height: 300,
343 fontSize: 14,
344 chartArea: {
345 width: '50%',
346 height: '80%'
347 },
348 annotations: {
349 alwaysOutside: true
350 },
351 bars: 'horizontal',
352 bar: { groupWidth: "50%" },
353 };
354
355 var chart = new google.visualization.BarChart( document.getElementById( 'survey_chart3_div') );
356
357 chart.draw(view,options);
358 }
359
360 var countriesCount = {
361 "USA": 6,
362 "England": 2,
363 "Germany": 3,
364 };
365
366 var aysCountriesBarChartData = new Array(['', '']);
367 for (var count in countriesCount) {
368 aysCountriesBarChartData.push([
369 count,
370 parseInt(countriesCount[count])
371 ]);
372 }
373
374 google.charts.load('current', {'packages':['corechart']});
375 google.charts.setOnLoadCallback(drawChart2);
376
377 function drawChart2() {
378
379 var data = google.visualization.arrayToDataTable(aysCountriesBarChartData);
380
381 var options = {
382 // title: 'My Daily Activities'
383 width: 700,
384 height: 300,
385 fontSize: 16,
386 chartArea: {
387 width: '80%',
388 height: '80%',
389 }
390 };
391
392 var chart = new google.visualization.PieChart(document.getElementById('survey_chart4_div'));
393
394 chart.draw(data, options);
395 }
396 }
397 });
398
399 function resizeChart(chart, data, options){
400
401 //create trigger to resizeEnd event
402 jQuery(window).resize(function() {
403 if(this.resizeTO) clearTimeout(this.resizeTO);
404 this.resizeTO = setTimeout(function() {
405 jQuery(this).trigger('resizeEnd');
406 }, 100);
407 });
408
409 //redraw graph when window resize is completed
410 jQuery(window).on('resizeEnd', function() {
411 chart.draw(data, options);
412 });
413
414 }
415
416 function getStars(lenght,averagePercent){
417
418 var content = "";
419 content += '<div class="ays-survey-star-list-chart-star-box">';
420 content += '<div class="ays-survey-star-list-chart-star-box-wrap">';
421 content += '<span class="ays-survey-star-list-chart-stars-active" style="width:'+averagePercent+'%">';
422 for (var i = 1; i <= lenght; i++) {
423 content += '<i class="fa fa_star" aria-hidden="true"></i>';
424 }
425 content += '</span>';
426
427 content += '<span class="ays-survey-star-list-chart-stars-inactive">';
428 for (var i = 1; i <= lenght; i++) {
429 content += '<i class="fa fa_star_o"></i>';
430 }
431 content += '</span>';
432 content += '</div>';
433 content += '</div>';
434 return content;
435 }
436 });
437 })(jQuery);
438