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