1(function($) { 2 'use strict'; 3 4 /** 5 * All of the code for your public-facing JavaScript source 6 * should reside in this file. 7 * 8 * Note: It has been assumed you will write jQuery code here, so the 9 * $ function reference has been prepared for usage within the scope 10 * of this function. 11 * 12 * This enables you to define handlers, for when the DOM is ready: 13 * 14 * $(function() { 15 * 16 * }); 17 * 18 * When the window is loaded: 19 * 20 * $( window ).load(function() { 21 * 22 * }); 23 * 24 * ...and/or other possibilities. 25 * 26 * Ideally, it is not considered best practise to attach more than a 27 * single DOM-ready or window-load handler for a particular page. 28 * Although scripts in the WordPress core, Plugins and Themes may be 29 * practising this, we should strive to set a better example in our own work. 30 */ 31 32 $(window).on('load', function () { 33 let ele = $('.chart-card'); 34 addRemoveClass(ele.find('h4'), 'graphina-chart-heading'); 35 addRemoveClass(ele.find('p'), 'graphina-chart-sub-heading'); 36 }); 37 38 39 // Graphina Feature Request For Elementor Panel 40 document.addEventListener('DOMContentLoaded', function() { 41 if (parent.document.querySelector('.elementor-editor-active') !== null) { 42 let _graphina_get_help = ''; 43 let _graphina_get_help_url = "https://iqonic.design/feature-request/?for_product=graphina"; 44 setInterval(function() { 45 if (parent.document.querySelector('[class*=elementor-control-iq]') != null) { 46 _graphina_get_help = parent.document.querySelector('#elementor-panel__editor__help__link'); 47 if (_graphina_get_help != null) { 48 if (_graphina_get_help.getAttribute("href") !== _graphina_get_help_url) { 49 _graphina_get_help.setAttribute("href", _graphina_get_help_url); 50 _graphina_get_help.innerHTML = "<b> Graphina Feature Request <i class='eicon-editor-external-link'></i> </b>"; 51 } 52 } 53 } 54 }, 3000) 55 } 56 }); 57 58})(jQuery); 59 60 61/*********************** 62 * Variables 63 */ 64if (typeof fadein == "undefined") { 65 var fadein = {}; 66} 67if (typeof fadeout == "undefined") { 68 var fadeout = {}; 69} 70if (typeof isInit == "undefined") { 71 var isInit = {}; 72} 73 74const googleChartList = ['area_google','bar_google','column_google','line_google','pie_google','donut_google','gauge_google','geo_google','org_google']; 75 76const manualChartList = ['mixed','brush','gantt_google']; 77 78function graphinNumberWithCommas(x, separator, decimal = -1) { 79 if (isNaN(x)) { 80 return x; 81 } 82 var parts = x.toString().split("."); 83 let val = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, separator); 84 85 if (parts[1]) { 86 if (decimal === -1) { 87 val = val + '.' + parts[1] 88 }else if (decimal !== 0) { 89 val = val + '.' + parts[1].substring(0, decimal) 90 } 91 } 92 93 return val; 94} 95 96function resetGraphinaVars() { 97 if (typeof graphina_localize.graphinaAllGraphs == "undefined") { 98 graphina_localize.graphinaAllGraphs = {}; 99 } 100 if (typeof graphina_localize.graphinaAllGraphsOptions == "undefined") { 101 graphina_localize.graphinaAllGraphsOptions = {}; 102 } 103 if (typeof graphina_localize.graphinaBlockCharts == "undefined") { 104 graphina_localize.graphinaBlockCharts = {}; 105 } 106} 107resetGraphinaVars(); 108 109/*************** 110 * Jquery Base 111 * @param ele 112 * @param add 113 * @param remove 114 */ 115 116function addRemoveClass(ele, add = '', remove = '') { 117 if (remove !== '' && ele.hasClass(add)) ele.removeClass(remove); 118 if (add !== '' && !ele.hasClass(add)) ele.addClass(add); 119} 120 121/************ 122 * 123 * @param timestamp 124 * @param isTime 125 * @param isDate 126 * @returns {string} 127 */ 128 129function dateFormat(timestamp, isTime = false, isDate = false) { 130 let dateSeparator = '-'; 131 let date = new Date(timestamp); 132 let hours = date.getHours(); 133 let minutes = "0" + date.getMinutes(); 134 let day = date.getDate(); 135 let month = date.getMonth() + 1; 136 let year = date.getFullYear() 137 return (isDate ? (day + dateSeparator + month + dateSeparator + year) : '') + (isDate && isTime ? ' ' : '') + (isTime ? (hours + ':' + minutes.substr(-2)) : ''); 138} 139 140/******************** 141 * 142 * @param date1 143 * @param date2 144 * @returns {string} 145 */ 146function timeDifference(date1, date2) { 147 let difference = new Date(date2).getTime() - new Date(date1).getTime(); 148 149 let daysDifference = Math.floor(difference / 1000 / 60 / 60 / 24); 150 difference -= daysDifference * 1000 * 60 * 60 * 24 151 152 let hoursDifference = Math.floor(difference / 1000 / 60 / 60); 153 difference -= hoursDifference * 1000 * 60 * 60 154 155 let minutesDifference = Math.floor(difference / 1000 / 60); 156 157 return getPostfix(daysDifference, 'day', 'days') + 158 (daysDifference > 0 && hoursDifference > 0 ? ' ' : '') + 159 getPostfix(hoursDifference, 'hour', 'hours') + 160 (hoursDifference > 0 && minutesDifference > 0 ? ' ' : '') + 161 getPostfix(minutesDifference, 'minute', 'minutes'); 162} 163 164/********************* 165 * 166 * @param value 167 * @param postfix1 168 * @param postfix2 169 * @returns {string} 170 */ 171function getPostfix(value, postfix1, postfix2) { 172 let result = '' 173 switch (true) { 174 case value === 0: 175 break; 176 case value === 1: 177 result += value + ' ' + postfix1; 178 break; 179 case value > 1: 180 result += value + ' ' + postfix2; 181 break; 182 } 183 return result; 184} 185 186function isInViewport(el) { 187 if (graphina_localize.is_view_port_disable != undefined && graphina_localize.is_view_port_disable == 'on') { 188 return true; 189 } 190 const rect = el.getBoundingClientRect(); 191 return ( 192 ( 193 (rect.top - ((window.innerHeight || document.documentElement.clientHeight) / 2.1)) >= 0 && 194 (rect.bottom - ((window.innerHeight || document.documentElement.clientHeight) / 1.9)) <= (window.innerHeight || document.documentElement.clientHeight) 195 ) || 196 ( 197 rect.top >= 0 && 198 rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) 199 ) 200 ); 201} 202 203function initNowGraphina(myElement, chart, id) { 204 resetGraphinaVars(); 205 if (id in graphina_localize.graphinaAllGraphs) { 206 graphina_localize.graphinaAllGraphs[id].destroy(); 207 delete graphina_localize.graphinaAllGraphs[id]; 208 delete graphina_localize.graphinaBlockCharts[id]; 209 } 210 graphina_localize.graphinaAllGraphsOptions[id] = chart; 211 isInit[id] = false; 212 getChart(graphina_localize.graphinaAllGraphsOptions[id].ele, id); 213} 214 215function getChart(myElement, id) { 216 if (typeof ApexCharts == 'function' && myElement !== null && 217 (id in isInit) && isInit[id] === false) { 218 if ((graphina_localize.is_view_port_disable != undefined && graphina_localize.is_view_port_disable == 'on') || (graphina_localize.graphinaAllGraphsOptions[id].type !== undefined && graphina_localize.graphinaAllGraphsOptions[id].type === 'brush')) { 219 initGraphinaCharts(id); 220 } else { 221 const observer = new IntersectionObserver(enteries => {
222 enteries.forEach(entry => { 223 if (entry.isIntersecting) { 224 if (isInit[id] === false) { 225 initGraphinaCharts(id); 226 } 227 } 228 }) 229 }) 230 observer.observe(myElement); 231 } 232 } 233} 234 235function initGraphinaCharts(id, type = 'area') { 236 if (Object.keys(graphina_localize.graphinaBlockCharts).includes(id)) { 237 if(!googleChartList.includes(type)){ 238 if (isInit[id] === true) { 239 graphina_localize.graphinaAllGraphs[id].destroy(); 240 } 241 } 242 graphina_localize.graphinaAllGraphsOptions[id].ele.innerHTML = ''; 243 graphina_localize.graphinaAllGraphsOptions[id].ele.innerHTML = graphina_localize.graphinaBlockCharts[id]; 244 } else { 245 if (isInit[id] === true || graphina_localize.graphinaAllGraphs[id]) { 246 if(googleChartList.includes(type)){ 247 graphina_localize.graphinaAllGraphs[id].draw(graphina_localize.graphinaAllGraphsOptions[id].series,graphina_localize.graphinaAllGraphsOptions[id].options); 248 }else{ 249 let option = graphina_localize.graphinaAllGraphsOptions[id].options; 250 let series = option.series; 251 // delete option.series; 252 if (type === 'mixed') { 253 graphina_localize.graphinaAllGraphs[id].updateOptions({ 254 series: option.series, 255 labels: graphina_localize.graphinaAllGraphsOptions[id].options.category 256 }); 257 }else if (type === 'counter'){ 258 if(option.series.length){ 259 graphina_localize.graphinaAllGraphs[id].updateSeries(option.series,true); 260 } 261 } 262 else { 263 if( typeof graphina_localize.graphinaAllGraphs[id].updateOptions !== "undefined" 264 && typeof graphina_localize.graphinaAllGraphs[id].updateSeries !== "undefined" ){ 265 graphina_localize.graphinaAllGraphs[id].updateOptions(option, true, graphina_localize.graphinaAllGraphsOptions[id].animation); 266 graphina_localize.graphinaAllGraphs[id].updateSeries(series, graphina_localize.graphinaAllGraphsOptions[id].animation); 267 graphina_localize.graphinaAllGraphs[id].destroy(); 268 instantInitGraphinaCharts(id,type); 269 }else{ 270 graphina_localize.graphinaAllGraphs[id].destroy(); 271 instantInitGraphinaCharts(id,type); 272 } 273 } 274 } 275 } else { 276 if(googleChartList.includes(type)){ 277 graphinaGoogleChartRender(id,type) 278 }else{ 279 instantInitGraphinaCharts(id,type); 280 } 281 } 282 } 283} 284 285function updateGoogleChartType(defaultType, select, id) { 286 if (graphina_localize.graphinaAllGraphsOptions[id]) { 287 let selectType = select.value; 288 graphina_localize.graphinaAllGraphsOptions[id].renderType = selectType; 289 graphinaGoogleChartRender(id, selectType) 290 } 291} 292 293function updateChartType(defaultvalue, select, id) { 294 var x = select.value; 295 if (defaultvalue == x) { 296 graphina_localize.graphinaAllGraphs[id].updateOptions(graphina_localize.graphinaAllGraphsOptions[id].options); 297 return; 298 } 299 if (x == 'area') { 300 graphina_localize.graphinaAllGraphs[id].updateOptions({ 301 chart: { 302 type: x 303 }, 304 fill: { 305 opacity: 0.4, 306 pattern: { 307 width: 6, 308 height: 6, 309 strokeWidth: 2 310 } 311 }, 312 dataLabels: { 313 offsetY: 0, 314 offsetX: 0 315 }, 316 stroke: { 317 show: true, 318 colors: graphina_localize.graphinaAllGraphsOptions[id].options.colors, 319 width: 2 320 } 321 }) 322 } else if (x == 'line') { 323 graphina_localize.graphinaAllGraphs[id].updateOptions({ 324 chart: { 325 type: x 326 }, 327 dataLabels: { 328 offsetY: 0, 329 offsetX: 0 330 }, 331 stroke: { 332 show: true, 333 colors: graphina_localize.graphinaAllGraphsOptions[id].options.colors, 334 width: 5 335 } 336 }) 337 } else if (x == 'bar') { 338 graphina_localize.graphinaAllGraphs[id].updateOptions({ 339 chart: { 340 type: x 341 }, 342 fill: { 343 opacity: 0.9, 344 }, 345 stroke: { 346 show: true, 347 width: 2, 348 // colors: ['transparent'] 349 } 350 }) 351 } else if (x == 'pie' || x == 'donut') { 352 graphina_localize.graphinaAllGraphs[id].updateOptions({ 353 chart: { 354 type: x 355 }, 356 fill: { 357 opacity: 1, 358 }, 359 }) 360 } else if (x == 'polarArea') { 361 graphina_localize.graphinaAllGraphs[id].updateOptions({ 362 chart: { 363 type: x 364 }, 365 fill: { 366 opacity: 0.4, 367 }, 368 stroke: { 369 show: true, 370 width: 2, 371 colors: graphina_localize.graphinaAllGraphsOptions[id].options.colors, 372 }, 373 }) 374 } else if (x == 'scatter') { 375 graphina_localize.graphinaAllGraphs[id].updateOptions({ 376 chart: { 377 type: x 378 }, 379 stroke: { 380 show: true, 381 width: 2, 382 colors: ['transparent'] 383 }, 384 fill: { 385 opacity: 1 386 }, 387 markers: { 388 size: 10, 389 } 390 }) 391 392 } 393} 394 395function chartDatalabelsFormat(option, showlabel, showValue, numberformat, prefix, postfix, valueInStringShow, valueInString,forminatorPercentage=false,forminatorDecimal=0) { 396 397 if (showlabel == 'yes' && showValue == 'yes') { 398 return option.dataLabels.formatter = function(val, opt) { 399 let seriesValue = opt.w.config.series[opt.seriesIndex]; 400 if (numberformat == "yes") { 401 seriesValue = graphinNumberWithCommas(seriesValue,graphina_localize.thous
401and_seperator) 402 } else { 403 seriesValue = valueInStringShow == 'no' ? seriesValue : graphinaAbbrNum(seriesValue, valueInString); 404 } 405 if(forminatorPercentage){ 406 let totals = opt.w.globals.seriesTotals.reduce((a, b) => { 407 return a + b; 408 }, 0) 409 if(postfix.trim() === ''){ 410 postfix = '%'; 411 } 412 seriesValue = parseFloat(seriesValue/totals * 100).toFixed(parseInt(forminatorDecimal)) +postfix 413 postfix = ''; 414 } 415 return prefix + opt.w.config.labels[opt.seriesIndex] + '-' + seriesValue + postfix 416 } 417 } else if (showlabel == 'yes') { 418 return option.dataLabels.formatter = function(val, opt) { 419 if(forminatorPercentage){ 420 let totals = opt.w.globals.seriesTotals.reduce((a, b) => { 421 return a + b; 422 }, 0) 423 if(postfix.trim() === ''){
424 postfix = '%'; 425 } 426 val = parseFloat(val/totals * 100).toFixed(parseInt(forminatorDecimal)) +postfix 427 postfix = ''; 428 } 429 return prefix + opt.w.config.labels[opt.seriesIndex] + '-' + parseFloat(val).toFixed(1) + postfix 430 } 431 } else if (showValue == 'yes') { 432 return option.dataLabels.formatter = function(val, opt) { 433 let seriesValue = opt.w.config.series[opt.seriesIndex]; 434 if (numberformat == "yes") { 435 seriesValue = graphinNumberWithCommas(seriesValue,graphina_localize.thousand_seperator) 436 } else { 437 seriesValue = valueInStringShow == 'no' ? seriesValue : graphinaAbbrNum(seriesValue, valueInString); 438 } 439 if(forminatorPercentage){ 440 let totals = opt.w.globals.seriesTotals.reduce((a, b) => { 441 return a + b; 442 }, 0) 443 if(postfix.trim() === ''){ 444 postfix = '%'; 445 } 446 seriesValue = parseFloat(seriesValue/totals * 100).toFixed(parseInt(forminatorDecimal)) +postfix 447 postfix = ''; 448 } 449 return prefix + seriesValue + postfix 450 } 451 } else { 452 return option.dataLabels.formatter = function(val, opt) { 453 if(forminatorPercentage){ 454 let totals = opt.w.globals.seriesTotals.reduce((a, b) => { 455 return a + b; 456 }, 0) 457 if(postfix.trim() === ''){
458 postfix = '%'; 459 } 460 val = parseFloat(val/totals * 100).toFixed(parseInt(forminatorDecimal)) +postfix 461 postfix = ''; 462 } 463 return prefix + parseFloat(val).toFixed(1) + postfix; 464 } 465 } 466 467} 468 469function axisTitle(option, type, title, style, xaxisYoffset = 0) { 470 return option[type]['title'] = { 471 text: title, 472 offsetX: 0, 473 offsetY: type === 'xaxis' ? xaxisYoffset : 0, 474 style, 475 } 476} 477 478 479function instantInitGraphinaCharts(id,type) { 480 graphina_localize.graphinaAllGraphs[id] = new ApexCharts(graphina_localize.graphinaAllGraphsOptions[id].ele, graphina_localize.graphinaAllGraphsOptions[id].options); 481 graphina_localize.graphinaAllGraphs[id].render(); 482 isInit[id] = true; 483 // window.wp.hooks.doAction('graphina_apex_chart_render', type,id); 484} 485 486/** 487 * Simple object check. 488 * @param item 489 * @returns {boolean} 490 */ 491function isObject(item) { 492 return (item && typeof item === 'object' && !Array.isArray(item)); 493} 494 495/** 496 * Deep merge two objects. 497 * @param target 498 * @param sources 499 */ 500function mergeDeep(target, ...sources) { 501 if (!sources.length) return target; 502 const source = sources.shift(); 503 504 if (isObject(target) && isObject(source)) { 505 for (const key in source) { 506 if (source.hasOwnProperty(key)) { 507 if (isObject(source[key])) { 508 if (!target[key]) Object.assign(target, { 509 [key]: {} 510 }); 511 mergeDeep(target[key], source[key]); 512 } else { 513 Object.assign(target, { 514 [key]: source[key] 515 }); 516 } 517 } 518 } 519 } 520 521 return mergeDeep(target, ...sources); 522} 523 524function chunk(array, size) { 525 if (!array) return []; 526 const firstChunk = array.slice(0, size); 527 if (!firstChunk.length) { 528 return array; 529 } 530 return [firstChunk].concat(chunk(array.slice(size, array.length), size)); 531} 532 533function graphinaAbbrNum(number, decPlaces) { 534 decPlaces = parseInt(decPlaces); 535 if (number === undefined || number == null) { 536 return number; 537 } 538 var negativesign = ''; 539 if (number < 0) { 540 negativesign = '-'; 541 number = Math.abs(number) 542 } 543 if(number < 1000){ 544 return negativesign + parseFloat(number).toFixed(decPlaces) 545 } 546 // 2 decimal places => 100, 3 => 1000, etc 547 decPlaces = Math.pow(10, decPlaces); 548 549 // Enumerate number abbreviations 550 var abbrev = ["k", "m", "b", "t"]; 551 552 // Go through the array backwards, so we do the largest first 553 for (var i = abbrev.length - 1; i >= 0; i--) { 554 555 // Convert array index to "1000", "1000000", etc 556 var size = Math.pow(10, (i + 1) * 3); 557 558 // If the number is bigger or equal do the abbreviation 559 if (size <= number) { 560 // Here, we multiply by decPlaces, round, and then divide by decPlaces. 561 // This gives us nice rounding to a particular decimal place. 562 number = Math.round(number * decPlaces / size) / decPlaces; 563 564 // Handle special case where we round up to the next abbreviation 565 if ((number == 1000) && (i < abbrev.length - 1)) { 566 number = 1; 567 i++; 568 } 569 570 // Add the letter for the abbreviation 571 number += abbrev[i]; 572 573 // We are done... stop 574 break; 575 } 576 } 577 578 return negativesign + number; 579} 580 581function getDataForChartsAjax(request_fields, type, id, selected_field = '',button_filter_value='') { 582 583 if (jQuery('body').hasClass("elementor-editor-active")) { 584 let element_x = parent.document.querySelector('[data-setting="iq_' + type + '_chart_sql_builder_x_columns"]'); 585 let element_y = parent.document.querySelector('[data-setting="iq_' + type + '_chart_sql_builder_y_columns"]'); 586 if (element_x !== null && element_y !== null) { 587 element_x.innerHTML = ''; 588 element_y.innerHTML = ''; 589 } 590 591 let element_a = parent.document.querySelector('[data-setting="iq_' + type + '_chart_csv_x_columns"]'); 592 let element_b = parent.document.querySelector('[data-setting="iq_' + type + '_chart_csv_y_columns"]'); 593 if (element_a !== null && element_b !== null) { 594 element_a.innerHTML = ''; 595 element_b.innerHTML = ''; 596 } 597 }; 598 599 if (request_fields&& request_fields['iq_' + type + '_chart_filter_enable'] != undefined && request_fields['iq_' + type + '_chart_filter_enable'] == 'yes') { 600 selected_field = graphinaGetSelectOptionValue(id); 601 } 602 if(!jQuery('body').hasClass("elementor-editor-active")){ 603 request_fields = []; 604 605 } 606 let pageID= document.querySelector("#"+type+'_chart'+id)?.closest('[data-elementor-id]')?.dataset?.elementorId 607 608 jQuery.ajax({ 609 url: graphina_localize.ajaxurl, 610 type: "post", 611 dataType: "json", 612 data: { 613 action: "get_graphina_chart_settings", 614 nonce:graphina_localize.nonce, 615 selected_field: selected_field, 616 button_filter_value:button_filter_value, 617 chart_type: type, 618 chart_id: id, 619 page_id : pageID, 620 fields: request_fields 621 }, 622 success: function(response) { 623 624 if(document.getElementsByClassName(type + '-' + id).length !== 0){ 625 let counterOptions = { 626 easing: 'linear', 627 duration: myCounter[id].speed, 628 delimiter: myCounter[id].separator, 629 toValue: response.extra.counter_end,
630 rounding: myCounter[id].rounding 631 } 632 jQuery(myCounter[id].ele).numerator(counterOptions); 633 } 634 635 if (document.getElementsByClassName(type + '-chart-' + id).length === 0) { 636 return 0; 637 } 638 if (response.status === true && response.category_count > 0) { 639 jQuery(document).find('.' + type + '-chart-' + id + '-loader').addClass('d-none'); 640 jQuery(document).find('.' + type + '-chart-' + id).removeClass('d-none'); 641 jQuery(document).find('.' + type + '-chart-' + id).parents('.chart-box').removeClass('d-none') 642 } else { 643 if(!(['heatmap', 'candle', 'bubble', 'timeline'].includes(type))){ 644 jQuery(document).find('.' + type + '-chart-' + id).parents('.chart-box').addClass('d-none') 645 jQuery(document).find('.' + type + '-chart-' + id).addClass('d-none') 646 jQuery(document).find('.' + type + '-chart-' + id + '-loader').find('img').addClass('d-none'); 647 jQuery(document).find('.' + type + '-chart-' + id + '-loader').removeClass('d-none'); 648 jQuery(document).find('.' + type + '-chart-' + id + '-loader').find('p').removeClass('d-none'); 649 if(!jQuery('body').hasClass("elementor-editor-active")){ 650 return; 651 } 652 } 653 } 654 if (response.status === true) { 655 if (response.fail === true) { 656 graphina_localize.graphinaBlockCharts[response.chart_id] = response.fail_message; 657 initGraphinaCharts(response.chart_id); 658 } else { 659 if(googleChartList.includes(type)){ 660 if(!['pie_google','donut_google','gauge_google','geo_google','org_google'].includes(type)){ 661 let column = graphina_localize.graphinaAllGraphsOptions[id].series.getNumberOfColumns() 662 if(column > 0 ){ 663 graphina_localize.graphinaAllGraphsOptions[id].series.removeColumns(0,column) 664 } 665 graphina_localize.graphinaAllGraphsOptions[id].series.addColumn('string',response.googlechartData.title); 666 response.googlechartData.title_array.map((value,key)=>{ 667 graphina_localize.graphinaAllGraphsOptions[id].series.addColumn('number',value); 668 if(response.googlechartData.annotation_show === 'yes'){ 669 graphina_localize.graphinaAllGraphsOptions[id].series.addColumn( { role: 'annotation' }); 670 } 671 }) 672 } 673 let row = graphina_localize.graphinaAllGraphsOptions[id].series.getNumberOfRows(); 674 if(row > 0){ 675 graphina_localize.graphinaAllGraphsOptions[id].series.removeRows(0,row) 676 } 677 graphina_localize.graphinaAllGraphsOptions[id].series.addRows(response.googlechartData.data) 678 if(['pie_google','donut_google','gauge_google'].includes(type)){ 679 let formatJson = type === 'gauge_google' ? { 680 prefix: request_fields['iq_' + type + '_google_chart_value_prefix'] , 681 suffix: request_fields['iq_' + type + '_google_chart_value_postfix'], 682 fractionDigits: request_fields['iq_' + type + '_google_chart_value_decimal'] 683 } : { 684 prefix: request_fields['iq_' + type + '_chart_label_prefix'] , 685 suffix: request_fields['iq_' + type + '_chart_label_postfix'], 686 fractionDigits: 0 687 } 688 if(graphina_localize.graphinaAllGraphsOptions[id].series.getNumberOfRows() > 0){ 689 var formatter = new google.visualization.NumberFormat(formatJson); 690 formatter.format( graphina_localize.graphinaAllGraphsOptions[id].series, 1); 691 } 692 } 693 initGraphinaCharts(response.chart_id, type); 694 }else{ 695 if (response.instant_init === true) { 696 graphina_localize.graphinaAllGraphsOptions[response.chart_id].animation = false; 697 instantInitGraphinaCharts(response.chart_id,type); 698 } 699 graphina_localize.graphinaAllGraphsOptions[response.chart_id].options = mergeDeep(graphina_localize.graphinaAllGraphsOptions[response.chart_id].options, response.chart_option); 700 if (isInit[response.chart_id] === true) { 701 initGraphinaCharts(response.chart_id, type); 702 } 703 } 704 } 705 706 if (request_fields['iq_' + type + '_chart_dynamic_data_option'] !== undefined) { 707 if (request_fields['iq_' + type + '_chart_dynamic_data_option'] === "sql-builder") { 708 if (jQuery('body').hasClass("elementor-editor-active")) { 709 setFieldsFromSQLStateMent(request_fields, response, type); 710 }; 711 } 712 } 713 714 if (request_fields['iq_' + type + '_chart_dynamic_data_option'] !== undefined) { 715 if (request_fields['iq_' + type + '_chart_dynamic_data_option'] === "csv" || request_fields['iq_' + type + '_chart_dynamic_data_option'] === "remote-csv" || request_fields['iq_' + type + '_chart_dynamic_data_option'] === "google-sheet") { 716 if (jQuery('body').hasClass("elementor-editor-active")) { 717 setFieldsForCSV(request_fields, response, type); 718 }; 719 } 720 } 721 722 if(request_fields['iq_' + type + '_chart_data_option'] !== undefined 723 && request_fields['iq_' + type + '_chart_data_option'] === 'forminator'){ 724 if(jQuery('body').hasClass("elementor-editor-active")) { 725 setFieldsFromForminator(request_fields, response, type); 726 }; 727 } 728 } 729 }, 730 error: function() { 731 console.log('fail'); 732 } 733 }); 734 735} 736 737function setFieldsFromSQLStateMent(request_fields, response, type) { 738 739 740 let manualSql = manualChartList; 741 if (manualSql.includes(type)) { 742 if (response.sql_fail !== undefined && response.sql_fail !== '') { 743 let char_element = document.querySelector('[id="' + type + '-chart"]'); 744 if (char_element !== null) { 745 char_element.innerHTML = ''; 746 char_element.innerHTML = "<div class='text-center' style='color:red'> No data found, Please check your sql statement. </div>"; 747 } 748 return; 749 } 750 } else { 751 if (response.extra !== undefined && response.extra.sql_fail !== undefined && response.extra.sql_fail !== '') { 752 let char_element = document.querySelector('[id="' + type + '-chart"]'); 753 if (char_element !== null) { 754 char_element.innerHTML = ''; 755 char_element.innerHTML = "<div class='text-center' style='color:red'> No data found, Please check your sql statement. </div>"; 756 } 757 return; 758 } 759 } 760 761 // graphina pro sql-builder select sql result column 762 let db_columns = manualSql.includes(type) ? response.db_column : response.extra.db_column; 763 764 765 let element_x = parent.document.querySelector('[data-setting="iq_' + type + '_chart_sql_builder_x_columns"]'); 766 let element_y = parent.document.querySelector('[data-setting="iq_' + type + '_chart_sql_builder_y_columns"]'); 767 768 if (element_x == null || element_y == null) { 769 return; 770 } 771 772 x_option_tag = ''; 773 y_option_tag = ''; 774 775 if (db_columns !== undefined && db_columns.length !== undefined && db_columns.length > 0) { 776 db_columns.forEach(function(currentValue, index, arr) { 777 x_axis_selected_field = ''; 778 y_axis_selected_field = ''; 779 if (request_fields['iq_' + type + '_chart_sql_builder_x_columns'].includes(currentValue)) { 780 x_axis_selected_field = 'selected'; 781 } 782 if (request_fields['iq_' + type + '_chart_sql_builder_y_columns'].includes(currentValue)) { 783 y_axis_selected_field = 'selected'; 784 } 785 x_option_tag += '<option value="' + currentValue.toLowerCase() + '" ' + x_axis_selected_field + ' > ' + currentValue + '</option>'; 786 y_option_tag += '<option value="' + currentValue.toLowerCase() + '" ' + y_axis_selected_field + ' > ' + currentValue + '</option>'; 787 }); 788 } 789 790 element_x.innerHTML = x_option_tag; 791 792 element_y.innerHTML = y_option_tag; 793 794} 795 796function setFieldsForCSV(request_fields, response, type) { 797 798 799 800 let manualCsv = manualChartList; 801
802 let csv_columns = manualCsv.includes(type) ? response.column : response.extra.column; 803 804 if (csv_columns !== undefined && csv_columns.length !== undefined && csv_columns.length > 0) { 805 806 let element_x = parent.document.querySelector('[data-setting="iq_' + type + '_chart_csv_x_columns"]'); 807 808 let element_y = parent.document.querySelector('[data-setting="iq_' + type + '_chart_csv_y_columns"]'); 809 810 if (element_x == null || element_y == null) { 811 812 return; 813 } 814 815 x_option_tag = ''; 816 y_option_tag = ''; 817 818 csv_columns.forEach(function(currentValue, index, arr) { 819 820 821 x_axis_selected_field = ''; 822 y_axis_selected_field = ''; 823 824 if (request_fields['iq_' + type + '_chart_csv_x_columns'].includes(currentValue)) { 825 x_axis_selected_field = 'selected'; 826 } 827 if (request_fields['iq_' + type + '_chart_csv_y_columns'].includes(currentValue)) { 828 y_axis_selected_field = 'selected'; 829 } 830 831 x_option_tag += '<option value="' + currentValue.toLowerCase() + '" ' + x_axis_selected_field + ' > ' + currentValue + '</option>'; 832 833 y_option_tag += '<option value="' + currentValue.toLowerCase() + '" ' + y_axis_selected_field + ' > ' + currentValue + '</option>'; 834 835 836 }); 837 element_x.innerHTML = x_option_tag; 838 element_y.innerHTML = y_option_tag; 839 } 840 841} 842 843function graphinasetCookie(cname, cvalue, exdays) { 844 var d = new Date(); 845 d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); 846 var expires = "expires=" + d.toUTCString(); 847 document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; 848} 849 850function graphinaRestrictedPasswordAjax(form, e) { 851 e.preventDefault() 852 jQuery.ajax({ 853 url: graphina_localize.ajaxurl, 854 type: "post", 855 data: jQuery(form).serialize(), 856 success: function(response) { 857 if (response.status === true) { 858 graphinasetCookie(response.chart, true, 1); 859 location.reload(); 860 } else { 861 jQuery(form).find('.graphina-error').css('display', 'flex'); 862 } 863 } 864 }); 865 866 867 868} 869 870function graphinaChartFilter(type, selectedValue, id) { 871 jQuery(document).find('.' + type + '-chart-' + id + '-loader').removeClass('d-none'); 872 jQuery(document).find('.' + type + '-chart-' + id + '-loader').find('img').removeClass('d-none'); 873 jQuery(document).find('.' + type + '-chart-' + id + '-loader').find('p').addClass('d-none'); 874 jQuery(document).find('.' + type + '-chart-' + id).addClass('d-none'); 875 jQuery(document).find('.' + type + '-chart-' + id).parents('.chart-box').addClass('d-none') 876 getDataForChartsAjax(graphina_localize.graphinaAllGraphsOptions[id].setting_date, type, id, graphinaGetSelectOptionValue(id)); 877 878} 879 880function graphinaGetSelectOptionValue(id) { 881 let option = [] 882 let allSelect = document.querySelectorAll('.graphina_filter_select' + id); 883 for (let i = 0; i < allSelect.length; i++) { 884 if(allSelect[i].type !== undefined && ['datetime-local','date'].includes(allSelect[i].type)){ 885 if (allSelect[i].value !== undefined) { 886 let formatsign = "-"; 887 let date = new Date(allSelect[i].value) 888 if (date !== undefined) { 889 let formatDate = ''; 890 if (allSelect[i].type === 'date') { 891 formatDate = date.getFullYear() + formatsign + ("00" + (date.getMonth() + 1)).slice(-2) + formatsign + 892 ("00" + date.getDate()).slice(-2); 893 } else { 894 formatDate = date.getFullYear() + formatsign + ("00" + (date.getMonth() + 1)).slice(-2) + formatsign + 895 ("00" + date.getDate()).slice(-2) + " " + 896 ("00" + date.getHours()).slice(-2) + ":" + 897 ("00" + date.getMinutes()).slice(-2) + ":" + 898 ("00" + date.getSeconds()).slice(-2); 899 } 900 option.push(formatDate) 901 } 902 } 903 }else{ 904 if (allSelect[i].value !== undefined || allSelect[i].value !== null) { 905 if (allSelect[i].value !== 'default') { 906 option.push(allSelect[i].value) 907 } else { 908 option.push('') 909 } 910 } 911 } 912 } 913 return option; 914} 915 916function graphinaGoogleChartInit(ele, options, id, type) { 917 resetGraphinaVars(); 918 if (id in graphina_localize.graphinaAllGraphs) { 919 graphina_localize.graphinaAllGraphs[id].clearChart(); 920 delete graphina_localize.graphinaAllGraphs[id]; 921 delete graphina_localize.graphinaBlockCharts[id]; 922 } 923 isInit[id] = false; 924 graphina_localize.graphinaAllGraphsOptions[id] = options; 925 if (ele !== null) { 926 if (graphina_localize.is_view_port_disable != undefined && graphina_localize.is_view_port_disable == 'on') { 927 graphinaGoogleChartRender(id, type); 928 } else { 929 const observer = new IntersectionObserver(enteries => {
930 enteries.forEach(entry => { 931 if (entry.isIntersecting) { 932 if (isInit[id] === false) { 933 graphinaGoogleChartRender(id, type); 934 } 935 } 936 }) 937 }) 938 observer.observe(ele); 939 } 940 } 941} 942 943function graphinaGoogleChartRender(id, type) { 944 if (isInit[id] === true || graphina_localize.graphinaAllGraphs[id]) { 945 graphina_localize.graphinaAllGraphs[id] = new google.visualization[graphina_localize.graphinaAllGraphsOptions[id].renderType](graphina_localize.graphinaAllGraphsOptions[id].ele); 946 graphina_localize.graphinaAllGraphs[id].draw(graphina_localize.graphinaAllGraphsOptions[id].series, graphina_localize.graphinaAllGraphsOptions[id].options); 947 } else { 948 graphina_localize.graphinaAllGraphs[id] = new google.visualization[graphina_localize.graphinaAllGraphsOptions[id].renderType](graphina_localize.graphinaAllGraphsOptions[id].ele); 949 graphina_localize.graphinaAllGraphs[id].draw(graphina_localize.graphinaAllGraphsOptions[id].series, graphina_localize.graphinaAllGraphsOptions[id].options); 950 } 951 isInit[id] = true; 952 // window.wp.hooks.doAction('graphina_google_chart_render', type,id); 953 954 if (type === 'gauge_google' && typeof graphina_localize.graphinaAllGraphs[id] != "undefined") { 955 Array.prototype.forEach.call(graphina_localize.graphinaAllGraphsOptions[id].ele.getElementsByTagName('circle'), function(circle) { 956 if (circle.getAttribute('fill') === '#4684ee') { 957 circle.setAttribute('fill', typeof graphina_localize.graphinaAllGraphsOptions[id].ballColor !== "undefined" ? graphina_localize.graphinaAllGraphsOptions[id].ballColor : '#4684ee'); 958 } 959 if (circle.getAttribute('fill') === '#f7f7f7') { 960 circle.setAttribute('fill', typeof graphina_localize.graphinaAllGraphsOptions[id].innerCircleColor !== "undefined" ? graphina_localize.graphinaAllGraphsOptions[id].innerCircleColor : '#f7f7f7'); 961 } 962 if (circle.getAttribute('fill') === '#cccccc') { 963 circle.setAttribute('fill', typeof graphina_localize.graphinaAllGraphsOptions[id].outerCircleColor !== "undefined" ? graphina_localize.graphinaAllGraphsOptions[id].outerCircleColor : '#cccccc'); 964 } 965 }); 966 Array.prototype.forEach.call(graphina_localize.graphinaAllGraphsOptions[id].ele.getElementsByTagName('path'), function(path) { 967 if (path.getAttribute('stroke') === '#c63310') { 968 path.setAttribute('stroke', typeof graphina_localize.graphinaAllGraphsOptions[id].needleColor !== "undefined" ? graphina_localize.graphinaAllGraphsOptions[id].needleColor : '#c63310'); 969 path.setAttribute('fill', typeof graphina_localize.graphinaAllGraphsOptions[id].needleColor !== "undefined" ? graphina_localize.graphinaAllGraphsOptions[id].needleColor : '#c63310'); 970 } 971 }); 972 } 973} 974 975function setFieldsFromForminator(request_fields, response, type) { 976 if(request_fields['iq_' + type + '_section_chart_forminator_aggregate'] !== undefined && request_fields['iq_' + type + '_section_chart_forminator_aggregate'] === 'yes'){ 977 let element_aggregate = parent.document.querySelector('[data-setting="iq_' + type + '_section_chart_forminator_aggregate_column"]'); 978 if (element_aggregate == null) { 979 return; 980 } 981 let manualForminator = manualChartList; 982 let forminator_columns = manualForminator.includes(type) ? response.forminator_columns: response.extra.forminator_columns ; 983 let forminator_columns_labels = manualForminator.includes(type) ? response.forminator_columns_labels: response.extra.forminator_columns_labels ; 984 aggregate_column_option_tag = '' ; 985 if(forminator_columns !== undefined && forminator_columns.length !== undefined && forminator_columns.length > 0) { 986 let labels = ''; 987 forminator_columns.forEach(function(currentValue, index, arr) { 988 labels = ''; 989 labels = forminator_columns_labels !== undefined && forminator_columns_labels.length > 0 && forminator_columns_labels[index] !== undefined ? forminator_columns_labels[index] : currentValue; 990 aggregate_column_selected_field = '' ; 991 if(request_fields['iq_' + type + '_section_chart_forminator_aggregate_column'].includes(currentValue)) { 992 aggregate_column_selected_field = 'selected' ; 993 } 994 aggregate_column_option_tag += '<option value="' + currentValue + '" ' + aggregate_column_selected_field + ' > ' + labels + '</option>' ; 995 996 }); 997 } 998 element_aggregate.innerHTML = aggregate_column_option_tag ; 999 }else{ 1000 let element_x = parent.document.querySelector('[data-setting="iq_' + type + '_section_chart_forminator_x_axis_columns"]'); 1001 let element_y = parent.document.querySelector('[data-setting="iq_' + type + '_section_chart_forminator_y_axis_columns"]'); 1002 if (element_x == null || element_y == null) { 1003 return; 1004 } 1005 let manualForminator = manualChartList; 1006 // graphina pro sql-builder select sql result column 1007 let forminator_columns = manualForminator.includes(type) ? response.forminator_columns: response.extra.forminator_columns ; 1008 let forminator_columns_labels = manualForminator.includes(type) ? response.forminator_columns_labels: response.extra.forminator_columns_labels ; 1009 x_option_tag = '' ; 1010 y_option_tag = '' ; 1011 if(forminator_columns !== undefined && forminator_columns.length !== undefined && forminator_columns.length > 0) { 1012 let labels = ''; 1013 forminator_columns.forEach(function(currentValue, index, arr) { 1014 labels = ''; 1015 labels = forminator_columns_labels !== undefined && forminator_columns_labels.length > 0 && forminator_columns_labels[index] !== undefined ? forminator_columns_labels[index] : currentValue; 1016 x_axis_selected_field = '' ; 1017 y_axis_selected_field = '' ; 1018 if(request_fields['iq_' + type + '_section_chart_forminator_x_axis_columns'].includes(currentValue)) { 1019 x_axis_selected_field = 'selected' ; 1020 } 1021 if(request_fields['iq_' + type + '_section_chart_forminator_y_axis_columns'].includes(currentValue)) { 1022 y_axis_selected_field = 'selected' ; 1023 } 1024 x_option_tag += '<option value="' + currentValue + '" ' + x_axis_selected_field + ' > ' + labels + '</option>' ; 1025 y_option_tag += '<option value="' + currentValue + '" ' + y_axis_selected_field + ' > ' + labels + '</option>' ; 1026 }); 1027 } 1028 element_x.innerHTML = x_option_tag ; 1029 element_y.innerHTML = y_option_tag ; 1030 } 1031} 1032 1033function graphina_google_chart_ajax_reload(callAjax,type,chart_id,ajaxReload,ajaxIntervalTime){ 1034 let setting = graphina_localize.graphinaAllGraphsOptions[chart_id].setting_date; 1035 if(typeof getDataForChartsAjax !== "undefined" && callAjax === "1") { 1036 getDataForChartsAjax(setting, type, chart_id); 1037 if(ajaxReload === 'true'){ 1038 window['ajaxIntervalGraphina_' + chart_id] = setInterval(function () { 1039 getDataForChartsAjax(setting, type, chart_id); 1040 }, parseInt(ajaxIntervalTime * 1000)); 1041 } 1042 } 1043}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.