PluginProbe
Chartify – WordPress Chart Plugin / 3.7.1
Chartify – WordPress Chart Plugin v3.7.1
3.8.0 3.7.9 3.7.8 3.7.7 3.7.6 3.7.5 trunk 1.0.0 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 All 83 releases
chart-builder / admin / js / chart-builder-admin-chartjs.js

chart-builder-admin-chartjs.js in Chartify – WordPress Chart Plugin 3.7.1, at admin/js/chart-builder-admin-chartjs.js

1,439 lines 56.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function($) {
2 'use strict';
3 function ChartBuilderChartsJs(element, options){
4 this.el = element;
5 this.$el = $(element);
6 this.ajaxAction = 'ays_chart_admin_ajax';
7 this.htmlClassPrefix = 'ays-chart-';
8 this.htmlNamePrefix = 'ays_';
9 this.dbOptions = undefined;
10 this.chartSourceData = undefined;
11 this.chartObj = undefined;
12 this.chartOptions = null;
13 this.chartData = null;
14 this.chartTempData = null;
15 this.chartType = 'pie_chart';
16 this.chartSourceType = 'chart-js';
17 this.chartObject = null;
18
19 this.chartSources = {
20 'pie_chart' : 'Pie Chart',
21 'bar_chart' : 'Bar Chart',
22 'line_chart' : 'Line Chart',
23 }
24
25 this.init();
26
27 return this;
28 }
29
30 ChartBuilderChartsJs.prototype.init = function() {
31 var _this = this;
32 _this.chartSourceData = window.ChartBuilderSourceData;
33 _this.setEvents();
34 _this.initLibraries();
35 _this.setAccordionEvents();
36 };
37
38 // Set events
39 ChartBuilderChartsJs.prototype.setEvents = function(e){
40 var _this = this;
41
42 _this.chartType = _this.chartSourceData.chartType;
43 _this.chartSourceType = _this.chartSourceData.chartSourceType;
44 _this.chartData = _this.chartSourceData.source;
45 _this.loadChartBySource();
46 _this.configureOptions();
47 _this.resizeChart();
48
49 /* == Tabulation == */
50 _this.$el.on('click', '.nav-tab-wrapper a.nav-tab' , _this.changeTabs);
51 /* */
52
53 /* == Notifications dismiss button == */
54 _this.$el.on('click', '.notice-dismiss', function (e) {
55 _this.changeCurrentUrl('status');
56 });
57
58 _this.$el.on('click', '.toggle_ddmenu' , _this.toggleDDmenu);
59 /* */
60
61 /* Add Manual data */
62 _this.$el.on("click" , '.'+_this.htmlClassPrefix+'add-new-row-box', function(){
63 _this.addChartDataRow();
64 });
65
66 _this.$el.on("click" , '.'+_this.htmlClassPrefix+'add-new-column-box', function(){
67 _this.addChartDataColumn();
68 });
69
70 _this.$el.on('click', '.'+_this.htmlClassPrefix+'show-on-chart-bttn', function(e){
71 e.preventDefault();
72 _this.showOnChart();
73 });
74
75 /* */
76
77 /* Delete data */
78 _this.$el.on("click" , '.'+_this.htmlClassPrefix+'chart-source-data-remove-row', function(){
79 _this.deleteChartDataRow($(this));
80 _this.detectManualChange();
81 });
82 _this.$el.on("click" , '.'+_this.htmlClassPrefix+'chart-source-data-remove-col', function(){
83 _this.deleteChartDataColumn($(this));
84 _this.detectManualChange();
85 });
86 _this.$el.on('mouseenter', '.'+_this.htmlClassPrefix+'chart-source-data-remove-block', function() {
87 $(this).find('path').css('fill', '#ff0000');
88 });
89 _this.$el.on('mouseleave', '.'+_this.htmlClassPrefix+'chart-source-data-remove-block', function() {
90 $(this).find('path').css('fill', '#b8b8b8');
91 });
92 /* */
93
94 /* Save with Ctrl + S */
95 _this.$el.on('keydown', $(document), _this.quickSaveHotKeys);
96 /* */
97
98 // Submit buttons disabling
99 _this.$el.on('click', '.'+_this.htmlClassPrefix+'loader-banner', _this.submitOnce);
100 /* */
101
102 // Disabling submit when press enter button on inputing
103 $(document).on("keypress", '.ays-text-input', _this.keyBoardConfig.bind(_this));
104 /* */
105
106 // Modal close
107 $(document).on('click', '.ays-close', function () {
108 $(this).parents('.ays-modal').aysModal('hide');
109 });
110
111 // Changing source type to manual
112 _this.$el.on('input', '.'+_this.htmlClassPrefix+'chart-source-data-content input', function () {
113 _this.detectManualChange();
114 });
115
116 // Shortcode text for editor tooltip
117 $(document).find('strong.ays-chart-shortcode-box').on('mouseleave', function(){
118 var _this = $(this);
119
120 _this.attr('data-original-title', aysChartBuilderAdmin.clickForCopy);
121 _this.attr("data-bs-original-title", aysChartBuilderAdmin.clickForCopy);
122 _this.attr("title", aysChartBuilderAdmin.clickForCopy);
123 });
124
125 _this.$el.find('.'+_this.htmlClassPrefix+'toggle-hidden-option').on('change', function () {
126 // var animationOptions = _this.$el.find('.'+_this.htmlClassPrefix+'hidden-options-section');
127 var currentSettings = $(this).parents('.' + _this.htmlClassPrefix + 'settings-data-main-wrap')
128 var hiddenSection = currentSettings.find('.' + _this.htmlClassPrefix + 'hidden-options-section');
129 var notHiddenSection = currentSettings.find('.' + _this.htmlClassPrefix + 'not-hidden-options-section');
130
131 if ($(this).is(':checked')) {
132 hiddenSection.removeClass('display_none');
133 notHiddenSection.addClass('display_none');
134 } else {
135 hiddenSection.addClass('display_none');
136 notHiddenSection.removeClass('display_none');
137 }
138 });
139
140 _this.$el.on("click", '.'+_this.htmlClassPrefix+'chart-source-data-sort', function(){
141 _this.sortDataByColumn($(this));
142 _this.detectManualChange();
143 });
144
145 // Live preview
146 _this.liveSettingsPreview();
147 }
148
149 ChartBuilderChartsJs.prototype.liveSettingsPreview = function () {
150 var _this = this;
151
152 // title
153 _this.$el.find('#ays-title').on('input', function () {
154 _this.$el.find('.'+_this.htmlClassPrefix+'charts-title').text($(this).val());
155 });
156
157 // description
158 _this.$el.find('#'+_this.htmlClassPrefix+'description').on('input', function () {
159 _this.$el.find('.'+_this.htmlClassPrefix+'charts-description').text($(this).val());
160 });
161
162 // chart styles
163 _this.$el.find('#'+_this.htmlClassPrefix+'option-width').on('input', function () {
164 var format = _this.$el.find('#'+_this.htmlClassPrefix+'option-width-format').val() == '%' ? '%' : '';
165 _this.chartSourceData.settings.chart_width = $(this).val();
166 _this.$el.find('.'+_this.htmlClassPrefix+'charts-main-container').css('width', $(this).val() + format);
167 _this.chartObject.update();
168 });
169
170 _this.$el.find('#'+_this.htmlClassPrefix+'option-width-format').on('change', function () {
171 var format = '%';
172 if ($(this).val() == 'px') {
173 format = '';
174 }
175 var value = _this.$el.find('#'+_this.htmlClassPrefix+'option-width').val();
176 _this.$el.find('.'+_this.htmlClassPrefix+'charts-main-container').css('width', value + format);
177 _this.chartObject.update();
178 });
179
180 _this.$el.find('#'+_this.htmlClassPrefix+'option-height').on('input', function () {
181 var format = _this.$el.find('#'+_this.htmlClassPrefix+'option-height-format').val() == '%' ? '%' : '';
182 _this.chartSourceData.settings.chart_height = $(this).val();
183 _this.$el.find('.'+_this.htmlClassPrefix+'charts-main-container').css('height', $(this).val() + format);
184 _this.chartObject.update();
185 });
186
187 _this.$el.find('#'+_this.htmlClassPrefix+'option-height-format').on('change', function () {
188 var format = '';
189 if ($(this).val() == '%') {
190 format = '%';
191 }
192 var value = _this.$el.find('#'+_this.htmlClassPrefix+'option-height').val();
193 _this.$el.find('.'+_this.htmlClassPrefix+'charts-main-container').css('height', value + format);
194 _this.chartObject.update();
195 });
196
197 _this.$el.find('#'+_this.htmlClassPrefix+'option-border-width').on('input', function () {
198 _this.chartSourceData.settings.border_width = $(this).val();
199 _this.$el.find('.'+_this.htmlClassPrefix+'charts-main-container').css('border-width', $(this).val() + 'px');
200 _this.chartObject.update();
201 });
202
203 _this.$el.find('#'+_this.htmlClassPrefix+'option-border-radius').on('input', function () {
204 _this.chartSourceData.settings.border_radius = $(this).val();
205 _this.$el.find('.'+_this.htmlClassPrefix+'charts-main-container').css('border-radius', $(this).val() + 'px');
206 _this.chartObject.update();
207 });
208
209 _this.$el.find('#'+_this.htmlClassPrefix+'option-border-color').on('input', function () {
210 _this.chartSourceData.settings.border_color = $(this).val();
211 _this.$el.find('.'+_this.htmlClassPrefix+'charts-main-container').css('border-color', $(this).val());
212 _this.chartObject.update();
213 });
214
215 _this.$el.find('#'+_this.htmlClassPrefix+'option-border-style').on('change', function () {
216 _this.chartSourceData.settings.border_style = $(this).val();
217 _this.$el.find('.'+_this.htmlClassPrefix+'charts-main-container').css('border-style', $(this).val());
218 _this.chartObject.update();
219 });
220
221 _this.$el.find('#'+_this.htmlClassPrefix+'option-background-color').on('input', function () {
222 _this.chartSourceData.settings.background_color = $(this).val();
223 _this.$el.find('.'+_this.htmlClassPrefix+'charts-main-container').css('background-color', $(this).val());
224 _this.chartObject.update();
225 });
226
227 _this.$el.find('#'+_this.htmlClassPrefix+'option-border-width-with-title').on('input', function () {
228 _this.chartSourceData.settings.border_width_with_title = $(this).val();
229 _this.$el.find('.'+_this.htmlClassPrefix+'container').css('border-width', $(this).val() + 'px');
230 _this.chartObject.update();
231 });
232
233 _this.$el.find('#'+_this.htmlClassPrefix+'option-border-radius-with-title').on('input', function () {
234 _this.chartSourceData.settings.border_radius_with_title = $(this).val();
235 _this.$el.find('.'+_this.htmlClassPrefix+'container').css('border-radius', $(this).val() + 'px');
236 _this.chartObject.update();
237 });
238
239 _this.$el.find('#'+_this.htmlClassPrefix+'option-border-color-with-title').on('input', function () {
240 _this.chartSourceData.settings.border_color_with_title = $(this).val();
241 _this.$el.find('.'+_this.htmlClassPrefix+'container').css('border-color', $(this).val());
242 _this.chartObject.update();
243 });
244
245 _this.$el.find('#'+_this.htmlClassPrefix+'option-border-style-with-title').on('change', function () {
246 _this.chartSourceData.settings.border_style_with_title = $(this).val();
247 _this.$el.find('.'+_this.htmlClassPrefix+'container').css('border-style', $(this).val());
248 _this.chartObject.update();
249 });
250
251 _this.$el.find('#'+_this.htmlClassPrefix+'option-box-shadow').on('change', function () {
252 if ($(this).is(':checked')) {
253 _this.$el.find('.'+_this.htmlClassPrefix+'charts-main-container').css('box-shadow', '2px 2px 10px 2px ' + _this.chartSourceData.settings.box_shadow_color);
254 } else {
255 _this.$el.find('.'+_this.htmlClassPrefix+'charts-main-container').css('box-shadow', 'unset');
256 }
257 _this.chartObject.update();
258 });
259
260 _this.$el.find('#'+_this.htmlClassPrefix+'option-box-shadow-color').on('input', function () {
261 if (_this.$el.find('#'+_this.htmlClassPrefix+'option-box-shadow').is(':checked')) {
262 _this.chartSourceData.settings.box_shadow_color = $(this).val();
263 _this.$el.find('.'+_this.htmlClassPrefix+'charts-main-container').css('box-shadow', '2px 2px 10px 2px ' + _this.chartSourceData.settings.box_shadow_color);
264 _this.chartObject.update();
265 }
266 });
267
268 _this.$el.find('#'+_this.htmlClassPrefix+'option-padding-outer').on('input', function () {
269 _this.chartSourceData.settings.padding_outer = $(this).val();
270 _this.$el.find('.'+_this.htmlClassPrefix+'container').css('padding', $(this).val() + 'px');
271 _this.chartObject.update();
272 });
273
274 //title
275 _this.$el.find('#'+_this.htmlClassPrefix+'option-title-gap').on('input', function () {
276 _this.chartSourceData.settings.title_gap = $(this).val();
277 _this.$el.find('.'+_this.htmlClassPrefix+'header-container').attr('style', 'margin-bottom: ' + $(this).val() + 'px' + ' !important;');
278 _this.chartObject.update();
279 });
280
281 _this.$el.find('#'+_this.htmlClassPrefix+'option-title-color').on('input', function () {
282 _this.chartSourceData.settings.title_color = $(this).val();
283 _this.$el.find('.'+_this.htmlClassPrefix+'charts-title').css('color', $(this).val());
284 _this.chartObject.update();
285 });
286
287 _this.$el.find('#'+_this.htmlClassPrefix+'option-title-font-size').on('input', function () {
288 _this.chartSourceData.settings.title_font_size = $(this).val();
289 _this.$el.find('.'+_this.htmlClassPrefix+'charts-title').css('font-size', $(this).val() + 'px');
290 _this.chartObject.update();
291 });
292
293 _this.$el.find('#'+_this.htmlClassPrefix+'option-title-bold').on('change', function () {
294 _this.chartSourceData.settings.title_bold = $(this).is(':checked') ? 'checked' : '';
295 _this.$el.find('.'+_this.htmlClassPrefix+'charts-title').css('font-weight', $(this).is(':checked') ? 'bold' : 'normal');
296 _this.chartObject.update();
297 });
298
299 _this.$el.find('#'+_this.htmlClassPrefix+'option-title-italic').on('change', function () {
300 _this.chartSourceData.settings.title_italic = $(this).is(':checked') ? 'checked' : '';
301 _this.$el.find('.'+_this.htmlClassPrefix+'charts-title').css('font-style', $(this).is(':checked') ? 'italic' : 'normal');
302 _this.chartObject.update();
303 });
304
305 _this.$el.find('#'+_this.htmlClassPrefix+'option-title-text-shadow').on('change', function () {
306 if ($(this).is(':checked')) {
307 _this.$el.find('.'+_this.htmlClassPrefix+'charts-title').css('text-shadow', '2px 2px 5px ' + _this.chartSourceData.settings.title_shadow_color);
308 } else {
309 _this.$el.find('.'+_this.htmlClassPrefix+'charts-title').css('text-shadow', 'unset');
310 }
311 _this.chartObject.update();
312 });
313
314 _this.$el.find('#'+_this.htmlClassPrefix+'option-title-shadow-color').on('input', function () {
315 if (_this.$el.find('#'+_this.htmlClassPrefix+'option-title-text-shadow').is(':checked')) {
316 _this.chartSourceData.settings.title_shadow_color = $(this).val();
317 _this.$el.find('.'+_this.htmlClassPrefix+'charts-title').css('text-shadow', '2px 2px 5px ' + $(this).val());
318 _this.chartObject.update();
319 }
320 });
321
322 _this.$el.find('#'+_this.htmlClassPrefix+'option-title-position').on('change', function () {
323 _this.chartSourceData.settings.title_position = $(this).val();
324 _this.$el.find('.'+_this.htmlClassPrefix+'charts-title').css('text-align', $(this).val());
325 _this.chartObject.update();
326 });
327
328 _this.$el.find('#'+_this.htmlClassPrefix+'option-title-text-transform').on('change', function () {
329 _this.chartSourceData.settings.title_transform = $(this).val();
330 _this.$el.find('.'+_this.htmlClassPrefix+'charts-title').css('text-transform', $(this).val());
331 _this.chartObject.update();
332 });
333
334 _this.$el.find('#'+_this.htmlClassPrefix+'option-title-text-decoration').on('change', function () {
335 _this.chartSourceData.settings.title_decoration = $(this).val();
336 _this.$el.find('.'+_this.htmlClassPrefix+'charts-title').css('text-decoration', $(this).val());
337 _this.chartObject.update();
338 });
339
340 _this.$el.find('#'+_this.htmlClassPrefix+'option-title-letter-spacing').on('input', function () {
341 _this.chartSourceData.settings.title_letter_spacing = $(this).val();
342 _this.$el.find('.'+_this.htmlClassPrefix+'charts-title').css('letter-spacing', $(this).val() + 'px');
343 _this.chartObject.update();
344 });
345
346 _this.$el.find('#'+_this.htmlClassPrefix+'option-title-gap-description').on('input', function () {
347 _this.chartSourceData.settings.title_gap_description = $(this).val();
348 _this.$el.find('.'+_this.htmlClassPrefix+'charts-title').css('margin-bottom', $(this).val() + 'px');
349 _this.chartObject.update();
350 });
351
352 // description
353 _this.$el.find('#'+_this.htmlClassPrefix+'description').on('input', function () {
354 _this.$el.find('.'+_this.htmlClassPrefix+'charts-description').text($(this).val());
355 });
356
357 _this.$el.find('#'+_this.htmlClassPrefix+'option-description-color').on('input', function () {
358 _this.chartSourceData.settings.description_color = $(this).val();
359 _this.$el.find('.'+_this.htmlClassPrefix+'charts-description').css('color', $(this).val());
360 _this.chartObject.update();
361 });
362
363 _this.$el.find('#'+_this.htmlClassPrefix+'option-description-font-size').on('input', function () {
364 _this.chartSourceData.settings.description_font_size = $(this).val();
365 _this.$el.find('.'+_this.htmlClassPrefix+'charts-description').css('font-size', $(this).val() + 'px');
366 _this.chartObject.update();
367 });
368
369 _this.$el.find('#'+_this.htmlClassPrefix+'option-description-bold').on('change', function () {
370 _this.chartSourceData.settings.description_bold = $(this).is(':checked') ? 'checked' : '';
371 _this.$el.find('.'+_this.htmlClassPrefix+'charts-description').css('font-weight', $(this).is(':checked') ? 'bold' : 'normal');
372 _this.chartObject.update();
373 });
374
375 _this.$el.find('#'+_this.htmlClassPrefix+'option-description-italic').on('change', function () {
376 _this.chartSourceData.settings.description_italic = $(this).is(':checked') ? 'checked' : '';
377 _this.$el.find('.'+_this.htmlClassPrefix+'charts-description').css('font-style', $(this).is(':checked') ? 'italic' : 'normal');
378 _this.chartObject.update();
379 });
380
381 _this.$el.find('#'+_this.htmlClassPrefix+'option-description-text-shadow').on('change', function () {
382 if ($(this).is(':checked')) {
383 _this.$el.find('.'+_this.htmlClassPrefix+'charts-description').css('text-shadow', '2px 2px 5px ' + _this.chartSourceData.settings.description_shadow_color);
384 } else {
385 _this.$el.find('.'+_this.htmlClassPrefix+'charts-description').css('text-shadow', 'unset');
386 }
387 _this.chartObject.update();
388 });
389
390 _this.$el.find('#'+_this.htmlClassPrefix+'option-description-shadow-color').on('input', function () {
391 if (_this.$el.find('#'+_this.htmlClassPrefix+'option-description-text-shadow').is(':checked')) {
392 _this.chartSourceData.settings.description_shadow_color = $(this).val();
393 _this.$el.find('.'+_this.htmlClassPrefix+'charts-description').css('text-shadow', '2px 2px 5px ' + $(this).val());
394 _this.chartObject.update();
395 }
396 });
397
398 _this.$el.find('#'+_this.htmlClassPrefix+'option-description-position').on('change', function () {
399 _this.chartSourceData.settings.description_position = $(this).val();
400 _this.$el.find('.'+_this.htmlClassPrefix+'charts-description').css('text-align', $(this).val());
401 _this.chartObject.update();
402 });
403
404 _this.$el.find('#'+_this.htmlClassPrefix+'option-description-text-transform').on('change', function () {
405 _this.chartSourceData.settings.description_transform = $(this).val();
406 _this.$el.find('.'+_this.htmlClassPrefix+'charts-description').css('text-transform', $(this).val());
407 _this.chartObject.update();
408 });
409
410 _this.$el.find('#'+_this.htmlClassPrefix+'option-description-text-decoration').on('change', function () {
411 _this.chartSourceData.settings.description_decoration = $(this).val();
412 _this.$el.find('.'+_this.htmlClassPrefix+'charts-description').css('text-decoration', $(this).val());
413 _this.chartObject.update();
414 });
415
416 _this.$el.find('#'+_this.htmlClassPrefix+'option-description-letter-spacing').on('input', function () {
417 _this.chartSourceData.settings.description_letter_spacing = $(this).val();
418 _this.$el.find('.'+_this.htmlClassPrefix+'charts-description').css('letter-spacing', $(this).val() + 'px');
419 _this.chartObject.update();
420 });
421
422 // advanced options
423 _this.$el.find('#'+_this.htmlClassPrefix+'option-outer-radius').on('input', function () {
424 _this.chartSourceData.settings.outer_radius = $(this).val();
425 _this.chartObject.options.radius = _this.chartSourceData.settings.outer_radius;
426 _this.chartObject.update();
427 });
428
429 _this.$el.find('#'+_this.htmlClassPrefix+'option-slice-spacing').on('input', function () {
430 _this.chartSourceData.settings.slice_spacing = $(this).val();
431 _this.chartObject.options.spacing = _this.chartSourceData.settings.slice_spacing;
432 _this.chartObject.update();
433 });
434
435 _this.$el.find('#'+_this.htmlClassPrefix+'option-circumference').on('input', function () {
436 _this.chartSourceData.settings.circumference = $(this).val();
437 _this.chartObject.options.circumference = _this.chartSourceData.settings.circumference;
438 _this.chartObject.update();
439 });
440
441 _this.$el.find('#'+_this.htmlClassPrefix+'option-start-angle').on('input', function () {
442 _this.chartSourceData.settings.start_angle = $(this).val();
443 _this.chartObject.options.rotation = _this.chartSourceData.settings.start_angle;
444 _this.chartObject.update();
445 });
446
447 // Slices settings
448 _this.$el.find('.'+_this.htmlClassPrefix+'option-slice-color').on('input', function () {
449 var id = $(this).attr('data-slice-id');
450 _this.chartSourceData.settings.slice_color[id] = $(this).val();
451 if (_this.chartObject.data.datasets[0].backgroundColor) {
452 _this.chartObject.data.datasets[0].backgroundColor[id] = $(this).val();
453 }
454 _this.chartObject.update();
455 });
456
457 _this.$el.find('.'+_this.htmlClassPrefix+'option-slice-border-color').on('input', function () {
458 var id = $(this).attr('data-slice-id');
459 _this.chartSourceData.settings.slices_border_color[id] = $(this).val();
460 if (_this.chartObject.data.datasets[0].borderColor) {
461 _this.chartObject.data.datasets[0].borderColor[id] = $(this).val();
462 }
463 _this.chartObject.update();
464 });
465
466 _this.$el.find('#'+_this.htmlClassPrefix+'option-slice-border-color').on('input', function () {
467 _this.chartSourceData.settings.slice_border_color = $(this).val();
468 _this.chartObject.options.borderColor = _this.chartSourceData.settings.slice_border_color;
469 _this.chartObject.update();
470 });
471
472 _this.$el.find('#' + _this.htmlClassPrefix + 'option-slice-border-width').on('input', function () {
473 const val = parseInt($(this).val(), 10) || 0;
474 _this.chartSourceData.settings.slice_border_width = val;
475 _this.chartObject.data.datasets[0].borderWidth = val;
476 _this.chartObject.update();
477 });
478
479 //tooltip settings
480 _this.$el.find('#'+_this.htmlClassPrefix+'option-tooltip-text-color').on('input', function () {
481 _this.chartSourceData.settings.tooltip_text_color = $(this).val();
482 _this.chartObject.options.plugins.tooltip.titleColor = _this.chartSourceData.settings.tooltip_text_color;
483 _this.chartObject.options.plugins.tooltip.bodyColor = _this.chartSourceData.settings.tooltip_text_color;
484 _this.chartObject.update();
485 });
486
487 // legend settings
488 _this.$el.find('#'+_this.htmlClassPrefix+'option-legend-position').on('change', function () {
489 _this.chartSourceData.settings.legend_position = $(this).val();
490 _this.chartObject.options.plugins.legend.position = _this.chartSourceData.settings.legend_position;
491 _this.chartObject.update();
492 });
493
494 _this.$el.find('#'+_this.htmlClassPrefix+'option-legend-alignment').on('change', function () {
495 _this.chartSourceData.settings.legend_alignment = $(this).val();
496 _this.chartObject.options.plugins.legend.align = _this.chartSourceData.settings.legend_alignment;
497 _this.chartObject.update();
498 });
499
500 _this.$el.find('#'+_this.htmlClassPrefix+'option-legend-font-color').on('input', function () {
501 _this.chartSourceData.settings.legend_font_color = $(this).val();
502 _this.chartObject.options.plugins.legend.labels.color = _this.chartSourceData.settings.legend_font_color;
503 _this.chartObject.update();
504 });
505
506 _this.$el.find('#'+_this.htmlClassPrefix+'option-legend-font-size').on('input', function () {
507 _this.chartSourceData.settings.legend_font_size = $(this).val();
508 _this.chartObject.options.plugins.legend.labels.font.size = _this.chartSourceData.settings.legend_font_size;
509 _this.chartObject.update();
510 });
511
512 _this.$el.find('#'+_this.htmlClassPrefix+'option-legend-reverse').on('change', function () {
513 _this.chartSourceData.settings.legend_reverse = $(this).is(':checked');
514 _this.chartObject.options.plugins.legend.reverse = _this.chartSourceData.settings.legend_reverse ? 'checked' : '';
515 _this.chartObject.update();
516 });
517
518 _this.$el.find('#'+_this.htmlClassPrefix+'option-legend-italic').on('change', function () {
519 _this.chartSourceData.settings.legend_italic = $(this).is(':checked');
520 _this.chartObject.options.plugins.legend.labels.font.style = _this.chartSourceData.settings.legend_italic ? 'italic' : 'normal';
521 _this.chartObject.update();
522 });
523
524 _this.$el.find('#'+_this.htmlClassPrefix+'option-legend-bold').on('change', function () {
525 _this.chartSourceData.settings.legend_bold = $(this).is(':checked');
526 _this.chartObject.options.plugins.legend.labels.font.weight = _this.chartSourceData.settings.legend_bold ? 'bold' : 'normal';
527 _this.chartObject.update();
528 });
529
530 }
531
532 ChartBuilderChartsJs.prototype.detectManualChange = function (e) {
533 var input = $(document).find('input[name="ays_source_type"]');
534 if (input.val() !== 'manual') input.val('manual');
535 }
536
537 ChartBuilderChartsJs.prototype.keyBoardConfig = function(e) {
538 if (e.which == 13) {
539 if ($(document).find("#ays-charts-form-chart-js").length !== 0 || $(document).find("#ays-settings-form").length !== 0) {
540 var parent = $(e.target).parents('.ays-chart-chart-source-data-edit-block');
541 var index = $(e.target).parents('.ays-chart-chart-source-data-input-box').index();
542 index = parent.index() == 0 ? index - 1 : index - 2;
543
544 if (e.shiftKey) {
545 var prevRow;
546 if (parent.prev('.ays-chart-chart-source-data-edit-block').length === 0) {
547 return false;
548 }
549 prevRow = parent.prev('.ays-chart-chart-source-data-edit-block');
550
551 prevRow.children('.ays-chart-chart-source-data-input-box').eq(index).find('.ays-text-input').focus();
552 } else {
553 var nextRow;
554 if (parent.next('.ays-chart-chart-source-data-edit-block').length === 0) {
555 this.addChartDataRow();
556 }
557 nextRow = parent.next('.ays-chart-chart-source-data-edit-block');
558
559 nextRow.children('.ays-chart-chart-source-data-input-box').eq(index).find('.ays-text-input').focus();
560 }
561
562 return false;
563 }
564 }
565 }
566
567 // Change tabs (tabulation)
568 ChartBuilderChartsJs.prototype.changeTabs = function(e){
569 if(! $(this).hasClass('no-js')){
570 var elemenetID = $(this).attr('href');
571 var active_tab = $(this).attr('data-tab');
572 $(document).find('.nav-tab-wrapper a.nav-tab').each(function () {
573 if ($(this).hasClass('nav-tab-active')) {
574 $(this).removeClass('nav-tab-active');
575 }
576 });
577 $(this).addClass('nav-tab-active');
578 $(document).find('.ays-tab-content').each(function () {
579 $(this).removeClass('ays-tab-content-active');
580 });
581 $(document).find("[name='ays_chart_tab']").val(active_tab);
582 $('.ays-tab-content' + elemenetID).addClass('ays-tab-content-active');
583 e.preventDefault();
584 }
585 }
586
587 ChartBuilderChartsJs.prototype.changeCurrentUrl = function(key){
588 var linkModified = location.href.split('?')[1].split('&');
589 for(var i = 0; i < linkModified.length; i++){
590 if(linkModified[i].split("=")[0] == key){
591 linkModified.splice(i, 1);
592 }
593 }
594 linkModified = linkModified.join('&');
595 window.history.replaceState({}, document.title, '?'+linkModified);
596 }
597
598 ChartBuilderChartsJs.prototype.toggleDDmenu = function(e){
599 var ddmenu = $(this).next();
600 var state = ddmenu.attr('data-expanded');
601 switch (state) {
602 case 'true':
603 $(this).find('.ays_fa').css({
604 transform: 'rotate(0deg)'
605 });
606 ddmenu.attr('data-expanded', 'false');
607 break;
608 case 'false':
609 $(this).find('.ays_fa').css({
610 transform: 'rotate(90deg)'
611 });
612 ddmenu.attr('data-expanded', 'true');
613 break;
614 }
615 }
616
617 ChartBuilderChartsJs.prototype.submitOnce = function(el) {
618 setTimeout(function() {
619 $(document).find('.ays-chart-loader-banner').attr('disabled', true);
620 }, 50);
621
622 setTimeout(function() {
623 $(document).find('.ays-chart-loader-banner').attr('disabled', false);
624 }, 5000);
625 }
626
627 // Load charts by given type main function
628 ChartBuilderChartsJs.prototype.initLibraries = function (){
629 var _this = this;
630
631 _this.$el.find('#ays-chart-option-create-author').select2({
632 placeholder: aysChartBuilderAdmin.selectUser,
633 minimumInputLength: 1,
634 allowClear: true,
635 language: {
636 searching: function() {
637 return aysChartBuilderAdmin.searching;
638 },
639 inputTooShort: function () {
640 return aysChartBuilderAdmin.pleaseEnterMore;
641 }
642 },
643 ajax: {
644 url: ajaxurl,
645 dataType: 'json',
646 data: function (response) {
647 var checkedUsers = _this.$el.find('#ays-chart-option-create-author').val();
648 return {
649 action: _this.ajaxAction,
650 function: window.aysChartBuilderChartSettings.ajax['actions']['author_user_search'],
651 security: window.aysChartBuilderChartSettings.ajax['nonces']['author_user_search'],
652 params: {
653 search: response.term,
654 val: checkedUsers
655 }
656 };
657 }
658 }
659 });
660
661 _this.$el.find('.' + _this.htmlClassPrefix + 'chart-source-data-content').sortable({
662 items: "> div." + _this.htmlClassPrefix + "chart-source-data-edit-block:not(:first)",
663 handle: "." + _this.htmlClassPrefix + "chart-source-data-move-row",
664 update: function (event, ui) {
665 _this.$el.find('div.' + _this.htmlClassPrefix + 'chart-source-data-edit-block:not(:first)').each(function (index) {
666 $(this).attr('data-source-id', index + 1);
667 $(this).find("input.ays-text-input").attr('name', 'ays_chart_source_data[' + (index + 1) + '][]')
668 });
669 }
670 });
671 }
672
673 // Load charts by given type main function
674 ChartBuilderChartsJs.prototype.loadChartBySource = function(isChangedType = false){
675 var _this = this;
676
677 if( ! _this.chartType ){
678 _this.chartType = _this.chartSourceData.chartType;
679 }
680
681 if(typeof _this.chartType !== undefined && _this.chartType){
682 switch (_this.chartType) {
683 case 'pie_chart':
684 _this.pieChartView(isChangedType);
685 break;
686 case 'bar_chart':
687 _this.barChartView(isChangedType);
688 break;
689 case 'line_chart':
690 _this.lineChartView(isChangedType);
691 break;
692 default:
693 _this.pieChartView(isChangedType);
694 break;
695 }
696 }
697 }
698
699 Chart.register({
700 id: 'hoverGlowPlugin',
701 beforeDraw(chart) {
702 if (chart.config.type !== 'pie') {
703 return;
704 }
705 const ctx = chart.ctx;
706 const activeElements = chart.getActiveElements();
707
708 if (activeElements.length === 0) {
709 return;
710 }
711 const meta = chart.getDatasetMeta(activeElements[0].datasetIndex);
712 const element = meta.data[activeElements[0].index];
713
714 if (!element) {
715 return;
716 }
717 const sliceColor = element.options.backgroundColor || 'rgba(0, 0, 0, 1)';
718 ctx.save();
719 ctx.shadowColor = sliceColor;
720 ctx.shadowBlur = 15;
721 ctx.shadowOffsetX = 0;
722 ctx.shadowOffsetY = 0;
723
724 element.draw(ctx);
725 ctx.restore();
726 }
727 });
728
729 // Load chart by pie chart
730 ChartBuilderChartsJs.prototype.pieChartView = function(isChangedType){
731 var _this = this;
732 var getChartSource = _this.chartSourceData.source;
733
734 var dataTypes = _this.chartConvertData( getChartSource );
735
736 var settings = _this.chartSourceData.settings;
737 var nSettings = _this.configOptionsForCharts(settings);
738
739 var ctx = document.getElementById(_this.htmlClassPrefix + '-canvas');
740
741 ctx.width = nSettings.chartWidth;
742 ctx.height = nSettings.chartHeight;
743
744 if (nSettings.chartWidthFormat === 'px') {
745 ctx.width = parseInt(nSettings.chartWidth);
746 } else if (nSettings.chartWidthFormat === '%') {
747 ctx.style.width = nSettings.chartWidth + '%';
748 }
749
750 if (nSettings.chartHeightFormat === 'px') {
751 ctx.height = parseInt(nSettings.chartHeight);
752 } else if (nSettings.chartHeightFormat === '%') {
753 ctx.style.height = nSettings.chartHeight + '%';
754 }
755
756 var sliceCount = dataTypes?.dataSets[0]?.data?.length || 0;
757 dataTypes.dataSets[0].backgroundColor = [];
758 dataTypes.dataSets[0].borderColor = [];
759
760 for (var i = 0; i < sliceCount; i++) {
761 dataTypes.dataSets[0].backgroundColor[i] = nSettings.sliceColor?.[i] || nSettings.sliceColorDefault?.[i % nSettings.sliceColorDefault.length];
762 dataTypes.dataSets[0].borderColor[i] = nSettings.slicesBorderColor?.[i] || 'transparent';
763 }
764 dataTypes.dataSets[0].borderWidth = nSettings.sliceBorderWidth;
765 _this.chartObject = new Chart(ctx, {
766 type: 'pie',
767 data: {
768 labels: dataTypes?.labels,
769 datasets: dataTypes?.dataSets,
770 },
771 options: {
772 radius: nSettings.outerRadius,
773 spacing: nSettings.sliceSpacing,
774 circumference: nSettings.circumference,
775 rotation: nSettings.startAngle,
776 borderColor: nSettings.sliceBorderColor,
777 plugins: {
778 maintainAspectRatio: false,
779 tooltip:{
780 titleColor: nSettings.tooltipColor,
781 bodyColor: nSettings.tooltipColor,
782 footerColor: nSettings.tooltipColor,
783 position: 'nearest',
784 },
785 legend: {
786 position: nSettings.legendPosition,
787 reverse: nSettings.legendReverse,
788 align: nSettings.legendAlignment,
789 labels: {
790 color: nSettings.legendColor,
791 font: {
792 size: nSettings.legendFontSize,
793 weight: nSettings.legendBoldText ? 'bold' : 'normal',
794 style: nSettings.legendItalicText ? 'italic' : 'normal'
795 }
796 }
797 }
798 }
799 }
800 });
801
802 _this.resizeChart();
803 }
804
805 // Load chart by bar chart
806 ChartBuilderChartsJs.prototype.barChartView = function(isChangedType){
807 var _this = this;
808 var getChartSource = _this.chartSourceData.source;
809
810 var dataTypes = _this.chartConvertData( getChartSource );
811
812 var settings = _this.chartSourceData.settings;
813 var nSettings = _this.configOptionsForCharts(settings);
814
815 var ctx = document.getElementById(_this.htmlClassPrefix + '-canvas');
816
817 ctx.width = nSettings.chartWidth;
818 ctx.height = nSettings.chartHeight;
819
820 if (nSettings.chartWidthFormat === 'px') {
821 ctx.width = parseInt(nSettings.chartWidth);
822 } else if (nSettings.chartWidthFormat === '%') {
823 ctx.style.width = nSettings.chartWidth + '%';
824 }
825
826 if (nSettings.chartHeightFormat === 'px') {
827 ctx.height = parseInt(nSettings.chartHeight);
828 } else if (nSettings.chartHeightFormat === '%') {
829 ctx.style.height = nSettings.chartHeight + '%';
830 }
831
832 _this.chartObject = new Chart(ctx, {
833 type: 'bar',
834 data: {
835 labels: dataTypes?.labels,
836 datasets: dataTypes?.dataSets,
837 },
838 options: {
839 maintainAspectRatio: false,
840 // indexAxis: nSettings.indexAxis,
841 plugins: {
842 tooltip:{
843 titleColor: nSettings.tooltipColor,
844 bodyColor: nSettings.tooltipColor,
845 footerColor: nSettings.tooltipColor,
846 },
847 legend: {
848 position: nSettings.legendPosition,
849 align: nSettings.legendAlignment,
850 labels: {
851 color: nSettings.legendColor,
852 font: {
853 size: nSettings.legendFontSize,
854 weight: nSettings.legendBoldText ? 'bold' : 'normal',
855 style: nSettings.legendItalicText ? 'italic' : 'normal'
856 }
857 }
858 }
859 }
860 }
861 });
862
863 _this.resizeChart();
864 }
865
866 // Load chart by line chart
867 ChartBuilderChartsJs.prototype.lineChartView = function(isChangedType){
868 var _this = this;
869 var getChartSource = _this.chartSourceData.source;
870
871 var dataTypes = _this.chartConvertData( getChartSource );
872
873 var settings = _this.chartSourceData.settings;
874 var nSettings = _this.configOptionsForCharts(settings);
875
876 var ctx = document.getElementById(_this.htmlClassPrefix + '-canvas');
877
878 ctx.width = nSettings.chartWidth;
879 ctx.height = nSettings.chartHeight;
880
881 if (nSettings.chartWidthFormat === 'px') {
882 ctx.width = parseInt(nSettings.chartWidth);
883 } else if (nSettings.chartWidthFormat === '%') {
884 ctx.style.width = nSettings.chartWidth + '%';
885 }
886
887 if (nSettings.chartHeightFormat === 'px') {
888 ctx.height = parseInt(nSettings.chartHeight);
889 } else if (nSettings.chartHeightFormat === '%') {
890 ctx.style.height = nSettings.chartHeight + '%';
891 }
892 _this.chartObject = new Chart(ctx, {
893 type: 'line',
894 data: {
895 labels: dataTypes?.labels,
896 datasets: dataTypes?.dataSets,
897 },
898 options: {
899 maintainAspectRatio: false,
900 // indexAxis: nSettings.indexAxis,
901 plugins: {
902 tooltip:{
903 titleColor: nSettings.tooltipColor,
904 bodyColor: nSettings.tooltipColor,
905 footerColor: nSettings.tooltipColor,
906 },
907 legend: {
908 position: nSettings.legendPosition,
909 align: nSettings.legendAlignment,
910 labels: {
911 color: nSettings.legendColor,
912 font: {
913 size: nSettings.legendFontSize,
914 weight: nSettings.legendBoldText ? 'bold' : 'normal',
915 style: nSettings.legendItalicText ? 'italic' : 'normal'
916 }
917 }
918 }
919 }
920 }
921 });
922
923 _this.resizeChart();
924 }
925
926 /*
927 Configure all settings for all chart types
928 Getting settings for each chart type in respective function
929 */
930 ChartBuilderChartsJs.prototype.configOptionsForCharts = function (settings) {
931 var newSettings = {};
932
933 // newSettings.indexAxis = (settings['index_axis'] == 'checked') ? 'y' : 'x';
934 newSettings.chartWidth = parseInt(settings['chart_width']);
935 newSettings.chartWidthFormat = settings['chart_width_format'];
936 newSettings.chartHeight = settings['chart_height'];
937 newSettings.chartHeightFormat = settings['chart_height_format'];
938 newSettings.outerRadius = settings['outer_radius'];
939 newSettings.sliceSpacing = settings['slice_spacing'];
940 newSettings.circumference = settings['circumference'];
941 newSettings.startAngle = settings['start_angle'];
942 newSettings.sliceColor = settings['slice_color'];
943 newSettings.slicesBorderColor = settings['slices_border_color'];
944 newSettings.sliceColorDefault = settings['slice_colors_default'];
945 newSettings.sliceBorderWidth = settings['slice_border_width'];
946 newSettings.sliceBorderColor = settings['slice_border_color'];
947 newSettings.legendColor = settings['legend_color'];
948 newSettings.legendPosition = settings['legend_position'];
949 newSettings.legendAlignment = settings['legend_alignment'];
950 newSettings.legendFontSize = settings['legend_font_size'];
951 newSettings.legendItalicText = (settings['legend_italic'] == 'checked') ? true : false;
952 newSettings.legendBoldText = (settings['legend_bold'] == 'checked') ? true : false;
953 newSettings.legendReverse = settings['legend_reverse'];
954 newSettings.tooltipColor = settings['tooltip_text_color'];
955 return newSettings;
956 }
957
958 // Detect window resize moment to draw charts responsively
959 ChartBuilderChartsJs.prototype.resizeChart = function(){
960 var _this = this;
961
962 //create trigger to resizeEnd event
963 $(window).resize(function() {
964 if(this.resizeTO) clearTimeout(this.resizeTO);
965 this.resizeTO = setTimeout(function() {
966 $(this).trigger('resizeEnd');
967 }, 100);
968 });
969
970 //redraw graph when window resize is completed
971 $(window).on('resizeEnd', function() {
972 _this.chartObject.resize();
973 });
974
975 }
976
977 ChartBuilderChartsJs.prototype.chartConvertData = function( data ){
978 var _this = this;
979 var dataTypes = [];
980
981 var dataTypes = Array.from({ length: data[0].length }, () => []);
982 for (var i = 0; i < data.length; i++) {
983 for (var j = 0; j < data[i].length; j++) {
984 if (i === 0) {
985 dataTypes[j].push(data[i][j]);
986 } else {
987 dataTypes[j].push(i === 0 || j === 0 ? data[i][j] : +data[i][j]);
988 }
989 }
990 }
991
992 var labels = dataTypes.shift();
993 labels.shift();
994 var dataSets = dataTypes.map(item => ({
995 label: item[0],
996 data: item.slice(1).map(Number),
997 }));
998
999 return {labels, dataSets};
1000 }
1001
1002 // Update chart data and display immediately
1003 ChartBuilderChartsJs.prototype.updateChartData = function(){
1004 var _this = this;
1005 var newData = _this.chartConvertData( _this.chartData );
1006
1007 _this.chartObject.data = {
1008 ..._this.chartObject.data,
1009 labels: newData?.labels,
1010 datasets: newData?.dataSets,
1011 },
1012 _this.chartObject.update();
1013 }
1014
1015 ChartBuilderChartsJs.prototype.addChartDataRow = function (element){
1016 var _this = this;
1017 var content = '';
1018
1019 var addedTermsandConds = this.$el.find("."+this.htmlClassPrefix+"chart-source-data-edit-block");
1020 var addedTermsandCondsId = this.$el.find("."+this.htmlClassPrefix+"chart-source-data-edit-block:last-child");
1021 var dataId = addedTermsandConds.length >= 1 ? addedTermsandCondsId.data("sourceId") + 1 : 1;
1022 var colCount = addedTermsandConds.first().children().length - 1;
1023
1024 var termsCondsMessageAttrName = this.newTermsCondsMessageAttrName( this.htmlNamePrefix + 'chart_source_data' , dataId );
1025
1026 content += '<div class = "'+this.htmlClassPrefix+'chart-source-data-edit-block" data-source-id="' + dataId + '" >';
1027 content += '<div class="'+this.htmlClassPrefix+'chart-source-data-move-block '+this.htmlClassPrefix+'chart-source-data-move-row">';
1028 content += '<svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 512 512"><path d="M278.6 9.4c-12.5-12.5-32.8-12.5-45.3 0l-64 64c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l9.4-9.4V224H109.3l9.4-9.4c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-64 64c-12.5 12.5-12.5 32.8 0 45.3l64 64c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3l-9.4-9.4H224V402.7l-9.4-9.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l64 64c12.5 12.5 32.8 12.5 45.3 0l64-64c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-9.4 9.4V288H402.7l-9.4 9.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l64-64c12.5-12.5 12.5-32.8 0-45.3l-64-64c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l9.4 9.4H288V109.3l9.4 9.4c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3l-64-64z" style="fill: #b8b8b8;" /></svg>';
1029 content += '</div>';
1030 content += '<div class="'+this.htmlClassPrefix+'icons-box '+this.htmlClassPrefix+'icons-remove-box">';
1031 content += '<svg class="'+this.htmlClassPrefix+'chart-source-data-remove-block '+this.htmlClassPrefix+'chart-source-data-remove-row" data-trigger="hover" data-bs-toggle="tooltip" title="Delete row" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><path d="M310.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L160 210.7 54.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L114.7 256 9.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L160 301.3 265.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L205.3 256 310.6 150.6z" style="fill: #b8b8b8;" /></svg>';
1032 content += '</div>';
1033 for (var i = 0; i < colCount; i++) {
1034 if (i == 0) {
1035 content += '<div class="'+this.htmlClassPrefix+'chart-source-data-input-box '+this.htmlClassPrefix+'chart-source-data-name-input-box" data-cell-id="'+i+'">';
1036 content += '<input type="text" class="ays-text-input form-control" name="' + termsCondsMessageAttrName + '">';
1037 content += '</div>';
1038 } else {
1039 content += '<div class="'+this.htmlClassPrefix+'chart-source-data-input-box '+this.htmlClassPrefix+'chart-source-data-input-number" data-cell-id="'+i+'">';
1040 content += '<input type="number" class="ays-text-input form-control" name="' + termsCondsMessageAttrName + '" step="any">';
1041 content += '</div>';
1042 }
1043 }
1044 content += '</div>';
1045
1046 this.$el.find('.'+this.htmlClassPrefix+'chart-source-data-content').append(content);
1047 $('[data-bs-toggle="tooltip"]').tooltip();
1048 }
1049
1050 ChartBuilderChartsJs.prototype.addChartDataColumn = function (e){
1051 var _this = this;
1052
1053 var rows = _this.$el.find("."+_this.htmlClassPrefix+"chart-source-data-content").children();
1054 var lastColId = +$(rows[0]).find('.'+_this.htmlClassPrefix+'chart-source-data-input-box:last-child').attr('data-cell-id');
1055 rows.each(function(key, row){
1056 var dataIDEach = row.getAttribute('data-source-id');
1057 var content = '';
1058
1059 if (key === 0) {
1060 content += '<div class="'+_this.htmlClassPrefix+'chart-source-data-input-box ' +_this.htmlClassPrefix+'chart-source-title-box" data-cell-id="'+(lastColId+1)+'">';
1061 content += '<svg class="'+_this.htmlClassPrefix+'chart-source-data-remove-block '+_this.htmlClassPrefix+'chart-source-data-remove-col" data-trigger="hover" data-bs-toggle="tooltip" title="Delete column" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512" width="10px">';
1062 content += '<path d="M310.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L160 210.7 54.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L114.7 256 9.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L160 301.3 265.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L205.3 256 310.6 150.6z" style="fill: #b8b8b8;" />';
1063 content += '</svg>';
1064
1065 content += '<div class="' + _this.htmlClassPrefix + 'chart-source-data-titles-box-item">';
1066 content += '<input type="text" class="ays-text-input form-control ' + _this.htmlClassPrefix+'chart-source-title-input" name="' + _this.newTermsCondsMessageAttrName( _this.htmlNamePrefix + 'chart_source_data' , dataIDEach ) + '">';
1067 content += '<svg class="' + _this.htmlClassPrefix + 'chart-source-data-sort" data-sort-order="asc" xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 320 512">';
1068 content += '<path d="M137.4 41.4c12.5-12.5 32.8-12.5 45.3 0l128 128c9.2 9.2 11.9 22.9 6.9 34.9s-16.6 19.8-29.6 19.8H32c-12.9 0-24.6-7.8-29.6-19.8s-2.2-25.7 6.9-34.9l128-128zm0 429.3l-128-128c-9.2-9.2-11.9-22.9-6.9-34.9s16.6-19.8 29.6-19.8H288c12.9 0 24.6 7.8 29.6 19.8s2.2 25.7-6.9 34.9l-128 128c-12.5 12.5-32.8 12.5-45.3 0z" style="fill: #b8b8b8;" />';
1069 content += '</svg>';
1070 content += '</div>'
1071 content += '</div>';
1072 } else {
1073 content += '<div class="'+_this.htmlClassPrefix+'chart-source-data-input-box ' +_this.htmlClassPrefix+'chart-source-data-input-number" data-cell-id="'+(lastColId+1)+'">';
1074 content += '<input type="number" class="ays-text-input form-control" name="' + _this.newTermsCondsMessageAttrName( _this.htmlNamePrefix + 'chart_source_data' , dataIDEach ) + '" step="any">';
1075 content += '</div>';
1076 }
1077
1078 $(row).append(content);
1079 $('[data-bs-toggle="tooltip"]').tooltip();
1080 });
1081 }
1082
1083 ChartBuilderChartsJs.prototype.deleteChartDataRow = function (element){
1084 var _this = this;
1085
1086 var rows = _this.$el.find("."+_this.htmlClassPrefix+"chart-source-data-content").children();
1087 if ((rows.length - 1) >= 2) {
1088 var confirm = window.confirm(aysChartBuilderAdmin.confirmRowDelete);
1089 if (confirm) {
1090 var thisMainParent = element.parent().parent();
1091 thisMainParent.remove();
1092 }
1093 } else {
1094 alert(aysChartBuilderAdmin.minRowNotice);
1095 }
1096
1097 element.blur();
1098 element.tooltip('hide');
1099 }
1100
1101 ChartBuilderChartsJs.prototype.deleteChartDataColumn = function (element){
1102 var _this = this;
1103
1104 var rows = _this.$el.find("."+_this.htmlClassPrefix+"chart-source-data-content").children();
1105 if (rows.eq(1).children('.ays-chart-chart-source-data-input-number').length >= 2) {
1106 var confirm = window.confirm(aysChartBuilderAdmin.confirmColDelete);
1107 if (confirm) {
1108 var parent = element.parents('.ays-chart-chart-source-title-box');
1109 var index = _this.returnIndexOfEl(parent);
1110 rows.each(function(key, row){
1111 var dataRow = $(row).find('.ays-chart-chart-source-data-input-box:not("ays-chart-chart-source-data-name-input-box")');
1112 $(dataRow).each(function(ind, cell){
1113 if (ind == index) {
1114 $(cell).remove();
1115 }
1116 });
1117 });
1118 }
1119 } else {
1120 alert(aysChartBuilderAdmin.minColNotice);
1121 }
1122
1123 element.blur();
1124 element.tooltip('hide');
1125 }
1126
1127 ChartBuilderChartsJs.prototype.sortDataByColumn = function (el) {
1128 var _this = this;
1129
1130 var sortingOrder = el.attr('data-sort-order');
1131 var colFirst = el.parents('.'+_this.htmlClassPrefix+'chart-source-data-input-box');
1132 var colIndex = colFirst.attr('data-cell-id');
1133 var colList = colFirst.parents('.'+_this.htmlClassPrefix+'chart-source-data-content').find('.'+_this.htmlClassPrefix+'chart-source-data-input-box[data-cell-id="'+colIndex+'"] input.ays-text-input');
1134
1135 var sorted = {};
1136 colList.each(function(key, input){
1137 if (key !== 0) {
1138 var rowIndex = $(input).parents('.'+_this.htmlClassPrefix+'chart-source-data-edit-block').attr('data-source-id');
1139 sorted[rowIndex] = +input.value
1140 }
1141 });
1142
1143 if (sortingOrder === 'asc') {
1144 sorted = _this.sortDataAsc(sorted);
1145 el.attr('data-sort-order', 'desc');
1146 } else if (sortingOrder === 'desc') {
1147 sorted = _this.sortDataDesc(sorted);
1148 el.attr('data-sort-order', 'asc');
1149 } else {
1150 sorted = _this.sortDataAsc(sorted);
1151 el.attr('data-sort-order', 'desc');
1152 }
1153
1154 var container = _this.$el.find('.'+_this.htmlClassPrefix+'chart-source-data-content');
1155 var newContainer = [];
1156 sorted.forEach((index, newIndex) => {
1157 var row = container.find("."+_this.htmlClassPrefix+"chart-source-data-edit-block[data-source-id='"+index+"']");
1158 var inputs = row.find('input.ays-text-input');
1159 var inputName = _this.newTermsCondsMessageAttrName(_this.htmlNamePrefix + 'chart_source_data', newIndex + 1);
1160
1161 $(inputs).each(function (inputIndex, input) {
1162 input.setAttribute('name', inputName);
1163 });
1164
1165 newContainer.push(row);
1166 });
1167 sorted.forEach((index, newIndex) => {
1168 var row = container.find("."+_this.htmlClassPrefix+"chart-source-data-edit-block[data-source-id='"+index+"']");
1169 newContainer.push(row);
1170 });
1171
1172 container.innerHTML = '';
1173 newContainer.forEach(row => {
1174 container.append(row);
1175 });
1176
1177 var rows = container.find("."+_this.htmlClassPrefix+"chart-source-data-edit-block");
1178 for (var i = 0; i < rows.length; i++) {
1179 $(rows[i]).attr('data-source-id', i);
1180 }
1181 }
1182
1183 ChartBuilderChartsJs.prototype.sortDataAsc = function (data) {
1184 return Object.keys(data).sort(function (a, b) {return data[a] - data[b]});
1185 }
1186
1187 ChartBuilderChartsJs.prototype.sortDataDesc = function (data) {
1188 return Object.keys(data).sort(function (a, b) {return data[b] - data[a]});
1189 }
1190
1191 ChartBuilderChartsJs.prototype.returnIndexOfEl = function (element){
1192 var i = 0;
1193 var elements = element.parent().find('.ays-chart-chart-source-title-box');
1194 elements.each(function(key, cell){
1195 if ($(cell).is(element)) {
1196 i = key;
1197 }
1198 });
1199 return i;
1200 }
1201
1202 ChartBuilderChartsJs.prototype.configureOptions = function() {
1203 var _this = this;
1204
1205 _this.$el.find('.ays-chart-chart-source-title-box').eq(0).find('.ays-chart-chart-source-data-remove-block').css('visibility', 'hidden');
1206
1207 var removeCols = _this.$el.find('.ays-chart-chart-source-title-box').find('.ays-chart-chart-source-data-remove-block');
1208 if (_this.chartType === 'pie_chart') {
1209 removeCols.css('visibility', 'hidden');
1210 }
1211
1212 var options = _this.$el.find('.cb-changable-opt');
1213 var typeOptions = _this.$el.find('.cb-'+_this.chartType+'-opt');
1214 options.addClass('display_none');
1215 typeOptions.removeClass('display_none');
1216
1217 var manualTabs = _this.$el.find('.cb-changable-manual:not(.cb-'+_this.chartType+'-manual)');
1218 var typeManualTab = _this.$el.find('.cb-'+_this.chartType+'-manual');
1219 manualTabs.remove();
1220 typeManualTab.removeClass('display_none');
1221
1222 var tabs = _this.$el.find('.cb-changable-tab:not(.cb-'+_this.chartType+'-tab)').parents('fieldset.ays-accordion-options-container');
1223 var currentTabs = _this.$el.find('.cb-'+_this.chartType+'-tab').parents('fieldset.ays-accordion-options-container');
1224 tabs.addClass('display_none');
1225 currentTabs.removeClass('display_none');
1226 }
1227
1228 ChartBuilderChartsJs.prototype.newTermsCondsMessageAttrName = function (termCondName, termCondId){
1229 var _this = this;
1230 return termCondName + '['+ termCondId +'][]';
1231 }
1232
1233 ChartBuilderChartsJs.prototype.setAccordionEvents = function(e){
1234 var _this = this;
1235
1236 _this.$el.on('click', '.ays-accordion-options-header', function(e){
1237 _this.openCloseAccordion(e, _this);
1238 });
1239
1240 _this.$el.on('click', '.ays-slices-accordion-options-header', function(e){
1241 _this.openCloseAccordion(e, _this, '-slices');
1242 });
1243
1244 _this.$el.on('click', '.ays-series-accordion-options-header', function(e){
1245 _this.openCloseAccordion(e, _this, '-series');
1246 });
1247
1248 _this.$el.on('click', '.ays-rows-accordion-options-header', function(e){
1249 _this.openCloseAccordion(e, _this, '-rows');
1250 });
1251 }
1252
1253 ChartBuilderChartsJs.prototype.openCloseAccordion = function(e, _this, contType = ""){
1254 var container = $(e.target).parents('.ays' + contType + '-accordion-options-container');
1255 var parent = (contType != "") ? container.parents('.ays-chart' + contType + '-settings') : _this.$el.find('#' + container.parents('.ays-tab-content').attr('id') + ' .ays-accordions-container').eq(0);
1256 var index = (contType != "") ? container.index() : -1;
1257
1258 if( container.attr('data-collapsed') === 'true' ){
1259 _this.closeAllAccordions( parent, contType, index );
1260 setTimeout(() => {
1261 container.find('.ays' + contType + '-accordion-options-content').slideDown();
1262 container.attr('data-collapsed', 'false');
1263 container.find('.ays' + contType + '-accordion-options-header .ays' + contType + '-accordion-arrow').find('path').css('fill', '#008cff');
1264 container.find('.ays' + contType + '-accordion-options-header .ays' + contType + '-accordion-arrow').removeClass('ays' + contType + '-accordion-arrow-right').addClass('ays' + contType + '-accordion-arrow-down');
1265 }, 150);
1266 }else{
1267 setTimeout(() => {
1268 container.find('.ays' + contType + '-accordion-options-content').slideUp();
1269 container.attr('data-collapsed', 'true');
1270 container.find('.ays' + contType + '-accordion-options-header .ays' + contType + '-accordion-arrow').find('path').css('fill', '#c4c4c4');
1271 container.find('.ays' + contType + '-accordion-options-header .ays' + contType + '-accordion-arrow').removeClass('ays' + contType + '-accordion-arrow-down').addClass('ays' + contType + '-accordion-arrow-right');
1272 }, 150);
1273 }
1274 }
1275
1276 ChartBuilderChartsJs.prototype.closeAllAccordions = function( container, contType, index ){
1277 var _this = this;
1278
1279 container.find('.ays' + contType + '-accordion-options-container').each(function (i){
1280 var $this = $(this);
1281 if (i != index) {
1282 setTimeout(() => {
1283 $this.find('.ays' + contType + '-accordion-options-content').slideUp();
1284 $this.attr('data-collapsed', 'true');
1285 $this.find('.ays' + contType + '-accordion-options-header .ays' + contType + '-accordion-arrow').find('path').css('fill', '#c4c4c4');
1286 $this.find('.ays' + contType + '-accordion-options-header .ays' + contType + '-accordion-arrow').removeClass('ays' + contType + '-accordion-arrow-down').addClass('ays' + contType + '-accordion-arrow-right');
1287 }, 150);
1288 }
1289 });
1290 }
1291
1292 ChartBuilderChartsJs.prototype.quickSaveHotKeys = function() {
1293 $(document).on('keydown', function(e){
1294 var saveButton = $(document).find('input#ays-button-apply');
1295 if ( saveButton.length > 0 ) {
1296 if (!(e.which == 83 && e.ctrlKey) && !(e.which == 19)){
1297 return true;
1298 }
1299 saveButton.trigger("click");
1300 e.preventDefault();
1301 return false;
1302 }
1303 });
1304 }
1305
1306 // Manual data preview button
1307 ChartBuilderChartsJs.prototype.showOnChart = function () { // TODO
1308 var _this = this;
1309
1310 var lastId = $(document).find(".ays-chart-chart-source-data-edit-block:last-child").attr('data-source-id');
1311 var chartData = [];
1312
1313 var rowTitles = $(document).find('.ays-chart-chart-source-data-name-input-box');
1314 rowTitles.each(function(key, el) {
1315 var value = $(el).find('input').val();
1316 if ( value == '' ) {
1317 $(el).find('input').val('Option');
1318 }
1319 });
1320
1321 var form = $(document).find("#ays-charts-form-chart-js");
1322 var data = form.serializeFormJSON();
1323
1324 for (var i = 0; i <= lastId; i++) {
1325 if (data['ays_chart_source_data['+i+'][]'] !== undefined) {
1326 var dataRow = data['ays_chart_source_data['+i+'][]'];
1327 var filteredRow = [];
1328 for (var key = 0; key < dataRow.length; key++) {
1329 var value = dataRow[key];
1330 if (value != '') {
1331 filteredRow.push(value);
1332 } else {
1333 if (i == 0) {
1334 filteredRow.push('Title'+key);
1335 } else {
1336 filteredRow.push('0');
1337 }
1338 }
1339 }
1340 if (filteredRow.length != 0) {
1341 chartData.push(filteredRow);
1342 }
1343 }
1344 }
1345
1346 _this.chartData = chartData;
1347 _this.updateChartData();
1348 }
1349
1350 ChartBuilderChartsJs.prototype.htmlDecode = function (input) {
1351 if (!input) return input;
1352
1353 var e = document.createElement('div');
1354 e.innerHTML = input;
1355 return e.childNodes[0].nodeValue;
1356 }
1357
1358 $.fn.ChartBuilderChartsJsMain = function(options) {
1359 return this.each(function() {
1360 if (!$.data(this, 'ChartBuilderChartsJsMain')) {
1361 $.data(this, 'ChartBuilderChartsJsMain', new ChartBuilderChartsJs(this, options));
1362 } else {
1363 try {
1364 $(this).data('ChartBuilderChartsJsMain').init();
1365 } catch (err) {
1366 console.error('ChartBuilderChartsJsMain has not initiated properly');
1367 }
1368 }
1369 });
1370 };
1371 $(document).find('#ays-charts-form-chart-js').ChartBuilderChartsJsMain();
1372
1373 })(jQuery);
1374
1375 (function ($) {
1376
1377 $.fn.serializeFormJSON = function () {
1378 let o = {},
1379 a = this.serializeArray();
1380 $.each(a, function () {
1381 if (o[this.name]) {
1382 if (!o[this.name].push) {
1383 o[this.name] = [o[this.name]];
1384 }
1385 o[this.name].push(this.value || '');
1386 } else {
1387 o[this.name] = this.value || '';
1388 }
1389 });
1390 return o;
1391 };
1392
1393 $.fn.lock = function () {
1394 $(this).each(function () {
1395 var $this = $(this);
1396 var position = $this.css('position');
1397
1398 if (!position) {
1399 position = 'static';
1400 }
1401
1402 switch (position) {
1403 case 'absolute':
1404 case 'relative':
1405 break;
1406 default:
1407 $this.css('position', 'relative');
1408 break;
1409 }
1410 $this.data('position', position);
1411
1412 var width = $this.width(),
1413 height = $this.height();
1414
1415 var locker = $('<div class="locker"></div>');
1416 locker.width(width).height(height);
1417
1418 var loader = $('<div class="locker-loader"></div>');
1419 loader.width(width).height(height);
1420
1421 locker.append(loader);
1422 $this.append(locker);
1423 $(window).resize(function () {
1424 $this.find('.locker,.locker-loader').width($this.width()).height($this.height());
1425 });
1426 });
1427
1428 return $(this);
1429 };
1430
1431 $.fn.unlock = function () {
1432 $(this).each(function () {
1433 $(this).find('.locker').remove();
1434 $(this).css('position', $(this).data('position'));
1435 });
1436
1437 return $(this);
1438 };
1439 })(jQuery);