PluginProbe
Chartify – WordPress Chart Plugin / 3.8.1
Chartify – WordPress Chart Plugin v3.8.1
3.8.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 All 84 releases
chart-builder / admin / js / chart-builder-admin-chartjs.js

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

1,798 lines 70.5 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 _this.$el.find('#'+_this.htmlClassPrefix+'option-rotation-degree').on('input', function () {
448 _this.chartSourceData.settings.rotation_degree = $(this).val();
449 _this.chartObject.options.rotation = _this.chartSourceData.settings.rotation_degree;
450 _this.chartObject.update();
451 });
452
453 _this.$el.find('#'+_this.htmlClassPrefix+'option-data-grouping-limit, #'+_this.htmlClassPrefix+'option-data-grouping-label, #'+_this.htmlClassPrefix+'option-data-grouping-color').on('input', function () {
454 _this.chartSourceData.settings.data_grouping_limit = _this.$el.find('#'+_this.htmlClassPrefix+'option-data-grouping-limit').val();
455 _this.chartSourceData.settings.data_grouping_label = _this.$el.find('#'+_this.htmlClassPrefix+'option-data-grouping-label').val();
456 _this.chartSourceData.settings.data_grouping_color = _this.$el.find('#'+_this.htmlClassPrefix+'option-data-grouping-color').val();
457 _this.chartObject.destroy();
458 _this.loadChartBySource();
459 });
460 // Slices settings
461 _this.$el.find('.'+_this.htmlClassPrefix+'option-slice-color').on('input', function () {
462 var id = $(this).attr('data-slice-id');
463 _this.chartSourceData.settings.slice_color[id] = $(this).val();
464 if (_this.chartObject.data.datasets[0].backgroundColor) {
465 _this.chartObject.data.datasets[0].backgroundColor[id] = $(this).val();
466 }
467 _this.chartObject.update();
468 });
469
470 _this.$el.find('.'+_this.htmlClassPrefix+'option-slice-border-color').on('input', function () {
471 var id = $(this).attr('data-slice-id');
472 _this.chartSourceData.settings.slices_border_color[id] = $(this).val();
473 if (_this.chartObject.data.datasets[0].borderColor) {
474 _this.chartObject.data.datasets[0].borderColor[id] = $(this).val();
475 }
476 _this.chartObject.update();
477 });
478
479 _this.$el.find('#'+_this.htmlClassPrefix+'option-slice-border-color').on('input', function () {
480 _this.chartSourceData.settings.slice_border_color = $(this).val();
481 _this.chartObject.options.borderColor = _this.chartSourceData.settings.slice_border_color;
482 _this.chartObject.update();
483 });
484
485 _this.$el.find('#' + _this.htmlClassPrefix + 'option-slice-border-width').on('input', function () {
486 const val = parseInt($(this).val(), 10) || 0;
487 _this.chartSourceData.settings.slice_border_width = val;
488 _this.chartObject.data.datasets[0].borderWidth = val;
489 _this.chartObject.update();
490 });
491
492 //tooltip settings
493 _this.$el.find('#'+_this.htmlClassPrefix+'option-tooltip-text-color').on('input', function () {
494 _this.chartSourceData.settings.tooltip_text_color = $(this).val();
495 _this.chartObject.options.plugins.tooltip.titleColor = _this.chartSourceData.settings.tooltip_text_color;
496 _this.chartObject.options.plugins.tooltip.bodyColor = _this.chartSourceData.settings.tooltip_text_color;
497 _this.chartObject.update();
498 });
499
500 _this.$el.find('#'+_this.htmlClassPrefix+'option-tooltip-text').on('change', function () {
501 _this.chartSourceData.settings.tooltip_text = $(this).val();
502 _this.chartObject.options.plugins.tooltip.callbacks = _this.getTooltipCallbacks(_this.chartSourceData.settings.tooltip_text, _this.chartSourceData.settings.show_color_code);
503 _this.chartObject.update();
504 });
505
506 _this.$el.find('#'+_this.htmlClassPrefix+'option-show-color-code').on('change', function () {
507 _this.chartSourceData.settings.show_color_code = $(this).is(':checked') ? 'checked' : '';
508 _this.chartObject.options.plugins.tooltip.callbacks = _this.getTooltipCallbacks(_this.chartSourceData.settings.tooltip_text, _this.chartSourceData.settings.show_color_code);
509 _this.chartObject.update();
510 });
511
512 _this.$el.find('#'+_this.htmlClassPrefix+'option-tooltip-italic').on('change', function () {
513 _this.chartSourceData.settings.tooltip_italic = $(this).is(':checked') ? 'checked' : '';
514 _this.updateTooltipItalic();
515 _this.chartObject.update();
516 });
517
518 _this.$el.find('#'+_this.htmlClassPrefix+'option-tooltip-font-size').on('input', function () {
519 _this.chartSourceData.settings.tooltip_font_size = $(this).val();
520 _this.updateTooltipFontSize();
521 _this.chartObject.update();
522 });
523
524 _this.$el.find('#'+_this.htmlClassPrefix+'option-tooltip-bold').on('change', function () {
525 _this.chartSourceData.settings.tooltip_bold = $(this).val();
526 _this.updateTooltipBold();
527 _this.chartObject.update();
528 });
529
530 // legend settings
531 _this.$el.find('#'+_this.htmlClassPrefix+'option-legend-position').on('change', function () {
532 _this.chartSourceData.settings.legend_position = $(this).val();
533 _this.chartObject.options.plugins.legend.position = _this.chartSourceData.settings.legend_position;
534 _this.chartObject.update();
535 });
536
537 _this.$el.find('#'+_this.htmlClassPrefix+'option-legend-alignment').on('change', function () {
538 _this.chartSourceData.settings.legend_alignment = $(this).val();
539 _this.chartObject.options.plugins.legend.align = _this.chartSourceData.settings.legend_alignment;
540 _this.chartObject.update();
541 });
542
543 _this.$el.find('#'+_this.htmlClassPrefix+'option-legend-font-color').on('input', function () {
544 _this.chartSourceData.settings.legend_font_color = $(this).val();
545 _this.chartObject.options.plugins.legend.labels.color = _this.chartSourceData.settings.legend_font_color;
546 _this.chartObject.update();
547 });
548
549 _this.$el.find('#'+_this.htmlClassPrefix+'option-legend-font-size').on('input', function () {
550 _this.chartSourceData.settings.legend_font_size = $(this).val();
551 _this.chartObject.options.plugins.legend.labels.font.size = _this.chartSourceData.settings.legend_font_size;
552 _this.chartObject.update();
553 });
554
555 _this.$el.find('#'+_this.htmlClassPrefix+'option-legend-reverse').on('change', function () {
556 _this.chartSourceData.settings.legend_reverse = $(this).is(':checked');
557 _this.chartObject.options.plugins.legend.reverse = _this.chartSourceData.settings.legend_reverse ? 'checked' : '';
558 _this.chartObject.update();
559 });
560
561 _this.$el.find('#'+_this.htmlClassPrefix+'option-legend-italic').on('change', function () {
562 _this.chartSourceData.settings.legend_italic = $(this).is(':checked');
563 _this.chartObject.options.plugins.legend.labels.font.style = _this.chartSourceData.settings.legend_italic ? 'italic' : 'normal';
564 _this.chartObject.update();
565 });
566
567 _this.$el.find('#'+_this.htmlClassPrefix+'option-legend-bold').on('change', function () {
568 _this.chartSourceData.settings.legend_bold = $(this).is(':checked');
569 _this.chartObject.options.plugins.legend.labels.font.weight = _this.chartSourceData.settings.legend_bold ? 'bold' : 'normal';
570 _this.chartObject.update();
571 });
572
573 // interactivity settings
574 _this.$el.find('#'+_this.htmlClassPrefix+'option-enable-interactivity').on('change', function () {
575 _this.chartSourceData.settings.enable_interactivity = $(this).is(':checked') ? 'checked' : '';
576 _this.updateInteractivity();
577 _this.chartObject.update();
578 });
579
580 }
581
582 ChartBuilderChartsJs.prototype.updateInteractivity = function() {
583 var _this = this;
584 var enableInteractivity = _this.chartSourceData.settings.enable_interactivity === 'checked';
585
586 if (enableInteractivity) {
587 // Enable tooltips and hover
588 _this.chartObject.options.plugins.tooltip.enabled = true;
589 _this.chartObject.options.hover = {
590 mode: 'nearest',
591 intersect: true
592 };
593 } else {
594 // Disable tooltips and hover
595 _this.chartObject.options.plugins.tooltip.enabled = false;
596 _this.chartObject.options.hover = {
597 mode: null,
598 intersect: false
599 };
600 }
601 }
602
603 ChartBuilderChartsJs.prototype.updateTooltipColorCode = function() {
604 var _this = this;
605 _this.chartObject.options.plugins.tooltip.events = ['click'];
606 _this.chartObject.options.plugins.tooltip.callbacks = _this.getTooltipCallbacks(_this.chartSourceData.settings.tooltip_text, _this.chartSourceData.settings.show_color_code);
607 };
608
609 ChartBuilderChartsJs.prototype.updateTooltipItalic = function() {
610 var _this = this;
611 var isItalic = _this.chartSourceData.settings.tooltip_italic === 'checked';
612
613 // Set tooltip font style based on italic setting
614 if (_this.chartObject.options.plugins.tooltip.titleFont) {
615 _this.chartObject.options.plugins.tooltip.titleFont.style = isItalic ? 'italic' : 'normal';
616 } else {
617 _this.chartObject.options.plugins.tooltip.titleFont = {
618 style: isItalic ? 'italic' : 'normal'
619 };
620 }
621
622 if (_this.chartObject.options.plugins.tooltip.bodyFont) {
623 _this.chartObject.options.plugins.tooltip.bodyFont.style = isItalic ? 'italic' : 'normal';
624 } else {
625 _this.chartObject.options.plugins.tooltip.bodyFont = {
626 style: isItalic ? 'italic' : 'normal'
627 };
628 }
629
630 if (_this.chartObject.options.plugins.tooltip.footerFont) {
631 _this.chartObject.options.plugins.tooltip.footerFont.style = isItalic ? 'italic' : 'normal';
632 } else {
633 _this.chartObject.options.plugins.tooltip.footerFont = {
634 style: isItalic ? 'italic' : 'normal'
635 };
636 }
637 }
638
639 ChartBuilderChartsJs.prototype.updateTooltipFontSize = function() {
640 var _this = this;
641 var fontSize = parseInt(_this.chartSourceData.settings.tooltip_font_size) || 12;
642
643 // Set tooltip font size based on setting
644 if (_this.chartObject.options.plugins.tooltip.titleFont) {
645 _this.chartObject.options.plugins.tooltip.titleFont.size = fontSize;
646 } else {
647 _this.chartObject.options.plugins.tooltip.titleFont = {
648 size: fontSize
649 };
650 }
651
652 if (_this.chartObject.options.plugins.tooltip.bodyFont) {
653 _this.chartObject.options.plugins.tooltip.bodyFont.size = fontSize;
654 } else {
655 _this.chartObject.options.plugins.tooltip.bodyFont = {
656 size: fontSize
657 };
658 }
659
660 if (_this.chartObject.options.plugins.tooltip.footerFont) {
661 _this.chartObject.options.plugins.tooltip.footerFont.size = fontSize;
662 } else {
663 _this.chartObject.options.plugins.tooltip.footerFont = {
664 size: fontSize
665 };
666 }
667 }
668
669 ChartBuilderChartsJs.prototype.updateTooltipBold = function() {
670 var _this = this;
671 var boldSetting = _this.chartSourceData.settings.tooltip_bold;
672 var isBold = boldSetting === 'true';
673
674 // Set tooltip font weight based on bold setting
675 if (boldSetting === 'default') {
676 // Use default (remove custom weight)
677 if (_this.chartObject.options.plugins.tooltip.titleFont) {
678 delete _this.chartObject.options.plugins.tooltip.titleFont.weight;
679 }
680 if (_this.chartObject.options.plugins.tooltip.bodyFont) {
681 delete _this.chartObject.options.plugins.tooltip.bodyFont.weight;
682 }
683 if (_this.chartObject.options.plugins.tooltip.footerFont) {
684 delete _this.chartObject.options.plugins.tooltip.footerFont.weight;
685 }
686 } else {
687 var weight = isBold ? 'bold' : 'normal';
688
689 if (_this.chartObject.options.plugins.tooltip.titleFont) {
690 _this.chartObject.options.plugins.tooltip.titleFont.weight = weight;
691 } else {
692 _this.chartObject.options.plugins.tooltip.titleFont = {
693 weight: weight
694 };
695 }
696
697 if (_this.chartObject.options.plugins.tooltip.bodyFont) {
698 _this.chartObject.options.plugins.tooltip.bodyFont.weight = weight;
699 } else {
700 _this.chartObject.options.plugins.tooltip.bodyFont = {
701 weight: weight
702 };
703 }
704
705 if (_this.chartObject.options.plugins.tooltip.footerFont) {
706 _this.chartObject.options.plugins.tooltip.footerFont.weight = weight;
707 } else {
708 _this.chartObject.options.plugins.tooltip.footerFont = {
709 weight: weight
710 };
711 }
712 }
713 }
714
715 ChartBuilderChartsJs.prototype.detectManualChange = function (e) {
716 var input = $(document).find('input[name="ays_source_type"]');
717 if (input.val() !== 'manual') input.val('manual');
718 }
719
720 ChartBuilderChartsJs.prototype.keyBoardConfig = function(e) {
721 if (e.which == 13) {
722 if ($(document).find("#ays-charts-form-chart-js").length !== 0 || $(document).find("#ays-settings-form").length !== 0) {
723 var parent = $(e.target).parents('.ays-chart-chart-source-data-edit-block');
724 var index = $(e.target).parents('.ays-chart-chart-source-data-input-box').index();
725 index = parent.index() == 0 ? index - 1 : index - 2;
726
727 if (e.shiftKey) {
728 var prevRow;
729 if (parent.prev('.ays-chart-chart-source-data-edit-block').length === 0) {
730 return false;
731 }
732 prevRow = parent.prev('.ays-chart-chart-source-data-edit-block');
733
734 prevRow.children('.ays-chart-chart-source-data-input-box').eq(index).find('.ays-text-input').focus();
735 } else {
736 var nextRow;
737 if (parent.next('.ays-chart-chart-source-data-edit-block').length === 0) {
738 this.addChartDataRow();
739 }
740 nextRow = parent.next('.ays-chart-chart-source-data-edit-block');
741
742 nextRow.children('.ays-chart-chart-source-data-input-box').eq(index).find('.ays-text-input').focus();
743 }
744
745 return false;
746 }
747 }
748 }
749
750 // Change tabs (tabulation)
751 ChartBuilderChartsJs.prototype.changeTabs = function(e){
752 if(! $(this).hasClass('no-js')){
753 var elemenetID = $(this).attr('href');
754 var active_tab = $(this).attr('data-tab');
755 $(document).find('.nav-tab-wrapper a.nav-tab').each(function () {
756 if ($(this).hasClass('nav-tab-active')) {
757 $(this).removeClass('nav-tab-active');
758 }
759 });
760 $(this).addClass('nav-tab-active');
761 $(document).find('.ays-tab-content').each(function () {
762 $(this).removeClass('ays-tab-content-active');
763 });
764 $(document).find("[name='ays_chart_tab']").val(active_tab);
765 $('.ays-tab-content' + elemenetID).addClass('ays-tab-content-active');
766 e.preventDefault();
767 }
768 }
769
770 ChartBuilderChartsJs.prototype.changeCurrentUrl = function(key){
771 var linkModified = location.href.split('?')[1].split('&');
772 for(var i = 0; i < linkModified.length; i++){
773 if(linkModified[i].split("=")[0] == key){
774 linkModified.splice(i, 1);
775 }
776 }
777 linkModified = linkModified.join('&');
778 window.history.replaceState({}, document.title, '?'+linkModified);
779 }
780
781 ChartBuilderChartsJs.prototype.toggleDDmenu = function(e){
782 var ddmenu = $(this).next();
783 var state = ddmenu.attr('data-expanded');
784 switch (state) {
785 case 'true':
786 $(this).find('.ays_fa').css({
787 transform: 'rotate(0deg)'
788 });
789 ddmenu.attr('data-expanded', 'false');
790 break;
791 case 'false':
792 $(this).find('.ays_fa').css({
793 transform: 'rotate(90deg)'
794 });
795 ddmenu.attr('data-expanded', 'true');
796 break;
797 }
798 }
799
800 ChartBuilderChartsJs.prototype.submitOnce = function(el) {
801 setTimeout(function() {
802 $(document).find('.ays-chart-loader-banner').attr('disabled', true);
803 }, 50);
804
805 setTimeout(function() {
806 $(document).find('.ays-chart-loader-banner').attr('disabled', false);
807 }, 5000);
808 }
809
810 // Load charts by given type main function
811 ChartBuilderChartsJs.prototype.initLibraries = function (){
812 var _this = this;
813
814 _this.$el.find('#ays-chart-option-create-author').select2({
815 placeholder: aysChartBuilderAdmin.selectUser,
816 minimumInputLength: 1,
817 allowClear: true,
818 language: {
819 searching: function() {
820 return aysChartBuilderAdmin.searching;
821 },
822 inputTooShort: function () {
823 return aysChartBuilderAdmin.pleaseEnterMore;
824 }
825 },
826 ajax: {
827 url: ajaxurl,
828 dataType: 'json',
829 data: function (response) {
830 var checkedUsers = _this.$el.find('#ays-chart-option-create-author').val();
831 return {
832 action: _this.ajaxAction,
833 function: window.aysChartBuilderChartSettings.ajax['actions']['author_user_search'],
834 security: window.aysChartBuilderChartSettings.ajax['nonces']['author_user_search'],
835 params: {
836 search: response.term,
837 val: checkedUsers
838 }
839 };
840 }
841 }
842 });
843
844 _this.$el.find('.' + _this.htmlClassPrefix + 'chart-source-data-content').sortable({
845 items: "> div." + _this.htmlClassPrefix + "chart-source-data-edit-block:not(:first)",
846 handle: "." + _this.htmlClassPrefix + "chart-source-data-move-row",
847 update: function (event, ui) {
848 _this.$el.find('div.' + _this.htmlClassPrefix + 'chart-source-data-edit-block:not(:first)').each(function (index) {
849 $(this).attr('data-source-id', index + 1);
850 $(this).find("input.ays-text-input").attr('name', 'ays_chart_source_data[' + (index + 1) + '][]')
851 });
852 }
853 });
854 }
855
856 // Load charts by given type main function
857 ChartBuilderChartsJs.prototype.loadChartBySource = function(isChangedType = false){
858 var _this = this;
859
860 if( ! _this.chartType ){
861 _this.chartType = _this.chartSourceData.chartType;
862 }
863
864 if(typeof _this.chartType !== undefined && _this.chartType){
865 switch (_this.chartType) {
866 case 'pie_chart':
867 _this.pieChartView(isChangedType);
868 break;
869 case 'bar_chart':
870 _this.barChartView(isChangedType);
871 break;
872 case 'line_chart':
873 _this.lineChartView(isChangedType);
874 break;
875 default:
876 _this.pieChartView(isChangedType);
877 break;
878 }
879 }
880 }
881
882 Chart.register({
883 id: 'hoverGlowPlugin',
884 beforeDraw(chart) {
885 if (chart.config.type !== 'pie') {
886 return;
887 }
888 const ctx = chart.ctx;
889 const activeElements = chart.getActiveElements();
890
891 if (activeElements.length === 0) {
892 return;
893 }
894 const meta = chart.getDatasetMeta(activeElements[0].datasetIndex);
895 const element = meta.data[activeElements[0].index];
896
897 if (!element) {
898 return;
899 }
900 const sliceColor = element.options.backgroundColor || 'rgba(0, 0, 0, 1)';
901 ctx.save();
902 ctx.shadowColor = sliceColor;
903 ctx.shadowBlur = 15;
904 ctx.shadowOffsetX = 0;
905 ctx.shadowOffsetY = 0;
906
907 element.draw(ctx);
908 ctx.restore();
909 }
910 });
911
912 // Load chart by pie chart
913 ChartBuilderChartsJs.prototype.pieChartView = function(isChangedType){
914 var _this = this;
915 var getChartSource = _this.chartSourceData.source;
916
917 var dataTypes = _this.chartConvertData( getChartSource );
918
919 var settings = _this.chartSourceData.settings;
920 var nSettings = _this.configOptionsForCharts(settings);
921 _this.applyPieDataGrouping(dataTypes, nSettings);
922
923 var ctx = document.getElementById(_this.htmlClassPrefix + '-canvas');
924
925 ctx.width = nSettings.chartWidth;
926 ctx.height = nSettings.chartHeight;
927
928 if (nSettings.chartWidthFormat === 'px') {
929 ctx.width = parseInt(nSettings.chartWidth);
930 } else if (nSettings.chartWidthFormat === '%') {
931 ctx.style.width = nSettings.chartWidth + '%';
932 }
933
934 if (nSettings.chartHeightFormat === 'px') {
935 ctx.height = parseInt(nSettings.chartHeight);
936 } else if (nSettings.chartHeightFormat === '%') {
937 ctx.style.height = nSettings.chartHeight + '%';
938 }
939
940 var sliceCount = dataTypes?.dataSets[0]?.data?.length || 0;
941 dataTypes.dataSets[0].backgroundColor = [];
942 dataTypes.dataSets[0].borderColor = [];
943
944 for (var i = 0; i < sliceCount; i++) {
945 dataTypes.dataSets[0].backgroundColor[i] = i === dataTypes.dataSets[0].groupedSliceIndex ? nSettings.dataGroupingColor : (nSettings.sliceColor?.[i] || nSettings.sliceColorDefault?.[i % nSettings.sliceColorDefault.length]);
946 dataTypes.dataSets[0].borderColor[i] = nSettings.slicesBorderColor?.[i] || 'transparent';
947 }
948 dataTypes.dataSets[0].borderWidth = nSettings.sliceBorderWidth;
949 _this.chartObject = new Chart(ctx, {
950 type: 'pie',
951 data: {
952 labels: dataTypes?.labels,
953 datasets: dataTypes?.dataSets,
954 },
955 options: {
956 radius: nSettings.outerRadius,
957 spacing: nSettings.sliceSpacing,
958 circumference: nSettings.circumference,
959 rotation: nSettings.rotationDegree,
960 borderColor: nSettings.sliceBorderColor,
961 plugins: {
962 maintainAspectRatio: false,
963 tooltip:{
964 titleColor: nSettings.tooltipColor,
965 bodyColor: nSettings.tooltipColor,
966 footerColor: nSettings.tooltipColor,
967 titleFont: {
968 size: nSettings.tooltipFontSize || 12,
969 style: nSettings.tooltipItalicText ? 'italic' : 'normal',
970 weight: nSettings.tooltipBoldText === 'true' ? 'bold' : (nSettings.tooltipBoldText === 'false' ? 'normal' : undefined)
971 },
972 bodyFont: {
973 size: nSettings.tooltipFontSize || 12,
974 style: nSettings.tooltipItalicText ? 'italic' : 'normal',
975 weight: nSettings.tooltipBoldText === 'true' ? 'bold' : (nSettings.tooltipBoldText === 'false' ? 'normal' : undefined)
976 },
977 footerFont: {
978 size: nSettings.tooltipFontSize || 12,
979 style: nSettings.tooltipItalicText ? 'italic' : 'normal',
980 weight: nSettings.tooltipBoldText === 'true' ? 'bold' : (nSettings.tooltipBoldText === 'false' ? 'normal' : undefined)
981 },
982 position: 'nearest',
983 events: ['click'],
984 callbacks: _this.getTooltipCallbacks(nSettings.tooltipText, nSettings.showColorCode)
985 },
986 legend: {
987 position: nSettings.legendPosition,
988 reverse: nSettings.legendReverse,
989 align: nSettings.legendAlignment,
990 labels: {
991 color: nSettings.legendColor,
992 font: {
993 size: nSettings.legendFontSize,
994 weight: nSettings.legendBoldText ? 'bold' : 'normal',
995 style: nSettings.legendItalicText ? 'italic' : 'normal'
996 }
997 }
998 }
999 }
1000 }
1001 });
1002
1003 _this.resizeChart();
1004 }
1005
1006 // Load chart by bar chart
1007 ChartBuilderChartsJs.prototype.barChartView = function(isChangedType){
1008 var _this = this;
1009 var getChartSource = _this.chartSourceData.source;
1010
1011 var dataTypes = _this.chartConvertData( getChartSource );
1012
1013 var settings = _this.chartSourceData.settings;
1014 var nSettings = _this.configOptionsForCharts(settings);
1015
1016 var ctx = document.getElementById(_this.htmlClassPrefix + '-canvas');
1017
1018 ctx.width = nSettings.chartWidth;
1019 ctx.height = nSettings.chartHeight;
1020
1021 if (nSettings.chartWidthFormat === 'px') {
1022 ctx.width = parseInt(nSettings.chartWidth);
1023 } else if (nSettings.chartWidthFormat === '%') {
1024 ctx.style.width = nSettings.chartWidth + '%';
1025 }
1026
1027 if (nSettings.chartHeightFormat === 'px') {
1028 ctx.height = parseInt(nSettings.chartHeight);
1029 } else if (nSettings.chartHeightFormat === '%') {
1030 ctx.style.height = nSettings.chartHeight + '%';
1031 }
1032
1033 _this.chartObject = new Chart(ctx, {
1034 type: 'bar',
1035 data: {
1036 labels: dataTypes?.labels,
1037 datasets: dataTypes?.dataSets,
1038 },
1039 options: {
1040 maintainAspectRatio: false,
1041 // indexAxis: nSettings.indexAxis,
1042 plugins: {
1043 tooltip:{
1044 titleColor: nSettings.tooltipColor,
1045 bodyColor: nSettings.tooltipColor,
1046 footerColor: nSettings.tooltipColor,
1047 titleFont: {
1048 size: nSettings.tooltipFontSize || 12,
1049 style: nSettings.tooltipItalicText ? "italic" : "normal",
1050 weight: nSettings.tooltipBoldText === 'true' ? 'bold' : (nSettings.tooltipBoldText === 'false' ? 'normal' : undefined)
1051 },
1052 bodyFont: {
1053 size: nSettings.tooltipFontSize || 12,
1054 style: nSettings.tooltipItalicText ? "italic" : "normal",
1055 weight: nSettings.tooltipBoldText === 'true' ? 'bold' : (nSettings.tooltipBoldText === 'false' ? 'normal' : undefined)
1056 },
1057 footerFont: {
1058 size: nSettings.tooltipFontSize || 12,
1059 style: nSettings.tooltipItalicText ? "italic" : "normal",
1060 weight: nSettings.tooltipBoldText === 'true' ? 'bold' : (nSettings.tooltipBoldText === 'false' ? 'normal' : undefined)
1061 }
1062 },
1063 legend: {
1064 position: nSettings.legendPosition,
1065 align: nSettings.legendAlignment,
1066 labels: {
1067 color: nSettings.legendColor,
1068 font: {
1069 size: nSettings.legendFontSize,
1070 weight: nSettings.legendBoldText ? 'bold' : 'normal',
1071 style: nSettings.legendItalicText ? 'italic' : 'normal'
1072 }
1073 }
1074 }
1075 }
1076 }
1077 });
1078
1079 _this.resizeChart();
1080 }
1081
1082 // Load chart by line chart
1083 ChartBuilderChartsJs.prototype.lineChartView = function(isChangedType){
1084 var _this = this;
1085 var getChartSource = _this.chartSourceData.source;
1086
1087 var dataTypes = _this.chartConvertData( getChartSource );
1088
1089 var settings = _this.chartSourceData.settings;
1090 var nSettings = _this.configOptionsForCharts(settings);
1091
1092 var ctx = document.getElementById(_this.htmlClassPrefix + '-canvas');
1093
1094 ctx.width = nSettings.chartWidth;
1095 ctx.height = nSettings.chartHeight;
1096
1097 if (nSettings.chartWidthFormat === 'px') {
1098 ctx.width = parseInt(nSettings.chartWidth);
1099 } else if (nSettings.chartWidthFormat === '%') {
1100 ctx.style.width = nSettings.chartWidth + '%';
1101 }
1102
1103 if (nSettings.chartHeightFormat === 'px') {
1104 ctx.height = parseInt(nSettings.chartHeight);
1105 } else if (nSettings.chartHeightFormat === '%') {
1106 ctx.style.height = nSettings.chartHeight + '%';
1107 }
1108 _this.chartObject = new Chart(ctx, {
1109 type: 'line',
1110 data: {
1111 labels: dataTypes?.labels,
1112 datasets: dataTypes?.dataSets,
1113 },
1114 options: {
1115 maintainAspectRatio: false,
1116 // indexAxis: nSettings.indexAxis,
1117 plugins: {
1118 tooltip:{
1119 titleColor: nSettings.tooltipColor,
1120 bodyColor: nSettings.tooltipColor,
1121 footerColor: nSettings.tooltipColor,
1122 titleFont: {
1123 size: nSettings.tooltipFontSize || 12,
1124 style: nSettings.tooltipItalicText ? "italic" : "normal",
1125 weight: nSettings.tooltipBoldText === 'true' ? 'bold' : (nSettings.tooltipBoldText === 'false' ? 'normal' : undefined)
1126 },
1127 bodyFont: {
1128 size: nSettings.tooltipFontSize || 12,
1129 style: nSettings.tooltipItalicText ? "italic" : "normal",
1130 weight: nSettings.tooltipBoldText === 'true' ? 'bold' : (nSettings.tooltipBoldText === 'false' ? 'normal' : undefined)
1131 },
1132 footerFont: {
1133 size: nSettings.tooltipFontSize || 12,
1134 style: nSettings.tooltipItalicText ? "italic" : "normal",
1135 weight: nSettings.tooltipBoldText === 'true' ? 'bold' : (nSettings.tooltipBoldText === 'false' ? 'normal' : undefined)
1136 }
1137 },
1138 legend: {
1139 position: nSettings.legendPosition,
1140 align: nSettings.legendAlignment,
1141 labels: {
1142 color: nSettings.legendColor,
1143 font: {
1144 size: nSettings.legendFontSize,
1145 weight: nSettings.legendBoldText ? 'bold' : 'normal',
1146 style: nSettings.legendItalicText ? 'italic' : 'normal'
1147 }
1148 }
1149 }
1150 }
1151 }
1152 });
1153
1154 _this.resizeChart();
1155 }
1156
1157 /*
1158 Configure all settings for all chart types
1159 Getting settings for each chart type in respective function
1160 */
1161 ChartBuilderChartsJs.prototype.configOptionsForCharts = function (settings) {
1162 var newSettings = {};
1163
1164 // newSettings.indexAxis = (settings['index_axis'] == 'checked') ? 'y' : 'x';
1165 newSettings.chartWidth = parseInt(settings['chart_width']);
1166 newSettings.chartWidthFormat = settings['chart_width_format'];
1167 newSettings.chartHeight = settings['chart_height'];
1168 newSettings.chartHeightFormat = settings['chart_height_format'];
1169 newSettings.outerRadius = settings['outer_radius'];
1170 newSettings.sliceSpacing = settings['slice_spacing'];
1171 newSettings.circumference = settings['circumference'];
1172 newSettings.startAngle = settings['start_angle'];
1173 newSettings.rotationDegree = settings['rotation_degree'];
1174 newSettings.sliceColor = settings['slice_color'];
1175 newSettings.slicesBorderColor = settings['slices_border_color'];
1176 newSettings.sliceColorDefault = settings['slice_colors_default'];
1177 newSettings.sliceBorderWidth = settings['slice_border_width'];
1178 newSettings.sliceBorderColor = settings['slice_border_color'];
1179 newSettings.dataGroupingLimit = parseFloat(settings['data_grouping_limit']) / 100;
1180 newSettings.dataGroupingLabel = settings['data_grouping_label'];
1181 newSettings.dataGroupingColor = settings['data_grouping_color'];
1182 newSettings.legendColor = settings['legend_color'];
1183 newSettings.legendPosition = settings['legend_position'];
1184 newSettings.legendAlignment = settings['legend_alignment'];
1185 newSettings.legendFontSize = settings['legend_font_size'];
1186 newSettings.legendItalicText = (settings['legend_italic'] == 'checked') ? true : false;
1187 newSettings.legendBoldText = (settings['legend_bold'] == 'checked') ? true : false;
1188 newSettings.legendReverse = settings['legend_reverse'];
1189 newSettings.tooltipColor = settings['tooltip_text_color'];
1190 newSettings.showColorCode = settings['show_color_code'];
1191 newSettings.tooltipItalicText = (settings['tooltip_italic'] == 'checked') ? true : false;
1192 newSettings.tooltipFontSize = settings['tooltip_font_size'];
1193 newSettings.tooltipBoldText = settings['tooltip_bold'];
1194 newSettings.tooltipText = settings['tooltip_text'];
1195 return newSettings;
1196 }
1197
1198 ChartBuilderChartsJs.prototype.applyPieDataGrouping = function (dataTypes, settings) {
1199 var groupingLimit = parseFloat(settings.dataGroupingLimit);
1200 var dataSet = dataTypes && dataTypes.dataSets && dataTypes.dataSets[0];
1201
1202 if (!(groupingLimit > 0) || !dataSet || !Array.isArray(dataSet.data)) {
1203 return;
1204 }
1205
1206 var total = dataSet.data.reduce(function (sum, value) {
1207 return sum + (Number(value) || 0);
1208 }, 0);
1209 var groupedValue = 0;
1210 var groupedSlices = 0;
1211 var labels = [];
1212 var values = [];
1213
1214 dataSet.data.forEach(function (value, index) {
1215 var numericValue = Number(value) || 0;
1216 if (total > 0 && numericValue / total < groupingLimit) {
1217 groupedValue += numericValue;
1218 groupedSlices++;
1219 } else {
1220 labels.push(dataTypes.labels[index]);
1221 values.push(numericValue);
1222 }
1223 });
1224
1225 if (groupedSlices > 0) {
1226 dataTypes.labels = labels.concat([settings.dataGroupingLabel]);
1227 dataSet.data = values.concat([groupedValue]);
1228 dataSet.groupedSliceIndex = values.length;
1229 }
1230 }
1231
1232 // Detect window resize moment to draw charts responsively
1233 ChartBuilderChartsJs.prototype.resizeChart = function(){
1234 var _this = this;
1235
1236 //create trigger to resizeEnd event
1237 $(window).resize(function() {
1238 if(this.resizeTO) clearTimeout(this.resizeTO);
1239 this.resizeTO = setTimeout(function() {
1240 $(this).trigger('resizeEnd');
1241 }, 100);
1242 });
1243
1244 //redraw graph when window resize is completed
1245 $(window).on('resizeEnd', function() {
1246 _this.chartObject.resize();
1247 });
1248
1249 }
1250
1251 ChartBuilderChartsJs.prototype.chartConvertData = function( data ){
1252 var _this = this;
1253 var dataTypes = [];
1254
1255 var dataTypes = Array.from({ length: data[0].length }, () => []);
1256 for (var i = 0; i < data.length; i++) {
1257 for (var j = 0; j < data[i].length; j++) {
1258 if (i === 0) {
1259 dataTypes[j].push(data[i][j]);
1260 } else {
1261 dataTypes[j].push(i === 0 || j === 0 ? data[i][j] : +data[i][j]);
1262 }
1263 }
1264 }
1265
1266 var labels = dataTypes.shift();
1267 labels.shift();
1268 var dataSets = dataTypes.map(item => ({
1269 label: item[0],
1270 data: item.slice(1).map(Number),
1271 }));
1272
1273 return {labels, dataSets};
1274 }
1275
1276 // Update chart data and display immediately
1277 ChartBuilderChartsJs.prototype.updateChartData = function(){
1278 var _this = this;
1279 var newData = _this.chartConvertData( _this.chartData );
1280
1281 var settings = _this.chartSourceData.settings;
1282 var nSettings = _this.configOptionsForCharts(settings);
1283 var defaultColors = nSettings.sliceColorDefault || ['#36A2EB','#FF6384','#FF9F40','#FFCD56', '#4BC0C0','#0099c6','#dd4477','#66aa00', '#b82e2e','#316395','#994499','#22aa99', '#aaaa11','#6633cc','#e67300','#8b0707', '#651067','#329262','#5574a6','#3b3eac', '#b77322','#16d620','#b91383','#f4359e', '#9c5935','#a9c413','#2a778d','#668d1c', '#bea413','#0c5922','#743411'];
1284
1285 var existingDatasets = _this.chartObject.data.datasets || [];
1286 newData.dataSets = newData.dataSets.map((dataset, index) => {
1287 var existingDataset = existingDatasets[index] || {};
1288
1289 // Handle backgroundColor for pie charts (array of colors per data point)
1290 if (_this.chartType === 'pie_chart' && Array.isArray(existingDataset.backgroundColor)) {
1291 var newBgColor = [...existingDataset.backgroundColor];
1292 for (var i = existingDataset.backgroundColor.length; i < dataset.data.length; i++) {
1293 newBgColor[i] = nSettings.sliceColor?.[i] || defaultColors[i % defaultColors.length];
1294 }
1295 return {
1296 ...dataset,
1297 backgroundColor: newBgColor,
1298 borderColor: existingDataset.borderColor || dataset.borderColor,
1299 borderWidth: existingDataset.borderWidth !== undefined ? existingDataset.borderWidth : dataset.borderWidth
1300 };
1301 }
1302
1303 // Handle backgroundColor for bar/line charts (single color per dataset)
1304 var bgColor = existingDataset.backgroundColor;
1305 var borderColor = existingDataset.borderColor;
1306
1307 if (!bgColor) {
1308 bgColor = defaultColors[index % defaultColors.length];
1309 }
1310 if (!borderColor) {
1311 borderColor = bgColor;
1312 }
1313
1314 return {
1315 ...dataset,
1316 backgroundColor: bgColor,
1317 borderColor: borderColor,
1318 borderWidth: existingDataset.borderWidth !== undefined ? existingDataset.borderWidth : dataset.borderWidth
1319 };
1320 });
1321
1322 _this.chartObject.data = {
1323 ..._this.chartObject.data,
1324 labels: newData?.labels,
1325 datasets: newData?.dataSets,
1326 },
1327 _this.chartObject.update();
1328 }
1329
1330 ChartBuilderChartsJs.prototype.getTooltipCallbacks = function(tooltipText, showColorCode) {
1331 var _this = this;
1332 if (showColorCode === 'checked' || showColorCode === true) {
1333 return {
1334 label: function(context) {
1335 var color = context.dataset.backgroundColor[context.dataIndex];
1336 return ' Color: ' + color;
1337 }
1338 };
1339 } else {
1340 switch(tooltipText) {
1341 case 'percentage':
1342 return {
1343 label: function(context) {
1344 var label = context.label || '';
1345 var value = context.parsed || 0;
1346 var total = context.chart._metasets[context.datasetIndex].total;
1347 var percentage = ((value / total) * 100).toFixed(1) + '%';
1348 return ' ' + label + ': ' + percentage;
1349 }
1350 };
1351 case 'both':
1352 return {
1353 label: function(context) {
1354 var label = context.label || '';
1355 var value = context.parsed || 0;
1356 var total = context.chart._metasets[context.datasetIndex].total;
1357 var percentage = ((value / total) * 100).toFixed(1) + '%';
1358 return ' ' + label + ': ' + value + ' (' + percentage + ')';
1359 }
1360 };
1361 case 'value':
1362 default:
1363 return {
1364 label: function(context) {
1365 var label = context.label || '';
1366 var value = context.parsed || 0;
1367 return ' ' + label + ': ' + value;
1368 }
1369 };
1370 }
1371 }
1372 };
1373
1374 ChartBuilderChartsJs.prototype.addChartDataRow = function (element){
1375 var _this = this;
1376 var content = '';
1377
1378 var addedTermsandConds = this.$el.find("."+this.htmlClassPrefix+"chart-source-data-edit-block");
1379 var addedTermsandCondsId = this.$el.find("."+this.htmlClassPrefix+"chart-source-data-edit-block:last-child");
1380 var dataId = addedTermsandConds.length >= 1 ? addedTermsandCondsId.data("sourceId") + 1 : 1;
1381 var colCount = addedTermsandConds.first().children().length - 1;
1382
1383 var termsCondsMessageAttrName = this.newTermsCondsMessageAttrName( this.htmlNamePrefix + 'chart_source_data' , dataId );
1384
1385 content += '<div class = "'+this.htmlClassPrefix+'chart-source-data-edit-block" data-source-id="' + dataId + '" >';
1386 content += '<div class="'+this.htmlClassPrefix+'chart-source-data-move-block '+this.htmlClassPrefix+'chart-source-data-move-row">';
1387 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>';
1388 content += '</div>';
1389 content += '<div class="'+this.htmlClassPrefix+'icons-box '+this.htmlClassPrefix+'icons-remove-box">';
1390 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>';
1391 content += '</div>';
1392 for (var i = 0; i < colCount; i++) {
1393 if (i == 0) {
1394 content += '<div class="'+this.htmlClassPrefix+'chart-source-data-input-box '+this.htmlClassPrefix+'chart-source-data-name-input-box" data-cell-id="'+i+'">';
1395 content += '<input type="text" class="ays-text-input form-control" name="' + termsCondsMessageAttrName + '">';
1396 content += '</div>';
1397 } else {
1398 content += '<div class="'+this.htmlClassPrefix+'chart-source-data-input-box '+this.htmlClassPrefix+'chart-source-data-input-number" data-cell-id="'+i+'">';
1399 content += '<input type="number" class="ays-text-input form-control" name="' + termsCondsMessageAttrName + '" step="any">';
1400 content += '</div>';
1401 }
1402 }
1403 content += '</div>';
1404
1405 this.$el.find('.'+this.htmlClassPrefix+'chart-source-data-content').append(content);
1406 $('[data-bs-toggle="tooltip"]').tooltip();
1407 }
1408
1409 ChartBuilderChartsJs.prototype.addChartDataColumn = function (e){
1410 var _this = this;
1411
1412 var rows = _this.$el.find("."+_this.htmlClassPrefix+"chart-source-data-content").children();
1413 var lastColId = +$(rows[0]).find('.'+_this.htmlClassPrefix+'chart-source-data-input-box:last-child').attr('data-cell-id');
1414 rows.each(function(key, row){
1415 var dataIDEach = row.getAttribute('data-source-id');
1416 var content = '';
1417
1418 if (key === 0) {
1419 content += '<div class="'+_this.htmlClassPrefix+'chart-source-data-input-box ' +_this.htmlClassPrefix+'chart-source-title-box" data-cell-id="'+(lastColId+1)+'">';
1420 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">';
1421 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;" />';
1422 content += '</svg>';
1423
1424 content += '<div class="' + _this.htmlClassPrefix + 'chart-source-data-titles-box-item">';
1425 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 ) + '">';
1426 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">';
1427 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;" />';
1428 content += '</svg>';
1429 content += '</div>'
1430 content += '</div>';
1431 } else {
1432 content += '<div class="'+_this.htmlClassPrefix+'chart-source-data-input-box ' +_this.htmlClassPrefix+'chart-source-data-input-number" data-cell-id="'+(lastColId+1)+'">';
1433 content += '<input type="number" class="ays-text-input form-control" name="' + _this.newTermsCondsMessageAttrName( _this.htmlNamePrefix + 'chart_source_data' , dataIDEach ) + '" step="any">';
1434 content += '</div>';
1435 }
1436
1437 $(row).append(content);
1438 $('[data-bs-toggle="tooltip"]').tooltip();
1439 });
1440 }
1441
1442 ChartBuilderChartsJs.prototype.deleteChartDataRow = function (element){
1443 var _this = this;
1444
1445 var rows = _this.$el.find("."+_this.htmlClassPrefix+"chart-source-data-content").children();
1446 if ((rows.length - 1) >= 2) {
1447 var confirm = window.confirm(aysChartBuilderAdmin.confirmRowDelete);
1448 if (confirm) {
1449 var thisMainParent = element.parent().parent();
1450 thisMainParent.remove();
1451 }
1452 } else {
1453 alert(aysChartBuilderAdmin.minRowNotice);
1454 }
1455
1456 element.blur();
1457 element.tooltip('hide');
1458 }
1459
1460 ChartBuilderChartsJs.prototype.deleteChartDataColumn = function (element){
1461 var _this = this;
1462
1463 var rows = _this.$el.find("."+_this.htmlClassPrefix+"chart-source-data-content").children();
1464 if (rows.eq(1).children('.ays-chart-chart-source-data-input-number').length >= 2) {
1465 var confirm = window.confirm(aysChartBuilderAdmin.confirmColDelete);
1466 if (confirm) {
1467 var parent = element.parents('.ays-chart-chart-source-title-box');
1468 var index = _this.returnIndexOfEl(parent);
1469 rows.each(function(key, row){
1470 var dataRow = $(row).find('.ays-chart-chart-source-data-input-box:not("ays-chart-chart-source-data-name-input-box")');
1471 $(dataRow).each(function(ind, cell){
1472 if (ind == index) {
1473 $(cell).remove();
1474 }
1475 });
1476 });
1477 }
1478 } else {
1479 alert(aysChartBuilderAdmin.minColNotice);
1480 }
1481
1482 element.blur();
1483 element.tooltip('hide');
1484 }
1485
1486 ChartBuilderChartsJs.prototype.sortDataByColumn = function (el) {
1487 var _this = this;
1488
1489 var sortingOrder = el.attr('data-sort-order');
1490 var colFirst = el.parents('.'+_this.htmlClassPrefix+'chart-source-data-input-box');
1491 var colIndex = colFirst.attr('data-cell-id');
1492 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');
1493
1494 var sorted = {};
1495 colList.each(function(key, input){
1496 if (key !== 0) {
1497 var rowIndex = $(input).parents('.'+_this.htmlClassPrefix+'chart-source-data-edit-block').attr('data-source-id');
1498 sorted[rowIndex] = +input.value
1499 }
1500 });
1501
1502 if (sortingOrder === 'asc') {
1503 sorted = _this.sortDataAsc(sorted);
1504 el.attr('data-sort-order', 'desc');
1505 } else if (sortingOrder === 'desc') {
1506 sorted = _this.sortDataDesc(sorted);
1507 el.attr('data-sort-order', 'asc');
1508 } else {
1509 sorted = _this.sortDataAsc(sorted);
1510 el.attr('data-sort-order', 'desc');
1511 }
1512
1513 var container = _this.$el.find('.'+_this.htmlClassPrefix+'chart-source-data-content');
1514 var newContainer = [];
1515 sorted.forEach((index, newIndex) => {
1516 var row = container.find("."+_this.htmlClassPrefix+"chart-source-data-edit-block[data-source-id='"+index+"']");
1517 var inputs = row.find('input.ays-text-input');
1518 var inputName = _this.newTermsCondsMessageAttrName(_this.htmlNamePrefix + 'chart_source_data', newIndex + 1);
1519
1520 $(inputs).each(function (inputIndex, input) {
1521 input.setAttribute('name', inputName);
1522 });
1523
1524 newContainer.push(row);
1525 });
1526 sorted.forEach((index, newIndex) => {
1527 var row = container.find("."+_this.htmlClassPrefix+"chart-source-data-edit-block[data-source-id='"+index+"']");
1528 newContainer.push(row);
1529 });
1530
1531 container.innerHTML = '';
1532 newContainer.forEach(row => {
1533 container.append(row);
1534 });
1535
1536 var rows = container.find("."+_this.htmlClassPrefix+"chart-source-data-edit-block");
1537 for (var i = 0; i < rows.length; i++) {
1538 $(rows[i]).attr('data-source-id', i);
1539 }
1540 }
1541
1542 ChartBuilderChartsJs.prototype.sortDataAsc = function (data) {
1543 return Object.keys(data).sort(function (a, b) {return data[a] - data[b]});
1544 }
1545
1546 ChartBuilderChartsJs.prototype.sortDataDesc = function (data) {
1547 return Object.keys(data).sort(function (a, b) {return data[b] - data[a]});
1548 }
1549
1550 ChartBuilderChartsJs.prototype.returnIndexOfEl = function (element){
1551 var i = 0;
1552 var elements = element.parent().find('.ays-chart-chart-source-title-box');
1553 elements.each(function(key, cell){
1554 if ($(cell).is(element)) {
1555 i = key;
1556 }
1557 });
1558 return i;
1559 }
1560
1561 ChartBuilderChartsJs.prototype.configureOptions = function() {
1562 var _this = this;
1563
1564 _this.$el.find('.ays-chart-chart-source-title-box').eq(0).find('.ays-chart-chart-source-data-remove-block').css('visibility', 'hidden');
1565
1566 var removeCols = _this.$el.find('.ays-chart-chart-source-title-box').find('.ays-chart-chart-source-data-remove-block');
1567 if (_this.chartType === 'pie_chart') {
1568 removeCols.css('visibility', 'hidden');
1569 }
1570
1571 var options = _this.$el.find('.cb-changable-opt');
1572 var typeOptions = _this.$el.find('.cb-'+_this.chartType+'-opt');
1573 options.addClass('display_none');
1574 typeOptions.removeClass('display_none');
1575
1576 var manualTabs = _this.$el.find('.cb-changable-manual:not(.cb-'+_this.chartType+'-manual)');
1577 var typeManualTab = _this.$el.find('.cb-'+_this.chartType+'-manual');
1578 manualTabs.remove();
1579 typeManualTab.removeClass('display_none');
1580
1581 var tabs = _this.$el.find('.cb-changable-tab:not(.cb-'+_this.chartType+'-tab)').parents('fieldset.ays-accordion-options-container');
1582 var currentTabs = _this.$el.find('.cb-'+_this.chartType+'-tab').parents('fieldset.ays-accordion-options-container');
1583 tabs.addClass('display_none');
1584 currentTabs.removeClass('display_none');
1585 }
1586
1587 ChartBuilderChartsJs.prototype.newTermsCondsMessageAttrName = function (termCondName, termCondId){
1588 var _this = this;
1589 return termCondName + '['+ termCondId +'][]';
1590 }
1591
1592 ChartBuilderChartsJs.prototype.setAccordionEvents = function(e){
1593 var _this = this;
1594
1595 _this.$el.on('click', '.ays-accordion-options-header', function(e){
1596 _this.openCloseAccordion(e, _this);
1597 });
1598
1599 _this.$el.on('click', '.ays-slices-accordion-options-header', function(e){
1600 _this.openCloseAccordion(e, _this, '-slices');
1601 });
1602
1603 _this.$el.on('click', '.ays-series-accordion-options-header', function(e){
1604 _this.openCloseAccordion(e, _this, '-series');
1605 });
1606
1607 _this.$el.on('click', '.ays-rows-accordion-options-header', function(e){
1608 _this.openCloseAccordion(e, _this, '-rows');
1609 });
1610 }
1611
1612 ChartBuilderChartsJs.prototype.openCloseAccordion = function(e, _this, contType = ""){
1613 var container = $(e.target).parents('.ays' + contType + '-accordion-options-container');
1614 var parent = (contType != "") ? container.parents('.ays-chart' + contType + '-settings') : _this.$el.find('#' + container.parents('.ays-tab-content').attr('id') + ' .ays-accordions-container').eq(0);
1615 var index = (contType != "") ? container.index() : -1;
1616
1617 if( container.attr('data-collapsed') === 'true' ){
1618 _this.closeAllAccordions( parent, contType, index );
1619 setTimeout(() => {
1620 container.find('.ays' + contType + '-accordion-options-content').slideDown();
1621 container.attr('data-collapsed', 'false');
1622 container.find('.ays' + contType + '-accordion-options-header .ays' + contType + '-accordion-arrow').find('path').css('fill', '#008cff');
1623 container.find('.ays' + contType + '-accordion-options-header .ays' + contType + '-accordion-arrow').removeClass('ays' + contType + '-accordion-arrow-right').addClass('ays' + contType + '-accordion-arrow-down');
1624 }, 150);
1625 }else{
1626 setTimeout(() => {
1627 container.find('.ays' + contType + '-accordion-options-content').slideUp();
1628 container.attr('data-collapsed', 'true');
1629 container.find('.ays' + contType + '-accordion-options-header .ays' + contType + '-accordion-arrow').find('path').css('fill', '#c4c4c4');
1630 container.find('.ays' + contType + '-accordion-options-header .ays' + contType + '-accordion-arrow').removeClass('ays' + contType + '-accordion-arrow-down').addClass('ays' + contType + '-accordion-arrow-right');
1631 }, 150);
1632 }
1633 }
1634
1635 ChartBuilderChartsJs.prototype.closeAllAccordions = function( container, contType, index ){
1636 var _this = this;
1637
1638 container.find('.ays' + contType + '-accordion-options-container').each(function (i){
1639 var $this = $(this);
1640 if (i != index) {
1641 setTimeout(() => {
1642 $this.find('.ays' + contType + '-accordion-options-content').slideUp();
1643 $this.attr('data-collapsed', 'true');
1644 $this.find('.ays' + contType + '-accordion-options-header .ays' + contType + '-accordion-arrow').find('path').css('fill', '#c4c4c4');
1645 $this.find('.ays' + contType + '-accordion-options-header .ays' + contType + '-accordion-arrow').removeClass('ays' + contType + '-accordion-arrow-down').addClass('ays' + contType + '-accordion-arrow-right');
1646 }, 150);
1647 }
1648 });
1649 }
1650
1651 ChartBuilderChartsJs.prototype.quickSaveHotKeys = function() {
1652 $(document).on('keydown', function(e){
1653 var saveButton = $(document).find('input#ays-button-apply');
1654 if ( saveButton.length > 0 ) {
1655 if (!(e.which == 83 && e.ctrlKey) && !(e.which == 19)){
1656 return true;
1657 }
1658 saveButton.trigger("click");
1659 e.preventDefault();
1660 return false;
1661 }
1662 });
1663 }
1664
1665 // Manual data preview button
1666 ChartBuilderChartsJs.prototype.showOnChart = function () { // TODO
1667 var _this = this;
1668
1669 var lastId = $(document).find(".ays-chart-chart-source-data-edit-block:last-child").attr('data-source-id');
1670 var chartData = [];
1671
1672 var rowTitles = $(document).find('.ays-chart-chart-source-data-name-input-box');
1673 rowTitles.each(function(key, el) {
1674 var value = $(el).find('input').val();
1675 if ( value == '' ) {
1676 $(el).find('input').val('Option');
1677 }
1678 });
1679
1680 var form = $(document).find("#ays-charts-form-chart-js");
1681 var data = form.serializeFormJSON();
1682
1683 for (var i = 0; i <= lastId; i++) {
1684 if (data['ays_chart_source_data['+i+'][]'] !== undefined) {
1685 var dataRow = data['ays_chart_source_data['+i+'][]'];
1686 var filteredRow = [];
1687 for (var key = 0; key < dataRow.length; key++) {
1688 var value = dataRow[key];
1689 if (value != '') {
1690 filteredRow.push(value);
1691 } else {
1692 if (i == 0) {
1693 filteredRow.push('Title'+key);
1694 } else {
1695 filteredRow.push('0');
1696 }
1697 }
1698 }
1699 if (filteredRow.length != 0) {
1700 chartData.push(filteredRow);
1701 }
1702 }
1703 }
1704
1705 _this.chartData = chartData;
1706 _this.updateChartData();
1707 }
1708
1709 ChartBuilderChartsJs.prototype.htmlDecode = function (input) {
1710 if (!input) return input;
1711
1712 var e = document.createElement('div');
1713 e.innerHTML = input;
1714 return e.childNodes[0].nodeValue;
1715 }
1716
1717 $.fn.ChartBuilderChartsJsMain = function(options) {
1718 return this.each(function() {
1719 if (!$.data(this, 'ChartBuilderChartsJsMain')) {
1720 $.data(this, 'ChartBuilderChartsJsMain', new ChartBuilderChartsJs(this, options));
1721 } else {
1722 try {
1723 $(this).data('ChartBuilderChartsJsMain').init();
1724 } catch (err) {
1725 console.error('ChartBuilderChartsJsMain has not initiated properly');
1726 }
1727 }
1728 });
1729 };
1730 $(document).find('#ays-charts-form-chart-js').ChartBuilderChartsJsMain();
1731
1732 })(jQuery);
1733
1734 (function ($) {
1735
1736 $.fn.serializeFormJSON = function () {
1737 let o = {},
1738 a = this.serializeArray();
1739 $.each(a, function () {
1740 if (o[this.name]) {
1741 if (!o[this.name].push) {
1742 o[this.name] = [o[this.name]];
1743 }
1744 o[this.name].push(this.value || '');
1745 } else {
1746 o[this.name] = this.value || '';
1747 }
1748 });
1749 return o;
1750 };
1751
1752 $.fn.lock = function () {
1753 $(this).each(function () {
1754 var $this = $(this);
1755 var position = $this.css('position');
1756
1757 if (!position) {
1758 position = 'static';
1759 }
1760
1761 switch (position) {
1762 case 'absolute':
1763 case 'relative':
1764 break;
1765 default:
1766 $this.css('position', 'relative');
1767 break;
1768 }
1769 $this.data('position', position);
1770
1771 var width = $this.width(),
1772 height = $this.height();
1773
1774 var locker = $('<div class="locker"></div>');
1775 locker.width(width).height(height);
1776
1777 var loader = $('<div class="locker-loader"></div>');
1778 loader.width(width).height(height);
1779
1780 locker.append(loader);
1781 $this.append(locker);
1782 $(window).resize(function () {
1783 $this.find('.locker,.locker-loader').width($this.width()).height($this.height());
1784 });
1785 });
1786
1787 return $(this);
1788 };
1789
1790 $.fn.unlock = function () {
1791 $(this).each(function () {
1792 $(this).find('.locker').remove();
1793 $(this).css('position', $(this).data('position'));
1794 });
1795
1796 return $(this);
1797 };
1798 })(jQuery);