jQuery(document).ready(function($) {

    // -----------------------------------------------------------------------------------------------------------------

    //set global variables
    let dsu_timeout_handler;
    let dauc_hot;
    let dauc_data = [];
    let dauc_max_rows;
    let dauc_max_columns;

    // -----------------------------------------------------------------------------------------------------------------

    //document -> ready - EVENT LISTENER
    disable_ctrl_z();
    initialize_select2();
    display_data_structure(1);
    set_type_based_titles();
    remove_border_last_cell_chart();
    initialize_spectrum();
    initialize_handsontable();
    responsive_sidebar_container();

    //#save -> click - EVENT LISTENER
    $('#save').click(function(){

        const validation_result = save_chart(true);

        //show error message
        if(validation_result !== true){
            $('#chart-error p').html($('#chart-error-partial-message').val() + ' <strong>' + validation_result.join(', ') + '</strong>');
            $('#chart-error').show();
        }

    });

    //#rows, #columns -> change - EVENT LISTENER
    $('#rows, #columns').change(function(){

        update_rows_and_columns();

    });

    //#update-data-structure -> click - EVENT LISTENER
    $('#update-data-structure').click(function(event){

        update_data_structure(false);

    });

    //#update-data-structure-and-globalize -> click - EVENT LISTENER
    $('#update-data-structure-and-globalize').click(function(event){

        update_data_structure(true);

    });

    //#type -> change - EVENT LISTENER
    $('#type').change(function(){

        remove_border_last_cell_chart()
        show_chart_specific_data_structure();
        set_type_based_titles();
        remove_border_last_cell_data_structure();

    });

    //.group-trigger -> click - EVENT LISTENER
    $('.group-trigger').click(function(){

        //open and close the various sections of the chart area
        const target = $(this).attr('data-trigger-target');
        $('.' + target).toggle(0);
        $(this).find('.expand-icon').toggleClass('arrow-down');

        remove_border_last_cell_chart();

    });

    //#load-model -> change - EVENT LISTENER
    $('#load-model').change(function(){

        //get data
        let chart_id = null;
        if( $('#temporary-chart-id').length ){
            chart_id = $('#temporary-chart-id').val();
        }else{
            chart_id = $('#update-id').val();
        }
        const model_id = parseInt($(this).val(), 10);

        //This is used to terminate the procedure in case "None" is selected
        if(model_id == 0){return;}

        //retrieve the chart data with an ajax request

        //prepare ajax request
        const data = {
            "action": "load_model",
            "security": window.DAEXTDAUC_PARAMETERS.nonce,
            "chart_id": chart_id,
            "model_id": model_id
        };

        //send ajax request
        $.post(window.DAEXTDAUC_PARAMETERS.ajax_url, data, function(answer_json) {

            const answer_obj = JSON.parse(answer_json);
            const chart = JSON.parse(answer_obj.chart);
            const data = JSON.parse(answer_obj.data);

            //fill the fields of the chart (except the data field) by using the 'chart' object -------------------------

            $('#name').val(chart.name);
            $('#description').val(chart.description);
            update_select2_field('#type', chart.type);
            $('#rows').val(chart.rows);
            $('#columns').val(chart.columns);

            //Common Chart Configuration
            update_select2_field('#canvas-transparent-background', chart.canvas_transparent_background);
            $('#canvas-backgroundColor').val(chart.canvas_backgroundColor);
            $('#margin-top').val(chart.margin_top);
            $('#margin-bottom').val(chart.margin_bottom);
            $('#width').val(chart.width);
            $('#height').val(chart.height);
            update_select2_field('#responsive', chart.responsive);
            $('#responsiveAnimationDuration').val(chart.responsiveAnimationDuration);
            update_select2_field('#maintainAspectRatio', chart.maintainAspectRatio);

            /*
             * Since fixed_height has been added in version 1.09 (and the old charts have the value of fixed_height
             * empty) set 0 if fixed_height is empty
             */
            if(chart.fixed_height.length == 0){
                $('#fixed-height').val(0);
            }else{
                $('#fixed-height').val(parseInt(chart.fixed_height, 10));
            }

            update_select2_field('#is-model', 0);

            //Title Configuration
            update_select2_field('#title-display', chart.title_display);
            update_select2_field('#title-position', chart.title_position);
            update_select2_field('#title-fullWidth', chart.title_fullWidth);
            $('#title-fontSize').val(chart.title_fontSize);
            $('#title-fontFamily').val(chart.title_fontFamily);
            $('#title-fontColor').val(chart.title_fontColor);
            update_select2_field('#title-fontStyle', chart.title_fontStyle);
            $('#title-padding').val(chart.title_padding);

            //Legend Configuration
            update_select2_field('#legend-display', chart.legend_display);
            update_select2_field('#legend-position', chart.legend_position);
            update_select2_field('#legend-fullWidth', chart.legend_fullWidth);
            update_select2_field('#legend-toggle-dataset', chart.legend_toggle_dataset);
            $('#legend-labels-boxWidth').val(chart.legend_labels_boxWidth);
            $('#legend-labels-fontSize').val(chart.legend_labels_fontSize);
            update_select2_field('#legend-labels-fontStyle', chart.legend_labels_fontStyle);
            $('#legend-labels-fontColor').val(chart.legend_labels_fontColor);
            $('#legend-labels-fontFamily').val(chart.legend_labels_fontFamily);
            $('#legend-labels-padding').val(chart.legend_labels_padding);

            //Tooltip Configuration
            update_select2_field('#tooltips-enabled', chart.tooltips_enabled);
            update_select2_field('#tooltips-mode', chart.tooltips_mode);
            $('#tooltips-backgroundColor').val(chart.tooltips_backgroundColor);
            $('#tooltips-titleFontFamily').val(chart.tooltips_titleFontFamily);
            $('#tooltips-titleFontSize').val(chart.tooltips_titleFontSize);
            update_select2_field('#tooltips-titleFontStyle', chart.tooltips_titleFontStyle);
            $('#tooltips-titleFontStyle').val(chart.tooltips_titleFontStyle);
            $('#tooltips-titleFontColor').val(chart.tooltips_titleFontColor);
            $('#tooltips-titleMarginBottom').val(chart.tooltips_titleMarginBottom);
            $('#tooltips-bodyFontFamily').val(chart.tooltips_bodyFontFamily);
            $('#tooltips-bodyFontSize').val(chart.tooltips_bodyFontSize);
            update_select2_field('#tooltips-bodyFontStyle', chart.tooltips_bodyFontStyle);
            $('#tooltips-bodyFontColor').val(chart.tooltips_bodyFontColor);
            $('#tooltips-footerFontFamily').val(chart.tooltips_footerFontFamily);
            $('#tooltips-footerFontSize').val(chart.tooltips_footerFontSize);
            update_select2_field('#tooltips-footerFontStyle', chart.tooltips_footerFontStyle);
            $('#tooltips-footerFontColor').val(chart.tooltips_footerFontColor);
            $('#tooltips-footerMarginTop').val(chart.tooltips_footerMarginTop);
            $('#tooltips-xPadding').val(chart.tooltips_xPadding);
            $('#tooltips-yPadding').val(chart.tooltips_yPadding);
            $('#tooltips-caretSize').val(chart.tooltips_caretSize);
            $('#tooltips-cornerRadius').val(chart.tooltips_cornerRadius);
            $('#tooltips-multiKeyBackground').val(chart.tooltips_multiKeyBackground);
            $('#hover-animationDuration').val(chart.hover_animationDuration);
            $('#tooltips-beforeTitle').val(chart.tooltips_beforeTitle);
            $('#tooltips-afterTitle').val(chart.tooltips_afterTitle);
            $('#tooltips-beforeBody').val(chart.tooltips_beforeBody);
            $('#tooltips-afterBody').val(chart.tooltips_afterBody);
            $('#tooltips-beforeLabel').val(chart.tooltips_beforeLabel);
            $('#tooltips-afterLabel').val(chart.tooltips_afterLabel);
            $('#tooltips-beforeValue').val(chart.tooltips_beforeValue);
            $('#tooltips-afterValue').val(chart.tooltips_afterValue);
            $('#tooltips-beforeFooter').val(chart.tooltips_beforeFooter);
            $('#tooltips-footer').val(chart.tooltips_footer);
            $('#tooltips-afterFooter').val(chart.tooltips_afterFooter);

            //Animation Configuration
            $('#animation_duration').val(chart.animation_duration);
            update_select2_field('#animation-easing', chart.animation_easing);
            update_select2_field('#animation-instantiation-event', chart.animation_instantiation_event);

            //Misc Configuration
            update_select2_field('#elements-rectangle-borderSkipped', chart.elements_rectangle_borderSkipped);
            update_select2_field('#half-pie-doughnut', chart.half_pie_doughnut);
            update_select2_field('#indexAxis', chart.indexAxis);
            $('#thousands-separator').val(chart.thousands_separator);
            $('#decimal-separator').val(chart.decimal_separator);

            //Scales Common Configuration X
            update_select2_field('#scales-xAxes-type', chart.scales_xAxes_type);
            update_select2_field('#scales-xAxes-display', chart.scales_xAxes_display);
            update_select2_field('#scales-xAxes-position', chart.scales_xAxes_position);
            update_select2_field('#scales-xAxes-stacked', chart.scales_xAxes_stacked);

            //Scales Grid Line Configuration X
            update_select2_field('#scales-xAxes-gridLines-display', chart.scales_xAxes_gridLines_display);
            $('#scales-xAxes-gridLines-color').val(chart.scales_xAxes_gridLines_color);
            $('#scales-xAxes-gridLines-lineWidth').val(chart.scales_xAxes_gridLines_lineWidth);
            update_select2_field('#scales-xAxes-gridLines-drawBorder', chart.scales_xAxes_gridLines_drawBorder);
            update_select2_field('#scales-xAxes-gridLines-drawOnChartArea', chart.scales_xAxes_gridLines_drawOnChartArea);
            update_select2_field('#scales-xAxes-gridLines-drawTicks', chart.scales_xAxes_gridLines_drawTicks);
            $('#scales-xAxes-gridLines-tickMarkLength').val(chart.scales_xAxes_gridLines_tickMarkLength);
            $('#scales-xAxes-gridLines-zeroLineWidth').val(chart.scales_xAxes_gridLines_zeroLineWidth);
            $('#scales-xAxes-gridLines-zeroLineColor').val(chart.scales_xAxes_gridLines_zeroLineColor);
            update_select2_field('#scales-xAxes-gridLines-offsetGridLines', chart.scales_xAxes_gridLines_offsetGridLines);

            //Scales Title Configuration X
            update_select2_field('#scales-xAxes-scaleLabel-display', chart.scales_xAxes_scaleLabel_display);
            $('#scales-xAxes-scaleLabel-labelString').val(chart.scales_xAxes_scaleLabel_labelString);
            $('#scales-xAxes-scaleLabel-fontColor').val(chart.scales_xAxes_scaleLabel_fontColor);
            $('#scales-xAxes-scaleLabel-fontFamily').val(chart.scales_xAxes_scaleLabel_fontFamily);
            $('#scales-xAxes-scaleLabel-fontSize').val(chart.scales_xAxes_scaleLabel_fontSize);
            update_select2_field('#scales-xAxes-scaleLabel-fontStyle', chart.scales_xAxes_scaleLabel_fontStyle);

            //Scales Tick Configuration X
            update_select2_field('#scales-xAxes-ticks-autoskip', chart.scales_xAxes_ticks_autoskip);
            update_select2_field('#scales-xAxes-ticks-display', chart.scales_xAxes_ticks_display);
            $('#scales-xAxes-ticks-fontColor').val(chart.scales_xAxes_ticks_fontColor);
            $('#scales-xAxes-ticks-fontFamily').val(chart.scales_xAxes_ticks_fontFamily);
            $('#scales-xAxes-ticks-fontSize').val(chart.scales_xAxes_ticks_fontSize);
            update_select2_field('#scales-xAxes-ticks-fontStyle', chart.scales_xAxes_ticks_fontStyle);
            $('#scales-xAxes-ticks-labelOffset').val(chart.scales_xAxes_ticks_labelOffset);
            $('#scales-xAxes-ticks-maxRotation').val(chart.scales_xAxes_ticks_maxRotation);
            $('#scales-xAxes-ticks-minRotation').val(chart.scales_xAxes_ticks_minRotation);
            update_select2_field('#scales-xAxes-ticks-reverse', chart.scales_xAxes_ticks_reverse);
            $('#scales-xAxes-ticks-prefix').val(chart.scales_xAxes_ticks_prefix);
            $('#scales-xAxes-ticks-suffix').val(chart.scales_xAxes_ticks_suffix);
            $('#scales-xAxes-ticks-round').val(chart.scales_xAxes_ticks_round);

            //Scale Configuration Options X
            $('#scales-xAxes-ticks-min').val(chart.scales_xAxes_ticks_min);
            $('#scales-xAxes-ticks-max').val(chart.scales_xAxes_ticks_max);
            update_select2_field('#scales-xAxes-ticks-beginAtZero', chart.scales_xAxes_ticks_beginAtZero);
            $('#scales-xAxes-ticks-maxTicksLimit').val(chart.scales_xAxes_ticks_maxTicksLimit);
            $('#scales-xAxes-ticks-stepSize').val(chart.scales_xAxes_ticks_stepSize);
            $('#scales-xAxes-ticks-suggestedMax').val(chart.scales_xAxes_ticks_suggestedMax);
            $('#scales-xAxes-ticks-suggestedMin').val(chart.scales_xAxes_ticks_suggestedMin);
            $('#scales-xAxes-categoryPercentage').val(chart.scales_xAxes_categoryPercentage);
            $('#scales-xAxes-barPercentage').val(chart.scales_xAxes_barPercentage);

            //Time Scale Configuration Options X
            $('#scales-xAxes-time-format').val(chart.scales_xAxes_time_format);
            $('#scales-xAxes-time-tooltipFormat').val(chart.scales_xAxes_time_tooltipFormat);
            $('#scales-xAxes-time-unit-format').val(chart.scales_xAxes_time_unit_format);
            update_select2_field('#scales-xAxes-time-unit', chart.scales_xAxes_time_unit);
            $('#scales-xAxes-time-unitStepSize').val(chart.scales_xAxes_time_unitStepSize);
            $('#scales-xAxes-time-max').val(chart.scales_xAxes_time_max);
            $('#scales-xAxes-time-min').val(chart.scales_xAxes_time_min);

            //Scales Common Configuration Y
            update_select2_field('#scales-yAxes-type', chart.scales_yAxes_type);
            update_select2_field('#scales-yAxes-display', chart.scales_yAxes_display);
            update_select2_field('#scales-yAxes-position', chart.scales_yAxes_position);
            update_select2_field('#scales-yAxes-stacked', chart.scales_yAxes_stacked);

            //Scales Grid Line Configuration Y
            update_select2_field('#scales-yAxes-gridLines-display', chart.scales_yAxes_gridLines_display);
            $('#scales-yAxes-gridLines-color').val(chart.scales_yAxes_gridLines_color);
            $('#scales-yAxes-gridLines-lineWidth').val(chart.scales_yAxes_gridLines_lineWidth);
            update_select2_field('#scales-yAxes-gridLines-drawBorder', chart.scales_yAxes_gridLines_drawBorder);
            update_select2_field('#scales-yAxes-gridLines-drawOnChartArea', chart.scales_yAxes_gridLines_drawOnChartArea);
            update_select2_field('#scales-yAxes-gridLines-drawTicks', chart.scales_yAxes_gridLines_drawTicks);
            $('#scales-yAxes-gridLines-tickMarkLength').val(chart.scales_yAxes_gridLines_tickMarkLength);
            $('#scales-yAxes-gridLines-zeroLineWidth').val(chart.scales_yAxes_gridLines_zeroLineWidth);
            $('#scales-yAxes-gridLines-zeroLineColor').val(chart.scales_yAxes_gridLines_zeroLineColor);
            update_select2_field('#scales-yAxes-gridLines-offsetGridLines', chart.scales_yAxes_gridLines_offsetGridLines);
            $('#scales-yAxes-gridLines-offsetGridLines').val(chart.scales_yAxes_gridLines_offsetGridLines);

            //Scales Title Configuration Y
            update_select2_field('#scales-yAxes-scaleLabel-display', chart.scales_yAxes_scaleLabel_display);
            $('#scales-yAxes-scaleLabel-labelString').val(chart.scales_yAxes_scaleLabel_labelString);
            $('#scales-yAxes-scaleLabel-fontColor').val(chart.scales_yAxes_scaleLabel_fontColor);
            $('#scales-yAxes-scaleLabel-fontFamily').val(chart.scales_yAxes_scaleLabel_fontFamily);
            $('#scales-yAxes-scaleLabel-fontSize').val(chart.scales_yAxes_scaleLabel_fontSize);
            update_select2_field('#scales-yAxes-scaleLabel-fontStyle', chart.scales_yAxes_scaleLabel_fontStyle);

            //Scales Tick Configuration Y
            update_select2_field('#scales-yAxes-ticks-autoskip', chart.scales_yAxes_ticks_autoskip);
            update_select2_field('#scales-yAxes-ticks-display', chart.scales_yAxes_ticks_display);
            $('#scales-yAxes-ticks-fontColor').val(chart.scales_yAxes_ticks_fontColor);
            $('#scales-yAxes-ticks-fontFamily').val(chart.scales_yAxes_ticks_fontFamily);
            $('#scales-yAxes-ticks-fontSize').val(chart.scales_yAxes_ticks_fontSize);
            update_select2_field('#scales-yAxes-ticks-fontStyle', chart.scales_yAxes_ticks_fontStyle);
            $('#scales-yAxes-ticks-maxRotation').val(chart.scales_yAxes_ticks_maxRotation);
            $('#scales-yAxes-ticks-minRotation').val(chart.scales_yAxes_ticks_minRotation);
            update_select2_field('#scales-yAxes-ticks-mirror', chart.scales_yAxes_ticks_mirror);
            $('#scales-yAxes-ticks-padding').val(chart.scales_yAxes_ticks_padding);
            update_select2_field('#scales-yAxes-ticks-reverse', chart.scales_yAxes_ticks_reverse);
            $('#scales-yAxes-ticks-prefix').val(chart.scales_yAxes_ticks_prefix);
            $('#scales-yAxes-ticks-suffix').val(chart.scales_yAxes_ticks_suffix);
            $('#scales-yAxes-ticks-round').val(chart.scales_yAxes_ticks_round);

            //Scale Configuration Options Y
            $('#scales-yAxes-ticks-min').val(chart.scales_yAxes_ticks_min);
            $('#scales-yAxes-ticks-max').val(chart.scales_yAxes_ticks_max);
            update_select2_field('#scales-yAxes-ticks-beginAtZero', chart.scales_yAxes_ticks_beginAtZero);
            $('#scales-yAxes-ticks-maxTicksLimit').val(chart.scales_yAxes_ticks_maxTicksLimit);
            $('#scales-yAxes-ticks-stepSize').val(chart.scales_yAxes_ticks_stepSize);
            $('#scales-yAxes-ticks-suggestedMax').val(chart.scales_yAxes_ticks_suggestedMax);
            $('#scales-yAxes-ticks-suggestedMin').val(chart.scales_yAxes_ticks_suggestedMin);
            $('#scales-yAxes-categoryPercentage').val(chart.scales_yAxes_categoryPercentage);
            $('#scales-yAxes-barPercentage').val(chart.scales_yAxes_barPercentage);

            //Scales Common Configuration Y2
            update_select2_field('#scales-y2Axes-type', chart.scales_y2Axes_type);
            update_select2_field('#scales-y2Axes-display', chart.scales_y2Axes_display);
            update_select2_field('#scales-y2Axes-position', chart.scales_y2Axes_position);

            //Scales Grid Line Configuration Y2
            update_select2_field('#scales-y2Axes-gridLines-display', chart.scales_y2Axes_gridLines_display);
            $('#scales-y2Axes-gridLines-color').val(chart.scales_y2Axes_gridLines_color);
            $('#scales-y2Axes-gridLines-lineWidth').val(chart.scales_y2Axes_gridLines_lineWidth);
            update_select2_field('#scales-y2Axes-gridLines-drawBorder', chart.scales_y2Axes_gridLines_drawBorder);
            update_select2_field('#scales-y2Axes-gridLines-drawOnChartArea', chart.scales_y2Axes_gridLines_drawOnChartArea);
            update_select2_field('#scales-y2Axes-gridLines-drawTicks', chart.scales_y2Axes_gridLines_drawTicks);
            $('#scales-y2Axes-gridLines-tickMarkLength').val(chart.scales_y2Axes_gridLines_tickMarkLength);
            $('#scales-y2Axes-gridLines-zeroLineWidth').val(chart.scales_y2Axes_gridLines_zeroLineWidth);
            $('#scales-y2Axes-gridLines-zeroLineColor').val(chart.scales_y2Axes_gridLines_zeroLineColor);
            update_select2_field('#scales-y2Axes-gridLines-offsetGridLines', chart.scales_y2Axes_gridLines_offsetGridLines);

            //Scales Title Configuration Y2
            update_select2_field('#scales-y2Axes-scaleLabel-display', chart.scales_y2Axes_scaleLabel_display);
            $('#scales-y2Axes-scaleLabel-labelString').val(chart.scales_y2Axes_scaleLabel_labelString);
            $('#scales-y2Axes-scaleLabel-fontColor').val(chart.scales_y2Axes_scaleLabel_fontColor);
            $('#scales-y2Axes-scaleLabel-fontFamily').val(chart.scales_y2Axes_scaleLabel_fontFamily);
            $('#scales-y2Axes-scaleLabel-fontSize').val(chart.scales_y2Axes_scaleLabel_fontSize);
            update_select2_field('#scales-y2Axes-scaleLabel-fontStyle', chart.scales_y2Axes_scaleLabel_fontStyle);

            //Scales Tick Configuration Y2
            update_select2_field('#scales-y2Axes-ticks-autoskip', chart.scales_y2Axes_ticks_autoskip);
            update_select2_field('#scales-y2Axes-ticks-display', chart.scales_y2Axes_ticks_display);
            $('#scales-y2Axes-ticks-fontColor').val(chart.scales_y2Axes_ticks_fontColor);
            $('#scales-y2Axes-ticks-fontFamily').val(chart.scales_y2Axes_ticks_fontFamily);
            $('#scales-y2Axes-ticks-fontSize').val(chart.scales_y2Axes_ticks_fontSize);
            update_select2_field('#scales-y2Axes-ticks-fontStyle', chart.scales_y2Axes_ticks_fontStyle);
            $('#scales-y2Axes-ticks-maxRotation').val(chart.scales_y2Axes_ticks_maxRotation);
            $('#scales-y2Axes-ticks-minRotation').val(chart.scales_y2Axes_ticks_minRotation);
            update_select2_field('#scales-y2Axes-ticks-mirror', chart.scales_y2Axes_ticks_mirror);
            $('#scales-y2Axes-ticks-padding').val(chart.scales_y2Axes_ticks_padding);
            update_select2_field('#scales-y2Axes-ticks-reverse', chart.scales_y2Axes_ticks_reverse);
            $('#scales-y2Axes-ticks-prefix').val(chart.scales_y2Axes_ticks_prefix);
            $('#scales-y2Axes-ticks-suffix').val(chart.scales_y2Axes_ticks_suffix);
            $('#scales-y2Axes-ticks-round').val(chart.scales_y2Axes_ticks_round);

            //Scale Configuration Options Y2
            $('#scales-y2Axes-ticks-min').val(chart.scales_y2Axes_ticks_min);
            $('#scales-y2Axes-ticks-max').val(chart.scales_y2Axes_ticks_max);
            update_select2_field('#scales-y2Axes-ticks-beginAtZero', chart.scales_y2Axes_ticks_beginAtZero);
            $('#scales-y2Axes-ticks-maxTicksLimit').val(chart.scales_y2Axes_ticks_maxTicksLimit);
            $('#scales-y2Axes-ticks-stepSize').val(chart.scales_y2Axes_ticks_stepSize);
            $('#scales-y2Axes-ticks-suggestedMax').val(chart.scales_y2Axes_ticks_suggestedMax);
            $('#scales-y2Axes-ticks-suggestedMin').val(chart.scales_y2Axes_ticks_suggestedMin);

            /* RL Scale Common Configuration */
            update_select2_field('#scales-rl-display', chart.scales_rl_display);

            /* RL Scale Grid Line Configuration */
            update_select2_field('#scales-rl-gridLines-display', chart.scales_rl_gridLines_display)
            $('#scales-rl-gridLines-color').val(chart.scales_rl_gridLines_color);
            $('#scales-rl-gridLines-lineWidth').val(chart.scales_rl_gridLines_lineWidth);

            /* RL Scale Angle Line Configuration */
            update_select2_field('#scales-rl-angleLines-display', chart.scales_rl_angleLines_display);
            $('#scales-rl-angleLines-color').val(chart.scales_rl_angleLines_color);
            $('#scales-rl-angleLines-lineWidth').val(chart.scales_rl_angleLines_lineWidth);

            /* RL Scale Point Label Configuration */
            $('#scales-rl-pointLabels-fontSize').val(chart.scales_rl_pointLabels_fontSize);
            $('#scales-rl-pointLabels-fontColor').val(chart.scales_rl_pointLabels_fontColor);
            $('#scales-rl-pointLabels-fontFamily').val(chart.scales_rl_pointLabels_fontFamily);
            $('#scales-rl-pointLabels-fontStyle').val(chart.scales_rl_pointLabels_fontStyle);

            /* RL Scale Tick Configuration */
            update_select2_field('#scales-rl-ticks-display', chart.scales_rl_ticks_display);
            update_select2_field('#scales-rl-ticks-autoskip', chart.scales_rl_ticks_autoskip);
            update_select2_field('#scales-rl-ticks-reverse', chart.scales_rl_ticks_reverse);
            $('#scales-rl-ticks-prefix').val(chart.scales_rl_ticks_prefix);
            $('#scales-rl-ticks-suffix').val(chart.scales_rl_ticks_suffix);
            $('#scales-rl-ticks-round').val(chart.scales_rl_ticks_round);
            $('#scales-rl-ticks-fontSize').val(chart.scales_rl_ticks_fontSize);
            $('#scales-rl-ticks-fontColor').val(chart.scales_rl_ticks_fontColor);
            $('#scales-rl-ticks-fontFamily').val(chart.scales_rl_ticks_fontFamily);
            $('#scales-rl-ticks-fontStyle').val(chart.scales_rl_ticks_fontStyle);

            /* RL Scale Configuration Options */
            $('#scales-rl-ticks-min').val(chart.scales_rl_ticks_min);
            $('#scales-rl-ticks-max').val(chart.scales_rl_ticks_max);
            $('#scales-rl-ticks-suggestedMin').val(chart.scales_rl_ticks_suggestedMin);
            $('#scales-rl-ticks-suggestedMax').val(chart.scales_rl_ticks_suggestedMax);
            $('#scales-rl-ticks-stepSize').val(chart.scales_rl_ticks_stepSize);
            $('#scales-rl-ticks-maxTicksLimit').val(chart.scales_rl_ticks_maxTicksLimit);
            update_select2_field('#scales-rl-ticks-beginAtZero', chart.scales_rl_ticks_beginAtZero);
            update_select2_field('#scales-rl-ticks-showLabelBackdrop', chart.scales_rl_ticks_showLabelBackdrop);
            $('#scales-rl-ticks-backdropColor').val(chart.scales_rl_ticks_backdropColor);
            $('#scales-rl-ticks-backdropPaddingX').val(chart.scales_rl_ticks_backdropPaddingX);
            $('#scales-rl-ticks-backdropPaddingY').val(chart.scales_rl_ticks_backdropPaddingY);

            /* Source */
            update_select2_field('#source-type', chart.source_type);
            $('#source-url').val(chart.source_url);
            $('#source-google-sheets-spreadsheet-id').val(chart.source_google_sheets_spreadsheet_id);

            /* Performance */
            $('#transient-expiration').val(chart.transient_expiration);


            /*
             Fill the fields of the data structure associated with the first row with the data in the first object
             (data[0]) available in the 'data' array of objects (each object represents a row)
             */
            const data_obj = data[0];
            $('#data-structure-title').text('Dataset ' + ( parseInt(data_obj.row_index, 10) ));
            $("#data-structure-row-index").val(data_obj.row_index);
            $("#data-structure-label").val(data_obj.label);
            update_select2_field("#data-structure-fill", data_obj.fill);
            $("#data-structure-lineTension").val(data_obj.lineTension);
            $("#data-structure-backgroundColor").val(data_obj.backgroundColor);
            $("#data-structure-borderWidth").val(data_obj.borderWidth);
            $("#data-structure-borderColor").val(data_obj.borderColor);
            update_select2_field("#data-structure-borderCapStyle", data_obj.borderCapStyle);
            $("#data-structure-borderDash").val(data_obj.borderDash);
            $("#data-structure-borderDashOffset").val(data_obj.borderDashOffset);
            update_select2_field("#data-structure-borderJoinStyle", data_obj.borderJoinStyle);
            $("#data-structure-pointBorderColor").val(data_obj.pointBorderColor);
            $("#data-structure-pointBackgroundColor").val(data_obj.pointBackgroundColor);
            $("#data-structure-pointBorderWidth").val(data_obj.pointBorderWidth);
            $("#data-structure-pointRadius").val(data_obj.pointRadius);
            $("#data-structure-pointHoverRadius").val(data_obj.pointHoverRadius);
            $("#data-structure-pointHitRadius").val(data_obj.pointHitRadius);
            $("#data-structure-pointHoverBackgroundColor").val(data_obj.pointHoverBackgroundColor);
            $("#data-structure-pointHoverBorderColor").val(data_obj.pointHoverBorderColor);
            $("#data-structure-pointHoverBorderWidth").val(data_obj.pointHoverBorderWidth);
            $("#data-structure-pointStyle").val(data_obj.pointStyle);
            update_select2_field("#data-structure-showLine", data_obj.showLine);
            update_select2_field("#data-structure-spanGaps", data_obj.spanGaps);
            $("#data-structure-hoverBackgroundColor").val(data_obj.hoverBackgroundColor);
            $("#data-structure-hoverBorderColor").val(data_obj.hoverBorderColor);
            $("#data-structure-hoverBorderWidth").val(data_obj.hoverBorderWidth);
            $("#data-structure-hitRadius").val(data_obj.hitRadius);
            $("#data-structure-hoverRadius").val(data_obj.hoverRadius);
            update_select2_field("#data-structure-plotY2", data_obj.plotY2);
            update_select2_field("#data-structure-hidden", data_obj.hidden);

            show_chart_specific_data_structure();
            remove_border_last_cell_data_structure();

            //set the new maximum number of rows and columns
            dauc_hot.updateSettings({
                maxRows: parseInt(chart.rows, 10) + 1,
                maxCols: chart.columns
            });

            //set the number of rows
            if( dauc_hot.countRows() - 1 < chart.rows ){

                while ( dauc_hot.countRows() - 1 < chart.rows){
                    dauc_hot.alter('insert_row');
                }

            }else if( dauc_hot.countRows() - 1 > chart.rows ){

                while (dauc_hot.countRows() - 1 > chart.rows){
                    dauc_hot.alter('remove_row');
                }

            }

            //set the number of columns
            if( dauc_hot.countCols() < chart.columns ){

                do {
                    dauc_hot.alter('insert_col');
                }
                while (dauc_hot.countCols() < chart.columns);

            }else if( dauc_hot.countCols() > chart.columns ){

                do {
                    dauc_hot.alter('remove_col');
                }
                while (dauc_hot.countCols() > chart.columns);

            }

            //add the labels on the first row of the handsontable table
            const labels = JSON.parse(chart.labels);
            $.each(labels, function( index, value ) {
                dauc_data[0][index] = value;
            });

            //add the data (from the second row to the bottom) to the handsontable table
            $.each(data, function( index, value ) {

                const row_obj = JSON.parse(value.content);
                $.each(row_obj, function( index2, value2 ) {

                    //actual index is used to start from the second row (and skip the first row, used for the labels)
                    const actual_index = parseInt(index, 10) + 1;

                    dauc_data[actual_index][index2] = value2;

                });

            });

            //render the changes on the data made on the data reference
            dauc_hot.render();

        });

    });

    //#save-and-refresh -> click - EVENT LISTENER
    $('#save-and-refresh').click(function(){

        save_and_refresh();

    });

    //tr[data-trigger-target="chart-preview"] -> click - EVENT LISTENER
    $('tr[data-trigger-target="chart-preview"]').click(function(){

        if( $('.chart-preview').css('display') == 'table-row' ){

            save_and_refresh();

        }else{

            $( '#chart-preview-iframe').detach();

        }

    });

    //window -> resize - EVENT LISTENER
    jQuery(window).resize(function(){

        responsive_sidebar_container();

    });

    // -----------------------------------------------------------------------------------------------------------------

    /*
    Update the number of rows and columns on the handsontable and on the "data" db table
     */
    function update_rows_and_columns(){

        //update the number of rows and columns of the table -----------------------------------------------------------

        //get the chart id
        let chart_id = null;
        if( $('#temporary-chart-id').length ){
            chart_id = $('#temporary-chart-id').val();
        }else{
            chart_id = $('#update-id').val();
        }

        //get the rows and columns limit
        const rows_and_columns_limit = parseInt($('#rows-and-columns-limit').attr('data-rows-and-columns-limit'), 10);

        //change the number of rows
        const current_number_of_rows = dauc_hot.countRows() - 1;
        let new_number_of_rows = parseInt($('#rows').val(), 10);
        if( isNaN(new_number_of_rows) || new_number_of_rows < 1 ){
            new_number_of_rows = 1;
            $('#rows').val(1);
        }

        //Do not allow to enter more rows than the ones defined with in the rows_and_columns_limit
        if( new_number_of_rows > rows_and_columns_limit ){
            new_number_of_rows = rows_and_columns_limit;
            $('#rows').val(rows_and_columns_limit);
        }

        //set the new maximum number of rows
        dauc_hot.updateSettings({
            maxRows: (new_number_of_rows + 1)
        });

        if(new_number_of_rows > current_number_of_rows){

            const cells_to_add = [];
            const row_difference = new_number_of_rows - current_number_of_rows;
            const count_rows_result = dauc_hot.countRows();
            const count_cols_result = dauc_hot.countCols();

            for(i=1;i<=row_difference;i++){

                //initialize with 0 all the cells of the new row
                for(t=1;t<=count_cols_result;t++){
                    cells_to_add.push([count_rows_result+i-1,(t-1), '0']);
                }

            }

            //create the new rows
            dauc_hot.alter('insert_row', (current_number_of_rows + 1), row_difference);

            //use the setDataAtCell() method one single time with a two dimensional array to avoid performance issues
            dauc_hot.setDataAtCell(cells_to_add);

        }else if(new_number_of_rows < current_number_of_rows){

            const row_difference = current_number_of_rows - new_number_of_rows;

            dauc_hot.alter('remove_row', null, row_difference);

        }

        //create or remove the new rows in the 'data' db table with an asynchronous ajax request -----------------------
        if(new_number_of_rows != current_number_of_rows){

            const data = {
                "action": "add_remove_rows",
                "security": window.DAEXTDAUC_PARAMETERS.nonce,
                "chart_id": chart_id,
                "current_number_of_rows": current_number_of_rows,
                "new_number_of_rows": new_number_of_rows,
                "current_number_of_columns": dauc_hot.countCols(),
            };

            //set ajax in synchronous mode
            jQuery.ajaxSetup({async:false});

            //send ajax request
            $.post(window.DAEXTDAUC_PARAMETERS.ajax_url, data, function(data_json) {});

            //set ajax in asynchronous mode
            jQuery.ajaxSetup({async:true});

        }

        //change the number of columns ---------------------------------------------------------------------------------
        const current_number_of_columns = dauc_hot.countCols();
        let new_number_of_columns = parseInt($('#columns').val(), 10);
        if( isNaN(new_number_of_columns) || new_number_of_columns < 1 ){
            new_number_of_columns = 1;
            $('#columns').val(1);
        }

        //Do not allow to enter more columns than the ones defined with in the rows_and_columns_limit
        if( new_number_of_columns > rows_and_columns_limit ){
            new_number_of_columns = rows_and_columns_limit;
            $('#columns').val(rows_and_columns_limit);
        }

        //set the new maximum number of columns
        dauc_hot.updateSettings({
            maxCols: new_number_of_columns
        });

        if(new_number_of_columns > current_number_of_columns){

            //add the new columns
            const cells_to_add = [];
            const column_difference = new_number_of_columns-current_number_of_columns;
            const count_rows_result = dauc_hot.countRows();
            const count_cols_result = dauc_hot.countCols();

            for(i=1;i<=column_difference;i++){

                for(t=1;t<=count_rows_result;t++){

                    if(t==1){
                        //in row 1 add the default label text
                        cells_to_add.push([0, (count_cols_result+i-1), 'Label ' + parseInt(count_cols_result+i, 10)]);
                    }else{
                        //from row 2 initialize with 0 all the cells of the new column
                        cells_to_add.push([(t-1), (count_cols_result+i-1), '0']);
                    }

                }

            }

            //create the new columns
            dauc_hot.alter('insert_col', current_number_of_columns, column_difference);

            //use the setDataAtCell() method one single time with a two dimensional array to avoid performance issues
            dauc_hot.setDataAtCell(cells_to_add);

        }else if(new_number_of_columns < current_number_of_columns){

            const column_difference = current_number_of_columns-new_number_of_columns;
            dauc_hot.alter('remove_col', null, column_difference);

        }

        //create or remove the new columns in the 'data' db table with an asynchronous ajax request --------------------
        if(new_number_of_columns != current_number_of_columns){

            const data = {
                "action": "add_remove_columns",
                "security": window.DAEXTDAUC_PARAMETERS.nonce,
                "chart_id": chart_id,
                "new_number_of_columns": new_number_of_columns
            };

            //set ajax in synchronous mode
            jQuery.ajaxSetup({async:false});

            //send ajax request
            $.post(window.DAEXTDAUC_PARAMETERS.ajax_url, data, function(data_json) {

            });

            //set ajax in asynchronous mode
            jQuery.ajaxSetup({async:true});

        }

    }

    /*
    Fill the fields in the dataset section
     */
    function display_data_structure(row){

        let chart_id = null;
        if( $('#temporary-chart-id').length ){
            chart_id = $('#temporary-chart-id').val();
        }else{
            chart_id = $('#update-id').val();
        }

        //prepare ajax request
        const data = {
            "action": "retrieve_row_data",
            "security": window.DAEXTDAUC_PARAMETERS.nonce,
            "chart_id": chart_id,
            "row": row
        };

        //send ajax request
        $.post(window.DAEXTDAUC_PARAMETERS.ajax_url, data, function(data_json) {

            const data_obj = JSON.parse(data_json);

            $('#data-structure-title').text('Dataset ' + parseInt(data_obj.row_index, 10) );
            $("#data-structure-row-index").val(data_obj.row_index);
            $("#data-structure-label").val(data_obj.label);
            update_select2_field("#data-structure-fill", data_obj.fill);
            $("#data-structure-lineTension").val(data_obj.lineTension);
            $("#data-structure-backgroundColor").val(data_obj.backgroundColor);
            $("#data-structure-borderWidth").val(data_obj.borderWidth);
            $("#data-structure-borderColor").val(data_obj.borderColor);
            update_select2_field("#data-structure-borderCapStyle", data_obj.borderCapStyle);
            $("#data-structure-borderDash").val(data_obj.borderDash);
            $("#data-structure-borderDashOffset").val(data_obj.borderDashOffset);
            update_select2_field("#data-structure-borderJoinStyle", data_obj.borderJoinStyle);
            $("#data-structure-pointBorderColor").val(data_obj.pointBorderColor);
            $("#data-structure-pointBackgroundColor").val(data_obj.pointBackgroundColor);
            $("#data-structure-pointBorderWidth").val(data_obj.pointBorderWidth);
            $("#data-structure-pointRadius").val(data_obj.pointRadius);
            $("#data-structure-pointHoverRadius").val(data_obj.pointHoverRadius);
            $("#data-structure-pointHitRadius").val(data_obj.pointHitRadius);
            $("#data-structure-pointHoverBackgroundColor").val(data_obj.pointHoverBackgroundColor);
            $("#data-structure-pointHoverBorderColor").val(data_obj.pointHoverBorderColor);
            $("#data-structure-pointHoverBorderWidth").val(data_obj.pointHoverBorderWidth);
            $("#data-structure-pointStyle").val(data_obj.pointStyle);
            update_select2_field("#data-structure-showLine", data_obj.showLine);
            update_select2_field("#data-structure-spanGaps", data_obj.spanGaps);
            $("#data-structure-hoverBackgroundColor").val(data_obj.hoverBackgroundColor);
            $("#data-structure-hoverBorderColor").val(data_obj.hoverBorderColor);
            $("#data-structure-hoverBorderWidth").val(data_obj.hoverBorderWidth);
            $("#data-structure-hitRadius").val(data_obj.hitRadius);
            $("#data-structure-hoverRadius").val(data_obj.hoverRadius);
            update_select2_field("#data-structure-plotY2", data_obj.plotY2);
            update_select2_field("#data-structure-hidden", data_obj.hidden);

            show_chart_specific_data_structure();
            remove_border_last_cell_data_structure();
            $('#data-structure').show();

        });

    }

    /*
    Update the data structure of a dataset in the "data" db table
     */
    function update_data_structure(globalize){

        //get data
        let chart_id = null;
        if( $('#temporary-chart-id').length ){
            chart_id = $('#temporary-chart-id').val();
        }else{
            chart_id = $('#update-id').val();
        }

        let row_index = $("#data-structure-row-index").val();
        let label = $("#data-structure-label").val();
        let fill = $("#data-structure-fill").val();
        let lineTension = $("#data-structure-lineTension").val();
        let backgroundColor = $("#data-structure-backgroundColor").val();
        let borderWidth = $("#data-structure-borderWidth").val();
        let borderColor = $("#data-structure-borderColor").val();
        let borderCapStyle = $("#data-structure-borderCapStyle").val();
        let borderDash = $("#data-structure-borderDash").val();
        let borderDashOffset = $("#data-structure-borderDashOffset").val();
        let borderJoinStyle = $("#data-structure-borderJoinStyle").val();
        let pointBorderColor = $("#data-structure-pointBorderColor").val();
        let pointBackgroundColor = $("#data-structure-pointBackgroundColor").val();
        let pointBorderWidth = $("#data-structure-pointBorderWidth").val();
        let pointRadius = $("#data-structure-pointRadius").val();
        let pointHoverRadius = $("#data-structure-pointHoverRadius").val();
        let pointHitRadius = $("#data-structure-pointHitRadius").val();
        let pointHoverBackgroundColor = $("#data-structure-pointHoverBackgroundColor").val();
        let pointHoverBorderColor = $("#data-structure-pointHoverBorderColor").val();
        let pointHoverBorderWidth = $("#data-structure-pointHoverBorderWidth").val();
        let pointStyle = $("#data-structure-pointStyle").val();
        let showLine = $("#data-structure-showLine").val();
        let spanGaps = $("#data-structure-spanGaps").val();
        let hoverBackgroundColor = $("#data-structure-hoverBackgroundColor").val();
        let hoverBorderColor = $("#data-structure-hoverBorderColor").val();
        let hoverBorderWidth = $("#data-structure-hoverBorderWidth").val();
        let hitRadius = $("#data-structure-hitRadius").val();
        let hoverRadius = $("#data-structure-hoverRadius").val();
        let plotY2 = $("#data-structure-plotY2").val();
        let hidden = $("#data-structure-hidden").val();

        //remove unnecessary spaces in all the data
        if(lineTension.length > 0){lineTension = lineTension.replace(/ /g,'');}
        if(backgroundColor.length > 0){backgroundColor = backgroundColor.replace(/ /g,'');}
        if(borderWidth.length > 0){borderWidth = borderWidth.replace(/ /g,'');}
        if(borderColor.length > 0){borderColor = borderColor.replace(/ /g,'');}
        if(borderDash.length > 0){borderDash = borderDash.replace(/ /g,'');}
        if(borderDashOffset.length > 0){borderDashOffset = borderDashOffset.replace(/ /g,'');}
        if(pointBorderColor.length > 0){pointBorderColor = pointBorderColor.replace(/ /g,'');}
        if(pointBackgroundColor.length > 0){pointBackgroundColor = pointBackgroundColor.replace(/ /g,'');}
        if(pointBorderWidth.length > 0){pointBorderWidth = pointBorderWidth.replace(/ /g,'');}
        if(pointRadius.length > 0){pointRadius = pointRadius.replace(/ /g,'');}
        if(pointHoverRadius.length > 0){pointHoverRadius = pointHoverRadius.replace(/ /g,'');}
        if(pointHitRadius.length > 0){pointHitRadius = pointHitRadius.replace(/ /g,'');}
        if(pointHoverBackgroundColor.length > 0){pointHoverBackgroundColor = pointHoverBackgroundColor.replace(/ /g,'');}
        if(pointHoverBorderColor.length > 0){pointHoverBorderColor = pointHoverBorderColor.replace(/ /g,'');}
        if(pointHoverBorderWidth.length > 0){pointHoverBorderWidth = pointHoverBorderWidth.replace(/ /g,'');}
        if(pointStyle.length > 0){pointStyle = pointStyle.replace(/ /g,'');}
        if(hoverBackgroundColor.length > 0){hoverBackgroundColor = hoverBackgroundColor.replace(/ /g,'');}
        if(hoverBorderColor.length > 0){hoverBorderColor = hoverBorderColor.replace(/ /g,'');}
        if(hoverBorderWidth.length > 0){hoverBorderWidth = hoverBorderWidth.replace(/ /g,'');}
        if(hitRadius.length > 0){hitRadius = hitRadius.replace(/ /g,'');}
        if(hoverRadius.length > 0){hoverRadius = hoverRadius.replace(/ /g,'');}

        //prepare ajax request
        const data = {
            "action": "update_data_structure",
            "security": window.DAEXTDAUC_PARAMETERS.nonce,
            "globalize": globalize,
            "chart_id": chart_id,
            "row_index": row_index,
            "label": label,
            "fill": fill,
            "lineTension": lineTension,
            "backgroundColor": backgroundColor,
            "borderWidth": borderWidth,
            "borderColor": borderColor,
            "borderCapStyle": borderCapStyle,
            "borderDash": borderDash,
            "borderDashOffset": borderDashOffset,
            "borderJoinStyle": borderJoinStyle,
            "pointBorderColor": pointBorderColor,
            "pointBackgroundColor": pointBackgroundColor,
            "pointBorderWidth": pointBorderWidth,
            "pointRadius": pointRadius,
            "pointHoverRadius": pointHoverRadius,
            "pointHitRadius": pointHitRadius,
            "pointHoverBackgroundColor": pointHoverBackgroundColor,
            "pointHoverBorderColor": pointHoverBorderColor,
            "pointHoverBorderWidth": pointHoverBorderWidth,
            "pointStyle": pointStyle,
            "showLine": showLine,
            "spanGaps": spanGaps,
            "hoverBackgroundColor": hoverBackgroundColor,
            "hoverBorderColor": hoverBorderColor,
            "hoverBorderWidth": hoverBorderWidth,
            "hitRadius": hitRadius,
            "hoverRadius": hoverRadius,
            "plotY2": plotY2,
            "hidden": hidden
        };

        if(data_structure_is_valid(data)){

            //send ajax request
            $.post(window.DAEXTDAUC_PARAMETERS.ajax_url, data, function(result) {

                if(result.trim() == 'success'){

                    //show success message
                    $('#data-structure-updated').show();
                    clearTimeout(dsu_timeout_handler);
                    dsu_timeout_handler = setTimeout(function(){ $('#data-structure-updated').hide(); }, 3000);

                }

            });

        }


    }

    /*
    In the data structure section show only the field associated with the current type of chart
     */
    function show_chart_specific_data_structure(){

        const type = $('#type').val();

        $('.data-structure-property').each(function(index, element ) {

            const affected_types = $(this).attr('data-affected-types');
            const affected_types_a = affected_types.split('-');

            if( affected_types.indexOf(type) !== -1 ){
                $(this).show();
            }else{
                $(this).hide();
            }

        });

    }

    /*
    Remove the bottom border on the cells of the last row of the chart section
     */
    function remove_border_last_cell_chart(){
        $('table.daext-form-chart tr > *').css('border-bottom-width', '1px');
        $('table.daext-form-chart tr:visible:last > *').css('border-bottom-width', '0');
    }

    /*
    Remove the bottom border on the cells of the last row of the data structure section
     */
    function remove_border_last_cell_data_structure(){
        $('table.daext-form-data-structure tr > *').css('border-bottom-width', '1px');
        $('table.daext-form-data-structure tr:visible:last > *').css('border-bottom-width', '0');
    }

    /*
    The "title" attribute of the fields in the dataset section is modified based on the current type of chart
     */
    function set_type_based_titles(){

        const type = $('#type').val();

        $('.data-structure-property').each(function(index_1, element_1 ) {

            const container = $(this).find('.help-icon');
            const chart_specific_title = container.attr('data-title-' + type);
            if(chart_specific_title !== undefined){

                const affected_types = $(this).attr('data-affected-types');
                const affected_types_a = affected_types.split('-');

                $.each(affected_types_a, function( index_2, value_2 ) {

                    if(value_2 == type){

                        container.attr('title', chart_specific_title);

                    }

                });

            }

        });

    }

    /*
    Verifies if the data of the data structure are valid
     */
    function data_structure_is_valid(data){

        //init variables
        const fields_with_errors_a = [];

        //define patterns ----------------------------------------------------------------------------------------------

        //match an integer or a float value
        const patt_integer_or_float = /^(\d+\.\d+)|\d+$/;

        //match a hex rgb color, a rgba color or a comma separated list of hex rgb colors and rgba colors
        const patt_color_or_colors = /^((\#([0-9a-fA-F]{3}){1,2})|(rgba\(\d{1,3},\d{1,3},\d{1,3},(\d{1}|\d{1}\.\d{1,2})\)))(,(\#([0-9a-fA-F]{3}){1,2}|rgba\(\d{1,3},\d{1,3},\d{1,3},(\d{1}|\d{1}\.\d{1,2})\)))*$/;

        //match an integer or a comma separated list of integers
        const patt_integer_or_integers = /^(\d+|(\d+(,\d+)*))$/;

        //match an integer
        const patt_integer = /^\d+$/;

        //match a pointStyle or a comma separated list of pointStyles
        const patt_pointStyle_or_pointStyles = /^((circle|triangle|rect|rectRot|cross|crossRot|star|line|dash)|(circle|triangle|rect|rectRot|cross|crossRot|star|line|dash)(,(circle|triangle|rect|rectRot|cross|crossRot|star|line|dash))*)$/;

        if(!patt_integer_or_float.test(data.lineTension)){fields_with_errors_a.push(objectL10n.data_structure_lineTension);}
        if(!patt_color_or_colors.test(data.backgroundColor)){fields_with_errors_a.push(objectL10n.data_structure_backgroundColor);}
        if(!patt_color_or_colors.test(data.borderColor)){fields_with_errors_a.push(objectL10n.data_structure_borderColor);}
        if(!patt_integer_or_integers.test(data.borderWidth)){fields_with_errors_a.push(objectL10n.data_structure_borderWidth);}
        if(!patt_integer_or_integers.test(data.borderDash)){fields_with_errors_a.push(objectL10n.data_structure_borderDash);}
        if(!patt_integer_or_float.test(data.borderDashOffset)){fields_with_errors_a.push(objectL10n.data_structure_borderDashOffset);}
        if(!patt_color_or_colors.test(data.pointBackgroundColor)){fields_with_errors_a.push(objectL10n.data_structure_pointBackgroundColor);}
        if(!patt_color_or_colors.test(data.pointBorderColor)){fields_with_errors_a.push(objectL10n.data_structure_pointBorderColor);}
        if(!patt_integer_or_integers.test(data.pointBorderWidth)){fields_with_errors_a.push(objectL10n.data_structure_pointBorderWidth);}
        if(!patt_integer_or_integers.test(data.pointRadius)){fields_with_errors_a.push(objectL10n.data_structure_pointRadius);}
        if(!patt_integer_or_integers.test(data.pointHitRadius)){fields_with_errors_a.push(objectL10n.data_structure_pointHitRadius);}
        if(!patt_pointStyle_or_pointStyles.test(data.pointStyle)){fields_with_errors_a.push(objectL10n.data_structure_pointStyle);}
        if(!patt_integer_or_integers.test(data.pointHoverRadius)){fields_with_errors_a.push(objectL10n.data_structure_pointHoverRadius);}
        if(!patt_color_or_colors.test(data.pointHoverBackgroundColor)){fields_with_errors_a.push(objectL10n.data_structure_pointHoverBackgroundColor);}
        if(!patt_color_or_colors.test(data.pointHoverBorderColor)){fields_with_errors_a.push(objectL10n.data_structure_pointHoverBorderColor);}
        if(!patt_integer_or_integers.test(data.pointHoverBorderWidth)){fields_with_errors_a.push(objectL10n.data_structure_pointHoverBorderWidth);}
        if(!patt_color_or_colors.test(data.hoverBackgroundColor)){fields_with_errors_a.push(objectL10n.data_structure_hoverBackgroundColor);}
        if(!patt_color_or_colors.test(data.hoverBorderColor)){fields_with_errors_a.push(objectL10n.data_structure_hoverBorderColor);}
        if(!patt_integer_or_integers.test(data.hoverBorderWidth)){fields_with_errors_a.push(objectL10n.data_structure_hoverBorderWidth);}
        if(!patt_integer_or_integers.test(data.hitRadius)){fields_with_errors_a.push(objectL10n.data_structure_hitRadius);}
        if(!patt_integer_or_integers.test(data.hoverRadius)){fields_with_errors_a.push(objectL10n.data_structure_hoverRadius);}

        if( fields_with_errors_a.length > 0){

            //hide the updated message if it's shown
            $('#data-structure-updated').hide();

            //show error message
            $('#data-structure-error p').html($('#data-structure-error-partial-message').val() + ' <strong>' + fields_with_errors_a.join(', ') + '</strong>');
            $('#data-structure-error').show();

            return false;

        }else{

            //hide the error message if it's shown
            $('#data-structure-error').hide();

            return true;

        }

    }

    /*
    Verifies if the data of the chart are valid
     */
    function chart_is_valid(data){

        //init variables
        const fields_with_errors_a = [];

        //define regex patterns ----------------------------------------------------------------------------------------

        //match an integer or a float value
        const patt_integer_or_float = /^(\d+\.\d+)|\d+$/;

        //match an integer or a float value with sign
        const patt_integer_or_float_with_sign = /^(\+|-)?(\d+\.\d+)|\d+$/;

        //match a float value
        const patt_float = /^\d\.\d$/;

        //match a hex rgb color or a rgba color
        const patt_color = /^((\#([0-9a-fA-F]{3}){1,2})|(rgba\(\d{1,3},\d{1,3},\d{1,3},(\d{1}|\d{1}\.\d{1,2})\)))$/;

        //match a hex rgb color, a rgba color or a comma separated list of hex rgb colors and rgba colors
        const patt_color_or_colors = /^((\#([0-9a-fA-F]{3}){1,2})|(rgba\(\d{1,3},\d{1,3},\d{1,3},(\d{1}|\d{1}\.\d{1,2})\)))(,(\#([0-9a-fA-F]{3}){1,2}|rgba\(\d{1,3},\d{1,3},\d{1,3},(\d{1}|\d{1}\.\d{1,2})\)))*$/;

        //match an integer or a comma separated list of integers
        const patt_integer_or_integers = /^(\d+|(\d+(,\d+)*))$/;

        //match an integer
        const patt_integer = /^\d+$/;

        //match a font family or a comma separated list of font families
        const patt_font_family_or_font_families = /^(('[^'"]+'|[^,"]+)(,('[^'"]+'|[^,"]+))*)$/;

        /**
         * Pattern to match all the data-fns (Unicode Tokens).
         *
         * See:
         *
         * - https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
         * - https://github.com/date-fns/date-fns/blob/main/docs/unicodeTokens.md
         */
        const patt_unicode_date_tokens = /^(\s|\/|,|:|G..GGG|GGGG|GGGGG|y|yy|yyy|yyyy|yyyyy+|Y|YY|YYY|YYYY|YYYYY+|u+|U..UUU|UUUU|UUUUU|r+|Q|QQ|QQQ|QQQQ|QQQQQ|q|qq|qqq|qqqq|qqqqq|M|MM|MMM|MMMM|MMMMM|L|LL|LLL|LLLL|LLLLL|l|w|ww|W|d|dd|D...DDD|F|g+|E..EEE|EEEE|EEEEE|EEEEEE|e|ee|eee|eeee|eeeee|eeeeee|E..EEE|EEEE|EEEEE|EEEEEE|e|ee|eee|eeee|eeeee|eeeeee|c..cc|ccc|cccc|ccccc|cccccc|a..aaa|aaaa|aaaaa|b..bbb|bbbb|bbbbb|B..BBB|BBBB|BBBBB|h|hh|H|HH|K|KK|k|kk|j|jj|jjj|jjjj|jjjjj|jjjjjj|J|JJ|C|CC|CCC|CCCC|CCCCC|CCCCCC|m|mm|s|ss|S+|A+|z..zzz|zzzz|Z..ZZZ|ZZZZ|ZZZZZ|O|OOOO|v|vvvv|V|VV|VVV|VVVV|X|XX|XXX|XXXX|XXXXX|x|xx|xxx|xxxx|xxxxx)+$/;

        //match a moment.js format output, for details see: http://momentjs.com/docs/#/displaying/format/
        const patt_moment_format_output = /^(\s|[0-9]|[a-z]|[A-Z]|\+|-|\[|\]|:|\.|\/|,)+$/;

        //match a URL
        const patt_url = /^https?:\/\/.+$/;

        //validate data ------------------------------------------------------------------------------------------------

        //Basic Info
        if( data.name.trim().length < 1 || data.name.trim().length > 200 ){fields_with_errors_a.push(objectL10n.name);}
        if( data.description.trim().length < 1 || data.description.trim().length > 200 ){fields_with_errors_a.push(objectL10n.description);}

        //Common Chart Configuration
        if(!patt_color.test(data.canvas_backgroundColor)){fields_with_errors_a.push(objectL10n.canvas_backgroundColor)}
        if(!patt_integer.test(data.width)){fields_with_errors_a.push(objectL10n.width)}
        if(!patt_integer.test(data.height)){fields_with_errors_a.push(objectL10n.height)}
        if(!patt_integer.test(data.margin_top)){fields_with_errors_a.push(objectL10n.margin_top)}
        if(!patt_integer.test(data.margin_bottom)){fields_with_errors_a.push(objectL10n.margin_bottom)}
        if(!patt_integer.test(data.responsiveAnimationDuration)){fields_with_errors_a.push(objectL10n.responsiveAnimationDuration);}
        if(!patt_integer.test(data.fixed_height)){fields_with_errors_a.push(objectL10n.fixed_height)}

        //Title Configuration
        if(!patt_integer.test(data.title_padding)){fields_with_errors_a.push(objectL10n.title_padding);}
        if(!patt_integer.test(data.title_fontSize)){fields_with_errors_a.push(objectL10n.title_fontSize);}
        if(!patt_color.test(data.title_fontColor)){fields_with_errors_a.push(objectL10n.title_fontColor);}
        if(!patt_font_family_or_font_families.test(data.title_fontFamily)){fields_with_errors_a.push(objectL10n.title_fontFamily);}

        //Legend Label Configuration
        if(!patt_integer.test(data.legend_labels_padding)){fields_with_errors_a.push(objectL10n.legend_labels_padding);}
        if(!patt_integer.test(data.legend_labels_boxWidth)){fields_with_errors_a.push(objectL10n.legend_labels_boxWidth);}
        if(!patt_integer.test(data.legend_labels_fontSize)){fields_with_errors_a.push(objectL10n.legend_labels_fontSize);}
        if(!patt_color.test(data.legend_labels_fontColor)){fields_with_errors_a.push(objectL10n.legend_labels_fontColor);}
        if(!patt_font_family_or_font_families.test(data.legend_labels_fontFamily)){fields_with_errors_a.push(objectL10n.legend_labels_fontFamily);}

        //Tooltip Configuration
        if(!patt_color.test(data.tooltips_backgroundColor)){fields_with_errors_a.push(objectL10n.tooltips_backgroundColor);}
        if(!patt_color.test(data.tooltips_multiKeyBackground)){fields_with_errors_a.push(objectL10n.tooltips_multiKeyBackground);}
        if(!patt_integer.test(data.tooltips_titleMarginBottom)){fields_with_errors_a.push(objectL10n.tooltips_titleMarginBottom);}
        if(!patt_integer.test(data.tooltips_footerMarginTop)){fields_with_errors_a.push(objectL10n.tooltips_footerMarginTop);}
        if(!patt_integer.test(data.tooltips_xPadding)){fields_with_errors_a.push(objectL10n.tooltips_xPadding);}
        if(!patt_integer.test(data.tooltips_yPadding)){fields_with_errors_a.push(objectL10n.tooltips_yPadding);}
        if(!patt_integer.test(data.tooltips_caretSize)){fields_with_errors_a.push(objectL10n.tooltips_caretSize);}
        if(!patt_integer.test(data.tooltips_cornerRadius)){fields_with_errors_a.push(objectL10n.tooltips_cornerRadius);}
        if(!patt_integer.test(data.hover_animationDuration)){fields_with_errors_a.push(objectL10n.hover_animationDuration);}
        if(!patt_integer.test(data.tooltips_titleFontSize)){fields_with_errors_a.push(objectL10n.tooltips_titleFontSize);}
        if(!patt_color.test(data.tooltips_titleFontColor)){fields_with_errors_a.push(objectL10n.tooltips_titleFontColor);}
        if(!patt_font_family_or_font_families.test(data.tooltips_titleFontFamily)){fields_with_errors_a.push(objectL10n.tooltips_titleFontFamily);}
        if(!patt_integer.test(data.tooltips_bodyFontSize)){fields_with_errors_a.push(objectL10n.tooltips_bodyFontSize);}
        if(!patt_color.test(data.tooltips_bodyFontColor)){fields_with_errors_a.push(objectL10n.tooltips_bodyFontColor);}
        if(!patt_font_family_or_font_families.test(data.tooltips_bodyFontFamily)){fields_with_errors_a.push(objectL10n.tooltips_bodyFontFamily);}
        if(!patt_integer.test(data.tooltips_footerFontSize)){fields_with_errors_a.push(objectL10n.tooltips_footerFontSize);}
        if(!patt_color.test(data.tooltips_footerFontColor)){fields_with_errors_a.push(objectL10n.tooltips_footerFontColor);}
        if(!patt_font_family_or_font_families.test(data.tooltips_footerFontFamily)){fields_with_errors_a.push(objectL10n.tooltips_footerFontFamily);}

        //Animation Configuration
        if(!patt_integer.test(data.animation_duration)){fields_with_errors_a.push(objectL10n.animation_duration);}

        //X Scale Grid Line
        if(!patt_color_or_colors.test(data.scales_xAxes_gridLines_color)){fields_with_errors_a.push(objectL10n.scales_xAxes_gridLines_color);}
        if(!patt_integer_or_integers.test(data.scales_xAxes_gridLines_lineWidth)){fields_with_errors_a.push(objectL10n.scales_xAxes_gridLines_lineWidth);}
        if(!patt_integer.test(data.scales_xAxes_gridLines_tickMarkLength)){fields_with_errors_a.push(objectL10n.scales_xAxes_gridLines_tickMarkLength);}
        if(!patt_color.test(data.scales_xAxes_gridLines_zeroLineColor)){fields_with_errors_a.push(objectL10n.scales_xAxes_gridLines_zeroLineColor);}
        if(!patt_integer.test(data.scales_xAxes_gridLines_zeroLineWidth)){fields_with_errors_a.push(objectL10n.scales_xAxes_gridLines_zeroLineWidth);}

        //X Scale Title
        if(!patt_integer.test(data.scales_xAxes_scaleLabel_fontSize)){fields_with_errors_a.push(objectL10n.scales_xAxes_scaleLabel_fontSize);}
        if(!patt_color.test(data.scales_xAxes_scaleLabel_fontColor)){fields_with_errors_a.push(objectL10n.scales_xAxes_scaleLabel_fontColor);}
        if(!patt_font_family_or_font_families.test(data.scales_xAxes_scaleLabel_fontFamily)){fields_with_errors_a.push(objectL10n.scales_xAxes_scaleLabel_fontFamily);}

        //X Scale Tick
        if(!patt_integer.test(data.scales_xAxes_ticks_labelOffset)){fields_with_errors_a.push(objectL10n.scales_xAxes_ticks_labelOffset);}
        if(!patt_integer.test(data.scales_xAxes_ticks_minRotation)){fields_with_errors_a.push(objectL10n.scales_xAxes_ticks_minRotation);}
        if(!patt_integer.test(data.scales_xAxes_ticks_maxRotation)){fields_with_errors_a.push(objectL10n.scales_xAxes_ticks_maxRotation);}
        if(!patt_integer.test(data.scales_xAxes_ticks_round) && data.scales_xAxes_ticks_round.trim().length !== 0  ){fields_with_errors_a.push(objectL10n.scales_xAxes_ticks_round);}
        if(!patt_integer.test(data.scales_xAxes_ticks_fontSize)){fields_with_errors_a.push(objectL10n.scales_xAxes_ticks_fontSize);}
        if(!patt_color.test(data.scales_xAxes_ticks_fontColor)){fields_with_errors_a.push(objectL10n.scales_xAxes_ticks_fontColor);}
        if(!patt_font_family_or_font_families.test(data.scales_xAxes_ticks_fontFamily)){fields_with_errors_a.push(objectL10n.scales_xAxes_ticks_fontFamily);}

        //X Scale Options
        if( !patt_integer_or_float_with_sign.test(data.scales_xAxes_ticks_min) && data.scales_xAxes_ticks_min.trim().length !== 0  ){fields_with_errors_a.push(objectL10n.scales_xAxes_ticks_min);}
        if( !patt_integer_or_float_with_sign.test(data.scales_xAxes_ticks_max) && data.scales_xAxes_ticks_max.trim().length !== 0  ){fields_with_errors_a.push(objectL10n.scales_xAxes_ticks_max);}
        if( !patt_integer_or_float_with_sign.test(data.scales_xAxes_ticks_suggestedMax) && data.scales_xAxes_ticks_suggestedMax.trim().length !== 0  ){fields_with_errors_a.push(objectL10n.scales_xAxes_ticks_suggestedMax);}
        if( !patt_integer_or_float_with_sign.test(data.scales_xAxes_ticks_suggestedMin) && data.scales_xAxes_ticks_suggestedMin.trim().length !== 0  ){fields_with_errors_a.push(objectL10n.scales_xAxes_ticks_suggestedMin);}
        if( !patt_integer_or_float.test(data.scales_xAxes_ticks_stepSize) && data.scales_xAxes_ticks_stepSize.trim().length !== 0  ){fields_with_errors_a.push(objectL10n.scales_xAxes_ticks_stepSize);}
        if( !patt_integer.test(data.scales_xAxes_ticks_maxTicksLimit) && data.scales_xAxes_ticks_maxTicksLimit.trim().length !== 0 ){fields_with_errors_a.push(objectL10n.scales_xAxes_ticks_maxTicksLimit);}
        if(!patt_integer_or_float.test(data.scales_xAxes_categoryPercentage)){fields_with_errors_a.push(objectL10n.scales_xAxes_categoryPercentage);}
        if(!patt_integer_or_float.test(data.scales_xAxes_barPercentage)){fields_with_errors_a.push(objectL10n.scales_xAxes_barPercentage);}

        //X Scale Time
        if(!patt_unicode_date_tokens.test(data.scales_xAxes_time_format)){fields_with_errors_a.push(objectL10n.scales_xAxes_time_format);}
        if(!patt_unicode_date_tokens.test(data.scales_xAxes_time_tooltipFormat)){fields_with_errors_a.push(objectL10n.scales_xAxes_time_tooltipFormat);}
        if(!patt_unicode_date_tokens.test(data.scales_xAxes_time_unit_format)){fields_with_errors_a.push(objectL10n.scales_xAxes_time_unit_format);}
        if( !patt_moment_format_output.test(data.scales_xAxes_time_min) && data.scales_xAxes_time_min.trim().length !== 0 ){fields_with_errors_a.push(objectL10n.scales_xAxes_time_min);}
        if( !patt_moment_format_output.test(data.scales_xAxes_time_max) && data.scales_xAxes_time_max.trim().length !== 0 ){fields_with_errors_a.push(objectL10n.scales_xAxes_time_max);}
        if(!patt_integer.test(data.scales_xAxes_time_unitStepSize)){fields_with_errors_a.push(objectL10n.scales_xAxes_time_unitStepSize);}

        //Y Scale Grid Line
        if(!patt_color_or_colors.test(data.scales_yAxes_gridLines_color)){fields_with_errors_a.push(objectL10n.scales_yAxes_gridLines_color);}
        if(!patt_integer_or_integers.test(data.scales_yAxes_gridLines_lineWidth)){fields_with_errors_a.push(objectL10n.scales_yAxes_gridLines_lineWidth);}
        if(!patt_integer.test(data.scales_yAxes_gridLines_tickMarkLength)){fields_with_errors_a.push(objectL10n.scales_yAxes_gridLines_tickMarkLength);}
        if(!patt_color.test(data.scales_yAxes_gridLines_zeroLineColor)){fields_with_errors_a.push(objectL10n.scales_yAxes_gridLines_zeroLineColor);}
        if(!patt_integer.test(data.scales_yAxes_gridLines_zeroLineWidth)){fields_with_errors_a.push(objectL10n.scales_yAxes_gridLines_zeroLineWidth);}

        //Y Scale Title
        if(!patt_integer.test(data.scales_yAxes_scaleLabel_fontSize)){fields_with_errors_a.push(objectL10n.scales_yAxes_scaleLabel_fontSize);}
        if(!patt_color.test(data.scales_yAxes_scaleLabel_fontColor)){fields_with_errors_a.push(objectL10n.scales_yAxes_scaleLabel_fontColor);}
        if(!patt_font_family_or_font_families.test(data.scales_yAxes_scaleLabel_fontFamily)){fields_with_errors_a.push(objectL10n.scales_yAxes_scaleLabel_fontFamily);}

        //Y Scale Tick
        if(!patt_integer.test(data.scales_yAxes_ticks_minRotation)){fields_with_errors_a.push(objectL10n.scales_yAxes_ticks_minRotation);}
        if(!patt_integer.test(data.scales_yAxes_ticks_maxRotation)){fields_with_errors_a.push(objectL10n.scales_yAxes_ticks_maxRotation);}
        if(!patt_integer.test(data.scales_yAxes_ticks_padding)){fields_with_errors_a.push(objectL10n.scales_yAxes_ticks_padding);}
        if(!patt_integer.test(data.scales_yAxes_ticks_round) && data.scales_yAxes_ticks_round.trim().length !== 0  ){fields_with_errors_a.push(objectL10n.scales_yAxes_ticks_round);}
        if(!patt_integer.test(data.scales_yAxes_ticks_fontSize)){fields_with_errors_a.push(objectL10n.scales_yAxes_ticks_fontSize);}
        if(!patt_color.test(data.scales_yAxes_ticks_fontColor)){fields_with_errors_a.push(objectL10n.scales_yAxes_ticks_fontColor);}
        if(!patt_font_family_or_font_families.test(data.scales_yAxes_ticks_fontFamily)){fields_with_errors_a.push(objectL10n.scales_yAxes_ticks_fontFamily);}

        //Y Scale Options
        if( !patt_integer_or_float_with_sign.test(data.scales_yAxes_ticks_min) && data.scales_yAxes_ticks_min.trim().length !== 0  ){fields_with_errors_a.push(objectL10n.scales_yAxes_ticks_min);}
        if( !patt_integer_or_float_with_sign.test(data.scales_yAxes_ticks_max) && data.scales_yAxes_ticks_max.trim().length !== 0  ){fields_with_errors_a.push(objectL10n.scales_yAxes_ticks_max);}
        if( !patt_integer_or_float_with_sign.test(data.scales_yAxes_ticks_suggestedMin) && data.scales_yAxes_ticks_suggestedMin.trim().length !== 0  ){fields_with_errors_a.push(objectL10n.scales_yAxes_ticks_suggestedMin);}
        if( !patt_integer_or_float_with_sign.test(data.scales_yAxes_ticks_suggestedMax) && data.scales_yAxes_ticks_suggestedMax.trim().length !== 0  ){fields_with_errors_a.push(objectL10n.scales_yAxes_ticks_suggestedMax);}
        if( !patt_integer_or_float.test(data.scales_yAxes_ticks_stepSize) && data.scales_yAxes_ticks_stepSize.trim().length !== 0  ){fields_with_errors_a.push(objectL10n.scales_yAxes_ticks_stepSize);}
        if( !patt_integer.test(data.scales_yAxes_ticks_maxTicksLimit) && data.scales_yAxes_ticks_maxTicksLimit.trim().length !== 0 ){fields_with_errors_a.push(objectL10n.scales_yAxes_ticks_maxTicksLimit);}
        if(!patt_integer_or_float.test(data.scales_yAxes_categoryPercentage)){fields_with_errors_a.push(objectL10n.scales_yAxes_categoryPercentage);}
        if(!patt_integer_or_float.test(data.scales_yAxes_barPercentage)){fields_with_errors_a.push(objectL10n.scales_yAxes_barPercentage);}

        //Y2 Scale Grid Line
        if(!patt_color_or_colors.test(data.scales_y2Axes_gridLines_color)){fields_with_errors_a.push(objectL10n.scales_y2Axes_gridLines_color);}
        if(!patt_integer_or_integers.test(data.scales_y2Axes_gridLines_lineWidth)){fields_with_errors_a.push(objectL10n.scales_y2Axes_gridLines_lineWidth);}
        if(!patt_integer.test(data.scales_y2Axes_gridLines_tickMarkLength)){fields_with_errors_a.push(objectL10n.scales_y2Axes_gridLines_tickMarkLength);}
        if(!patt_color.test(data.scales_y2Axes_gridLines_zeroLineColor)){fields_with_errors_a.push(objectL10n.scales_y2Axes_gridLines_zeroLineColor);}
        if(!patt_integer.test(data.scales_y2Axes_gridLines_zeroLineWidth)){fields_with_errors_a.push(objectL10n.scales_y2Axes_gridLines_zeroLineWidth);}

        //Y2 Scale Title
        if(!patt_integer.test(data.scales_y2Axes_scaleLabel_fontSize)){fields_with_errors_a.push(objectL10n.scales_y2Axes_scaleLabel_fontSize);}
        if(!patt_color.test(data.scales_y2Axes_scaleLabel_fontColor)){fields_with_errors_a.push(objectL10n.scales_y2Axes_scaleLabel_fontColor);}
        if(!patt_font_family_or_font_families.test(data.scales_y2Axes_scaleLabel_fontFamily)){fields_with_errors_a.push(objectL10n.scales_y2Axes_scaleLabel_fontFamily);}

        //Y2 Scale Tick
        if(!patt_integer.test(data.scales_y2Axes_ticks_minRotation)){fields_with_errors_a.push(objectL10n.scales_y2Axes_ticks_minRotation);}
        if(!patt_integer.test(data.scales_y2Axes_ticks_maxRotation)){fields_with_errors_a.push(objectL10n.scales_y2Axes_ticks_maxRotation);}
        if(!patt_integer.test(data.scales_y2Axes_ticks_padding)){fields_with_errors_a.push(objectL10n.scales_y2Axes_ticks_padding);}
        if(!patt_integer.test(data.scales_y2Axes_ticks_round) && data.scales_y2Axes_ticks_round.trim().length !== 0  ){fields_with_errors_a.push(objectL10n.scales_y2Axes_ticks_round);}
        if(!patt_integer.test(data.scales_y2Axes_ticks_fontSize)){fields_with_errors_a.push(objectL10n.scales_y2Axes_ticks_fontSize);}
        if(!patt_color.test(data.scales_y2Axes_ticks_fontColor)){fields_with_errors_a.push(objectL10n.scales_y2Axes_ticks_fontColor);}
        if(!patt_font_family_or_font_families.test(data.scales_y2Axes_ticks_fontFamily)){fields_with_errors_a.push(objectL10n.scales_y2Axes_ticks_fontFamily);}

        //Y2 Scale Options
        if( !patt_integer_or_float_with_sign.test(data.scales_y2Axes_ticks_min) && data.scales_y2Axes_ticks_min.trim().length !== 0  ){fields_with_errors_a.push(objectL10n.scales_y2Axes_ticks_min);}
        if( !patt_integer_or_float_with_sign.test(data.scales_y2Axes_ticks_max) && data.scales_y2Axes_ticks_max.trim().length !== 0  ){fields_with_errors_a.push(objectL10n.scales_y2Axes_ticks_max);}
        if( !patt_integer_or_float_with_sign.test(data.scales_y2Axes_ticks_suggestedMin) && data.scales_y2Axes_ticks_suggestedMin.trim().length !== 0  ){fields_with_errors_a.push(objectL10n.scales_y2Axes_ticks_suggestedMin);}
        if( !patt_integer_or_float_with_sign.test(data.scales_y2Axes_ticks_suggestedMax) && data.scales_y2Axes_ticks_suggestedMax.trim().length !== 0  ){fields_with_errors_a.push(objectL10n.scales_y2Axes_ticks_suggestedMax);}
        if( !patt_integer_or_float.test(data.scales_y2Axes_ticks_stepSize) && data.scales_y2Axes_ticks_stepSize.trim().length !== 0  ){fields_with_errors_a.push(objectL10n.scales_y2Axes_ticks_stepSize);}
        if( !patt_integer.test(data.scales_y2Axes_ticks_maxTicksLimit) && data.scales_y2Axes_ticks_maxTicksLimit.trim().length !== 0 ){fields_with_errors_a.push(objectL10n.scales_y2Axes_ticks_maxTicksLimit);}

        /* RL Scale Grid Line Configuration */
        if(!patt_color_or_colors.test(data.scales_rl_gridLines_color)){fields_with_errors_a.push(objectL10n.scales_rl_gridLines_color);}
        if(!patt_integer_or_integers.test(data.scales_rl_gridLines_lineWidth)){fields_with_errors_a.push(objectL10n.scales_rl_gridLines_lineWidth);}

        /* RL Scale Angle Line Configuration */
        if(!patt_color.test(data.scales_rl_angleLines_color)){fields_with_errors_a.push(objectL10n.scales_rl_angleLines_color);}
        if(!patt_integer.test(data.scales_rl_angleLines_lineWidth)){fields_with_errors_a.push(objectL10n.scales_rl_angleLines_lineWidth);}

        /* RL Scale Point Label Configuration */
        if(!patt_integer.test(data.scales_rl_pointLabels_fontSize)){fields_with_errors_a.push(objectL10n.scales_rl_pointLabels_fontSize);}
        if(!patt_color.test(data.scales_rl_pointLabels_fontColor)){fields_with_errors_a.push(objectL10n.scales_rl_pointLabels_fontColor);}
        if(!patt_font_family_or_font_families.test(data.scales_rl_pointLabels_fontFamily)){fields_with_errors_a.push(objectL10n.scales_rl_pointLabels_fontFamily);}

        /* RL Scale Tick Configuration */
        if(!patt_integer.test(data.scales_rl_ticks_round) && data.scales_rl_ticks_round.trim().length !== 0  ){fields_with_errors_a.push(objectL10n.scales_rl_ticks_round);}
        if(!patt_integer.test(data.scales_rl_ticks_fontSize)){fields_with_errors_a.push(objectL10n.scales_rl_ticks_fontSize);}
        if(!patt_color.test(data.scales_rl_ticks_fontColor)){fields_with_errors_a.push(objectL10n.scales_rl_ticks_fontColor);}
        if(!patt_font_family_or_font_families.test(data.scales_rl_ticks_fontFamily)){fields_with_errors_a.push(objectL10n.scales_rl_ticks_fontFamily);}

        /* RL Scale Configuration Options */
        if( !patt_integer_or_float_with_sign.test(data.scales_rl_ticks_min) && data.scales_rl_ticks_min.trim().length !== 0  ){fields_with_errors_a.push(objectL10n.scales_rl_ticks_min);}
        if( !patt_integer_or_float_with_sign.test(data.scales_rl_ticks_max) && data.scales_rl_ticks_max.trim().length !== 0  ){fields_with_errors_a.push(objectL10n.scales_rl_ticks_max);}
        if( !patt_integer_or_float_with_sign.test(data.scales_rl_ticks_suggestedMin) && data.scales_rl_ticks_suggestedMin.trim().length !== 0  ){fields_with_errors_a.push(objectL10n.scales_rl_ticks_suggestedMin);}
        if( !patt_integer_or_float_with_sign.test(data.scales_rl_ticks_suggestedMax) && data.scales_rl_ticks_suggestedMax.trim().length !== 0  ){fields_with_errors_a.push(objectL10n.scales_rl_ticks_suggestedMax);}
        if( !patt_integer_or_float.test(data.scales_rl_ticks_stepSize) && data.scales_rl_ticks_stepSize.trim().length !== 0  ){fields_with_errors_a.push(objectL10n.scales_rl_ticks_stepSize);}
        if( !patt_integer.test(data.scales_rl_ticks_maxTicksLimit) && data.scales_rl_ticks_maxTicksLimit.trim().length !== 0 ){fields_with_errors_a.push(objectL10n.scales_rl_ticks_maxTicksLimit);}
        if(!patt_color.test(data.scales_rl_ticks_backdropColor)){fields_with_errors_a.push(objectL10n.scales_rl_ticks_backdropColor);}
        if(!patt_integer.test(data.scales_rl_ticks_backdropPaddingX)){fields_with_errors_a.push(objectL10n.scales_rl_ticks_backdropPaddingX);}
        if(!patt_integer.test(data.scales_rl_ticks_backdropPaddingY)){fields_with_errors_a.push(objectL10n.scales_rl_ticks_backdropPaddingY);}

        /* Source */
        if(data.source_url.trim().length > 0 && !patt_url.test(data.source_url)){fields_with_errors_a.push(objectL10n.source_url);}

        if( fields_with_errors_a.length > 0){

            return fields_with_errors_a;

        }else{

            return true;

        }

    }

    /*
    Initialize the spectrum color picker
     */
    function initialize_spectrum(){

        $(".spectrum-input").spectrum({

            //options --------------------------------------------------------------------------------------------------
            color: 'rgba(0,117,165,1)',
            showAlpha: true,
            cancelText: objectL10n.cancelText,
            chooseText: objectL10n.chooseText,
            preferredFormat: 'rgb',

            //events ---------------------------------------------------------------------------------------------------
            change: function(color) {

                //get the name of the element involved
                const element_name = $(this).attr('id').substr(0, ( $(this).attr('id').length - 9 ) )

                //prepare the values of the color components
                const red = parseInt(color._r, 10);
                const green = parseInt(color._g, 10);
                const blue = parseInt(color._b, 10);
                const alpha = Math.round( color._a * 10 ) / 10;

                //generate the color in the rgba format
                const rgba_color = 'rgba(' + red + ',' + green + ',' + blue + ',' + alpha + ')';

                //if the related field is not empty add a comma and the color, otherwise add only the color
                if( $("#" + element_name).val().trim().length > 0 ){
                    $("#" + element_name).val( $("#" + element_name).val().trim() + ',' + rgba_color );
                }else{
                    $("#" + element_name).val( rgba_color );
                }

            }

        });

        //.spectrum-toggle -> click - EVENT LISTENER (a click on the colored circle that activates the color picker modal window)
        $(".spectrum-toggle").click(function() {

            //get the name of the element involved
            const element_name = $(this).attr('id').substr(0, ( $(this).attr('id').length - 16 ) )

            //toggle the colorpicker
            $("#" + element_name + "-spectrum").spectrum("toggle");

            //get the container of the color picker
            const container = $("#" + element_name + "-spectrum").spectrum("container");

            //add a data attribute to the color picker used during the resize event to identify the element involved
            $(container).attr('data-element-involved', element_name);

            //position the container of the color picker on the right of the toggle
            const toggle_position = $("#" + element_name + "-spectrum-toggle").offset();

            if( $(document).width() - 227 > toggle_position.left ){

                //if there is enough space on the right of the color picker show the color picker on the right of the toggle
                container.css('left', toggle_position.left + 28);

            }else{

                //otherwise show the color picker on the left of the toogle
                container.css('left', toggle_position.left - 202);

            }
            container.css('top', toggle_position.top + -2);

            //save the element name in a global variable, so that will be used during the resize event
            window.dauc_element_name = element_name;

            return false;

        });

        //window -> resize - EVENT LISTENER
        $(window).resize(function(){

            //get the element from a global variable
            const element_name = window.dauc_element_name;

            //disable the color picker
            const container = $("#" + element_name + "-spectrum").spectrum("disable");

        });

        //window -> load - EVENT LISTENER (page completely loaded)
        $(window).bind("load", function() {

            $('.spectrum-toggle, .spectrum-input').css('visibility', 'visible');

        });

    }

    /*
    Save the data of the chart and refresh the preview of the chart
     */
    function save_and_refresh(){

        const validation_result = save_chart(false);

        if(validation_result !== true){

            //detach iframe
            $( '#chart-preview-iframe').detach();

            //show error message
            $('#chart-preview-error').hide();
            $('#chart-preview-error').delay(400).fadeIn(0);

            /**
             * Add the validation errors message to the
             * #chart-preview-error-details container. Then show the
             * container.
             */
            let message = 'Please enter valid values in the following fields: ';
            for(let i = 0; i < validation_result.length; i++){
                message += validation_result[i];
                if(i < validation_result.length - 1){
                    message += ', ';
                }
            }
            $('#chart-preview-error-details').text(message);
            $('#chart-preview-error-details').hide();
            $('#chart-preview-error-details').delay(400).fadeIn(0);

        }else{

            $('#chart-preview-error').hide();
            $('#chart-preview-error-details').hide();

            let chart_id = null;
            if( $('#temporary-chart-id').length ){
                chart_id = $('#temporary-chart-id').val();
            }else{
                chart_id = $('#update-id').val();
            }

            if( $('#chart-preview-iframe').length ){

                //if the iframe exists detach the old iframe and add the new iframe
                $( '#chart-preview-iframe').detach();
                $('#chart-preview-iframe-container').append('<iframe scrolling="no" id="chart-preview-iframe" src="' + window.DAEXTDAUC_PARAMETERS.site_url + '?chart-preview=' + chart_id + '"></iframe>');

            }else{

                //if the iframe doesn't exist add the iframe
                $('#chart-preview-iframe-container').append('<iframe scrolling="no" id="chart-preview-iframe" src="' + window.DAEXTDAUC_PARAMETERS.site_url + '?chart-preview=' + chart_id + '"></iframe>');

            }

        }

    }

    /*
    * Save the chart. Used by the #save -> click and the #save-and-refresh -> click event handler
     */
    function save_chart(reload_menu){

        //get form data
        let chart_id = null;
        if( $('#temporary-chart-id').length ){
            chart_id = $('#temporary-chart-id').val();
        }else{
            chart_id = $('#update-id').val();
        }
        const name = $('#name').val();
        const description = $('#description').val();
        const type = $('#type').val();
        const rows = $('#rows').val();
        const columns = $('#columns').val();
        const is_model = parseInt($('#is-model').val(), 10);

        //Common Chart Configuration
        const canvas_transparent_background = $('#canvas-transparent-background').val();
        const canvas_backgroundColor = $('#canvas-backgroundColor').val().replace(/ /g,'');
        const margin_top = $('#margin-top').val();
        const margin_bottom = $('#margin-bottom').val();
        const width = $('#width').val();
        const height = $('#height').val();
        const responsive = $('#responsive').val();
        const responsiveAnimationDuration = $('#responsiveAnimationDuration').val();
        const maintainAspectRatio = $('#maintainAspectRatio').val();
        const fixed_height = $('#fixed-height').val();

        //Title Configuration
        const title_display = $('#title-display').val();
        const title_position = $('#title-position').val();
        const title_fullWidth = $('#title-fullWidth').val();
        const title_fontSize = $('#title-fontSize').val();
        const title_fontFamily = $('#title-fontFamily').val().trim();
        const title_fontColor = $('#title-fontColor').val().replace(/ /g,'');
        const title_fontStyle = $('#title-fontStyle').val();
        const title_padding = $('#title-padding').val();

        //Legend Configuration
        const legend_display = $('#legend-display').val();
        const legend_position = $('#legend-position').val();
        const legend_fullWidth = $('#legend-fullWidth').val();
        const legend_toggle_dataset = $('#legend-toggle-dataset').val();

        //Legend Label Configuration
        const legend_labels_boxWidth = $('#legend-labels-boxWidth').val();
        const legend_labels_fontSize = $('#legend-labels-fontSize').val();
        const legend_labels_fontStyle = $('#legend-labels-fontStyle').val();
        const legend_labels_fontColor = $('#legend-labels-fontColor').val().replace(/ /g,'');
        const legend_labels_fontFamily = $('#legend-labels-fontFamily').val().trim();
        const legend_labels_padding = $('#legend-labels-padding').val();

        //Tooltip Configuration
        const tooltips_enabled = $('#tooltips-enabled').val();
        const tooltips_mode = $('#tooltips-mode').val();
        const tooltips_backgroundColor = $('#tooltips-backgroundColor').val().replace(/ /g,'');
        const tooltips_titleFontFamily = $('#tooltips-titleFontFamily').val().trim();
        const tooltips_titleFontSize = $('#tooltips-titleFontSize').val();
        const tooltips_titleFontStyle = $('#tooltips-titleFontStyle').val();
        const tooltips_titleFontColor = $('#tooltips-titleFontColor').val().replace(/ /g,'');
        const tooltips_titleMarginBottom = $('#tooltips-titleMarginBottom').val();
        const tooltips_bodyFontFamily = $('#tooltips-bodyFontFamily').val().trim();
        const tooltips_bodyFontSize = $('#tooltips-bodyFontSize').val();
        const tooltips_bodyFontStyle = $('#tooltips-bodyFontStyle').val();
        const tooltips_bodyFontColor = $('#tooltips-bodyFontColor').val().replace(/ /g,'');
        const tooltips_footerFontFamily = $('#tooltips-footerFontFamily').val().trim();
        const tooltips_footerFontSize = $('#tooltips-footerFontSize').val();
        const tooltips_footerFontStyle = $('#tooltips-footerFontStyle').val();
        const tooltips_footerFontColor = $('#tooltips-footerFontColor').val().replace(/ /g,'');
        const tooltips_footerMarginTop = $('#tooltips-footerMarginTop').val();
        const tooltips_xPadding = $('#tooltips-xPadding').val();
        const tooltips_yPadding = $('#tooltips-yPadding').val();
        const tooltips_caretSize = $('#tooltips-caretSize').val();
        const tooltips_cornerRadius = $('#tooltips-cornerRadius').val();
        const tooltips_multiKeyBackground  = $('#tooltips-multiKeyBackground').val().replace(/ /g,'');
        const tooltips_beforeTitle = $('#tooltips-beforeTitle').val();
        const tooltips_afterTitle = $('#tooltips-afterTitle').val();
        const tooltips_beforeBody = $('#tooltips-beforeBody').val();
        const tooltips_afterBody = $('#tooltips-afterBody').val();
        const tooltips_beforeLabel = $('#tooltips-beforeLabel').val();
        const tooltips_afterLabel = $('#tooltips-afterLabel').val();
        const tooltips_beforeValue = $('#tooltips-beforeValue').val();
        const tooltips_afterValue = $('#tooltips-afterValue').val();
        const tooltips_beforeFooter = $('#tooltips-beforeFooter').val();
        const tooltips_footer = $('#tooltips-footer').val();
        const tooltips_afterFooter = $('#tooltips-afterFooter').val();

        //Hover Configuration
        const hover_animationDuration = $('#hover-animationDuration').val();

        //Animation Configuration
        const animation_duration = $('#animation-duration').val();
        const animation_easing = $('#animation-easing').val();
        const animation_instantiation_event = $('#animation-instantiation-event').val();

        //Misc Configuration
        const elements_rectangle_borderSkipped = $('#elements-rectangle-borderSkipped').val();
        const half_pie_doughnut = $('#half-pie-doughnut').val();
        const indexAxis = $('#indexAxis').val();
        const thousands_separator = $('#thousands-separator').val();
        const decimal_separator = $('#decimal-separator').val();

        //Scales Common Configuration X
        const scales_xAxes_type = $('#scales-xAxes-type').val();
        const scales_xAxes_display = $('#scales-xAxes-display').val();
        const scales_xAxes_position = $('#scales-xAxes-position').val();
        const scales_xAxes_stacked = $('#scales-xAxes-stacked').val();

        //Scales Grid Line Configuration X
        const scales_xAxes_gridLines_display = $('#scales-xAxes-gridLines-display').val();
        const scales_xAxes_gridLines_color = $('#scales-xAxes-gridLines-color').val();
        const scales_xAxes_gridLines_lineWidth = $('#scales-xAxes-gridLines-lineWidth').val();
        const scales_xAxes_gridLines_drawBorder = $('#scales-xAxes-gridLines-drawBorder').val();
        const scales_xAxes_gridLines_drawOnChartArea = $('#scales-xAxes-gridLines-drawOnChartArea').val();
        const scales_xAxes_gridLines_drawTicks = $('#scales-xAxes-gridLines-drawTicks').val();
        const scales_xAxes_gridLines_tickMarkLength = $('#scales-xAxes-gridLines-tickMarkLength').val();
        const scales_xAxes_gridLines_zeroLineWidth = $('#scales-xAxes-gridLines-zeroLineWidth').val();
        const scales_xAxes_gridLines_zeroLineColor = $('#scales-xAxes-gridLines-zeroLineColor').val();
        const scales_xAxes_gridLines_offsetGridLines = $('#scales-xAxes-gridLines-offsetGridLines').val();

        //Scales Title Configuration X
        const scales_xAxes_scaleLabel_display = $('#scales-xAxes-scaleLabel-display').val();
        const scales_xAxes_scaleLabel_labelString = $('#scales-xAxes-scaleLabel-labelString').val();
        const scales_xAxes_scaleLabel_fontColor = $('#scales-xAxes-scaleLabel-fontColor').val();
        const scales_xAxes_scaleLabel_fontFamily = $('#scales-xAxes-scaleLabel-fontFamily').val();
        const scales_xAxes_scaleLabel_fontSize = $('#scales-xAxes-scaleLabel-fontSize').val();
        const scales_xAxes_scaleLabel_fontStyle = $('#scales-xAxes-scaleLabel-fontStyle').val();

        //Scales Tick Configuration X
        const scales_xAxes_ticks_autoskip = $('#scales-xAxes-ticks-autoskip').val();
        const scales_xAxes_ticks_display = $('#scales-xAxes-ticks-display').val();
        const scales_xAxes_ticks_fontColor = $('#scales-xAxes-ticks-fontColor').val();
        const scales_xAxes_ticks_fontFamily = $('#scales-xAxes-ticks-fontFamily').val();
        const scales_xAxes_ticks_fontSize = $('#scales-xAxes-ticks-fontSize').val();
        const scales_xAxes_ticks_fontStyle = $('#scales-xAxes-ticks-fontStyle').val();
        const scales_xAxes_ticks_labelOffset = $('#scales-xAxes-ticks-labelOffset').val();
        const scales_xAxes_ticks_maxRotation = $('#scales-xAxes-ticks-maxRotation').val();
        const scales_xAxes_ticks_minRotation = $('#scales-xAxes-ticks-minRotation').val();
        const scales_xAxes_ticks_reverse = $('#scales-xAxes-ticks-reverse').val();
        const scales_xAxes_ticks_prefix = $('#scales-xAxes-ticks-prefix').val();
        const scales_xAxes_ticks_suffix = $('#scales-xAxes-ticks-suffix').val();
        const scales_xAxes_ticks_round = $('#scales-xAxes-ticks-round').val();

        //Scale Configuration Options X
        const scales_xAxes_ticks_min = $('#scales-xAxes-ticks-min').val();
        const scales_xAxes_ticks_max = $('#scales-xAxes-ticks-max').val();
        const scales_xAxes_ticks_beginAtZero = $('#scales-xAxes-ticks-beginAtZero').val();
        const scales_xAxes_ticks_maxTicksLimit = $('#scales-xAxes-ticks-maxTicksLimit').val();
        const scales_xAxes_ticks_stepSize = $('#scales-xAxes-ticks-stepSize').val();
        const scales_xAxes_ticks_suggestedMax = $('#scales-xAxes-ticks-suggestedMax').val();
        const scales_xAxes_ticks_suggestedMin = $('#scales-xAxes-ticks-suggestedMin').val();
        const scales_xAxes_categoryPercentage = $('#scales-xAxes-categoryPercentage').val();
        const scales_xAxes_barPercentage = $('#scales-xAxes-barPercentage').val();

        //Time Scale Configuration Options X
        const scales_xAxes_time_format = $('#scales-xAxes-time-format').val();
        const scales_xAxes_time_tooltipFormat = $('#scales-xAxes-time-tooltipFormat').val();
        const scales_xAxes_time_unit_format = $('#scales-xAxes-time-unit-format').val();
        const scales_xAxes_time_unit = $('#scales-xAxes-time-unit').val();
        const scales_xAxes_time_unitStepSize = $('#scales-xAxes-time-unitStepSize').val();
        const scales_xAxes_time_max = $('#scales-xAxes-time-max').val();
        const scales_xAxes_time_min = $('#scales-xAxes-time-min').val();

        //Scales Common Configuration Y
        const scales_yAxes_type = $('#scales-yAxes-type').val();
        const scales_yAxes_display = $('#scales-yAxes-display').val();
        const scales_yAxes_position = $('#scales-yAxes-position').val();
        const scales_yAxes_stacked = $('#scales-yAxes-stacked').val();

        //Scales Grid Line Configuration Y
        const scales_yAxes_gridLines_display = $('#scales-yAxes-gridLines-display').val();
        const scales_yAxes_gridLines_color = $('#scales-yAxes-gridLines-color').val();
        const scales_yAxes_gridLines_lineWidth = $('#scales-yAxes-gridLines-lineWidth').val();
        const scales_yAxes_gridLines_drawBorder = $('#scales-yAxes-gridLines-drawBorder').val();
        const scales_yAxes_gridLines_drawOnChartArea = $('#scales-yAxes-gridLines-drawOnChartArea').val();
        const scales_yAxes_gridLines_drawTicks = $('#scales-yAxes-gridLines-drawTicks').val();
        const scales_yAxes_gridLines_tickMarkLength = $('#scales-yAxes-gridLines-tickMarkLength').val();
        const scales_yAxes_gridLines_zeroLineWidth = $('#scales-yAxes-gridLines-zeroLineWidth').val();
        const scales_yAxes_gridLines_zeroLineColor = $('#scales-yAxes-gridLines-zeroLineColor').val();
        const scales_yAxes_gridLines_offsetGridLines = $('#scales-yAxes-gridLines-offsetGridLines').val();

        //Scales Title Configuration Y
        const scales_yAxes_scaleLabel_display = $('#scales-yAxes-scaleLabel-display').val();
        const scales_yAxes_scaleLabel_labelString = $('#scales-yAxes-scaleLabel-labelString').val();
        const scales_yAxes_scaleLabel_fontColor = $('#scales-yAxes-scaleLabel-fontColor').val();
        const scales_yAxes_scaleLabel_fontFamily = $('#scales-yAxes-scaleLabel-fontFamily').val();
        const scales_yAxes_scaleLabel_fontSize = $('#scales-yAxes-scaleLabel-fontSize').val();
        const scales_yAxes_scaleLabel_fontStyle = $('#scales-yAxes-scaleLabel-fontStyle').val();

        //Scales Tick Configuration Y
        const scales_yAxes_ticks_autoskip = $('#scales-yAxes-ticks-autoskip').val();
        const scales_yAxes_ticks_display = $('#scales-yAxes-ticks-display').val();
        const scales_yAxes_ticks_fontColor = $('#scales-yAxes-ticks-fontColor').val();
        const scales_yAxes_ticks_fontFamily = $('#scales-yAxes-ticks-fontFamily').val();
        const scales_yAxes_ticks_fontSize = $('#scales-yAxes-ticks-fontSize').val();
        const scales_yAxes_ticks_fontStyle = $('#scales-yAxes-ticks-fontStyle').val();
        const scales_yAxes_ticks_maxRotation = $('#scales-yAxes-ticks-maxRotation').val();
        const scales_yAxes_ticks_minRotation = $('#scales-yAxes-ticks-minRotation').val();
        const scales_yAxes_ticks_mirror = $('#scales-yAxes-ticks-mirror').val();
        const scales_yAxes_ticks_padding = $('#scales-yAxes-ticks-padding').val();
        const scales_yAxes_ticks_reverse = $('#scales-yAxes-ticks-reverse').val();
        const scales_yAxes_ticks_prefix = $('#scales-yAxes-ticks-prefix').val();
        const scales_yAxes_ticks_suffix = $('#scales-yAxes-ticks-suffix').val();
        const scales_yAxes_ticks_round = $('#scales-yAxes-ticks-round').val();

        //Scale Configuration Options Y
        const scales_yAxes_ticks_min = $('#scales-yAxes-ticks-min').val();
        const scales_yAxes_ticks_max = $('#scales-yAxes-ticks-max').val();
        const scales_yAxes_ticks_beginAtZero = $('#scales-yAxes-ticks-beginAtZero').val();
        const scales_yAxes_ticks_maxTicksLimit = $('#scales-yAxes-ticks-maxTicksLimit').val();
        const scales_yAxes_ticks_stepSize = $('#scales-yAxes-ticks-stepSize').val();
        const scales_yAxes_ticks_suggestedMax = $('#scales-yAxes-ticks-suggestedMax').val();
        const scales_yAxes_ticks_suggestedMin = $('#scales-yAxes-ticks-suggestedMin').val();
        const scales_yAxes_categoryPercentage = $('#scales-yAxes-categoryPercentage').val();
        const scales_yAxes_barPercentage = $('#scales-yAxes-barPercentage').val();

        //Scales Common Configuration Y2
        const scales_y2Axes_type = $('#scales-y2Axes-type').val();
        const scales_y2Axes_display = $('#scales-y2Axes-display').val();
        const scales_y2Axes_position = $('#scales-y2Axes-position').val();

        //Scales Grid Line Configuration Y2
        const scales_y2Axes_gridLines_display = $('#scales-y2Axes-gridLines-display').val();
        const scales_y2Axes_gridLines_color = $('#scales-y2Axes-gridLines-color').val();
        const scales_y2Axes_gridLines_lineWidth = $('#scales-y2Axes-gridLines-lineWidth').val();
        const scales_y2Axes_gridLines_drawBorder = $('#scales-y2Axes-gridLines-drawBorder').val();
        const scales_y2Axes_gridLines_drawOnChartArea = $('#scales-y2Axes-gridLines-drawOnChartArea').val();
        const scales_y2Axes_gridLines_drawTicks = $('#scales-y2Axes-gridLines-drawTicks').val();
        const scales_y2Axes_gridLines_tickMarkLength = $('#scales-y2Axes-gridLines-tickMarkLength').val();
        const scales_y2Axes_gridLines_zeroLineWidth = $('#scales-y2Axes-gridLines-zeroLineWidth').val();
        const scales_y2Axes_gridLines_zeroLineColor = $('#scales-y2Axes-gridLines-zeroLineColor').val();
        const scales_y2Axes_gridLines_offsetGridLines = $('#scales-y2Axes-gridLines-offsetGridLines').val();

        //Scales Title Configuration Y2
        const scales_y2Axes_scaleLabel_display = $('#scales-y2Axes-scaleLabel-display').val();
        const scales_y2Axes_scaleLabel_labelString = $('#scales-y2Axes-scaleLabel-labelString').val();
        const scales_y2Axes_scaleLabel_fontColor = $('#scales-y2Axes-scaleLabel-fontColor').val();
        const scales_y2Axes_scaleLabel_fontFamily = $('#scales-y2Axes-scaleLabel-fontFamily').val();
        const scales_y2Axes_scaleLabel_fontSize = $('#scales-y2Axes-scaleLabel-fontSize').val();
        const scales_y2Axes_scaleLabel_fontStyle = $('#scales-y2Axes-scaleLabel-fontStyle').val();

        //Scales Tick Configuration Y2
        const scales_y2Axes_ticks_autoskip = $('#scales-y2Axes-ticks-autoskip').val();
        const scales_y2Axes_ticks_display = $('#scales-y2Axes-ticks-display').val();
        const scales_y2Axes_ticks_fontColor = $('#scales-y2Axes-ticks-fontColor').val();
        const scales_y2Axes_ticks_fontFamily = $('#scales-y2Axes-ticks-fontFamily').val();
        const scales_y2Axes_ticks_fontSize = $('#scales-y2Axes-ticks-fontSize').val();
        const scales_y2Axes_ticks_fontStyle = $('#scales-y2Axes-ticks-fontStyle').val();
        const scales_y2Axes_ticks_maxRotation = $('#scales-y2Axes-ticks-maxRotation').val();
        const scales_y2Axes_ticks_minRotation = $('#scales-y2Axes-ticks-minRotation').val();
        const scales_y2Axes_ticks_mirror = $('#scales-y2Axes-ticks-mirror').val();
        const scales_y2Axes_ticks_padding = $('#scales-y2Axes-ticks-padding').val();
        const scales_y2Axes_ticks_reverse = $('#scales-y2Axes-ticks-reverse').val();
        const scales_y2Axes_ticks_prefix = $('#scales-y2Axes-ticks-prefix').val();
        const scales_y2Axes_ticks_suffix = $('#scales-y2Axes-ticks-suffix').val();
        const scales_y2Axes_ticks_round = $('#scales-y2Axes-ticks-round').val();

        //Scale Configuration Options Y2
        const scales_y2Axes_ticks_min = $('#scales-y2Axes-ticks-min').val();
        const scales_y2Axes_ticks_max = $('#scales-y2Axes-ticks-max').val();
        const scales_y2Axes_ticks_beginAtZero = $('#scales-y2Axes-ticks-beginAtZero').val();
        const scales_y2Axes_ticks_maxTicksLimit = $('#scales-y2Axes-ticks-maxTicksLimit').val();
        const scales_y2Axes_ticks_stepSize = $('#scales-y2Axes-ticks-stepSize').val();
        const scales_y2Axes_ticks_suggestedMax = $('#scales-y2Axes-ticks-suggestedMax').val();
        const scales_y2Axes_ticks_suggestedMin = $('#scales-y2Axes-ticks-suggestedMin').val();

        /* RL Scale Common Configuration */
        const scales_rl_display = $('#scales-rl-display').val();

        /* RL Scale Grid Line Configuration */
        const scales_rl_gridLines_display = $('#scales-rl-gridLines-display').val();
        const scales_rl_gridLines_color = $('#scales-rl-gridLines-color').val();
        const scales_rl_gridLines_lineWidth = $('#scales-rl-gridLines-lineWidth').val();

        /* RL Scale Angle Line Configuration */
        const scales_rl_angleLines_display = $('#scales-rl-angleLines-display').val();
        const scales_rl_angleLines_color = $('#scales-rl-angleLines-color').val();
        const scales_rl_angleLines_lineWidth = $('#scales-rl-angleLines-lineWidth').val();

        /* RL Scale Point Label Configuration */
        const scales_rl_pointLabels_fontSize = $('#scales-rl-pointLabels-fontSize').val();
        const scales_rl_pointLabels_fontColor = $('#scales-rl-pointLabels-fontColor').val();
        const scales_rl_pointLabels_fontFamily = $('#scales-rl-pointLabels-fontFamily').val();
        const scales_rl_pointLabels_fontStyle = $('#scales-rl-pointLabels-fontStyle').val();

        /* RL Scale Tick Configuration */
        const scales_rl_ticks_display = $('#scales-rl-ticks-display').val();
        const scales_rl_ticks_autoskip = $('#scales-rl-ticks-autoskip').val();
        const scales_rl_ticks_reverse = $('#scales-rl-ticks-reverse').val();
        const scales_rl_ticks_prefix = $('#scales-rl-ticks-prefix').val();
        const scales_rl_ticks_suffix = $('#scales-rl-ticks-suffix').val();
        const scales_rl_ticks_round = $('#scales-rl-ticks-round').val();
        const scales_rl_ticks_fontSize = $('#scales-rl-ticks-fontSize').val();
        const scales_rl_ticks_fontColor = $('#scales-rl-ticks-fontColor').val();
        const scales_rl_ticks_fontFamily = $('#scales-rl-ticks-fontFamily').val();
        const scales_rl_ticks_fontStyle = $('#scales-rl-ticks-fontStyle').val();

        /* RL Scale Configuration Options */
        const scales_rl_ticks_min = $('#scales-rl-ticks-min').val();
        const scales_rl_ticks_max = $('#scales-rl-ticks-max').val();
        const scales_rl_ticks_suggestedMin = $('#scales-rl-ticks-suggestedMin').val();
        const scales_rl_ticks_suggestedMax = $('#scales-rl-ticks-suggestedMax').val();
        const scales_rl_ticks_stepSize = $('#scales-rl-ticks-stepSize').val();
        const scales_rl_ticks_maxTicksLimit = $('#scales-rl-ticks-maxTicksLimit').val();
        const scales_rl_ticks_beginAtZero = $('#scales-rl-ticks-beginAtZero').val();
        const scales_rl_ticks_showLabelBackdrop = $('#scales-rl-ticks-showLabelBackdrop').val();
        const scales_rl_ticks_backdropColor = $('#scales-rl-ticks-backdropColor').val();
        const scales_rl_ticks_backdropPaddingX = $('#scales-rl-ticks-backdropPaddingX').val();
        const scales_rl_ticks_backdropPaddingY = $('#scales-rl-ticks-backdropPaddingY').val();

        /* Source */
        const source_type = $('#source-type').val();
        const source_url = $('#source-url').val();
        const source_google_sheets_spreadsheet_id = $('#source-google-sheets-spreadsheet-id').val();

        /* Performance */
        const transient_expiration = $('#transient-expiration').val();


        //save the table data as JSON
        const chart_data = JSON.stringify({data: dauc_hot.getData()});

        //prepare ajax request
        const data = {
            "action": "save_data",
            "security": window.DAEXTDAUC_PARAMETERS.nonce,
            "chart_id": chart_id,
            "name": name,
            "description": description,
            "type": type,
            "rows": rows,
            "columns": columns,
            "is_model": is_model,

            //Common Chart Configuration
            "canvas_transparent_background": canvas_transparent_background,
            "canvas_backgroundColor": canvas_backgroundColor,
            "margin_top": margin_top,
            "margin_bottom": margin_bottom,
            "width": width,
            "height": height,
            "responsive": responsive,
            "responsiveAnimationDuration": responsiveAnimationDuration,
            "maintainAspectRatio": maintainAspectRatio,
            "fixed_height": fixed_height,

            //Title Configuration
            "title_display": title_display,
            "title_position": title_position,
            "title_fullWidth": title_fullWidth,
            "title_fontSize": title_fontSize,
            "title_fontFamily": title_fontFamily,
            "title_fontColor": title_fontColor,
            "title_fontStyle": title_fontStyle,
            "title_padding": title_padding,

            //Legend Configuration
            "legend_display": legend_display,
            "legend_position": legend_position,
            "legend_fullWidth": legend_fullWidth,
            "legend_toggle_dataset": legend_toggle_dataset,

            //Legend Label Configuration
            "legend_labels_boxWidth": legend_labels_boxWidth,
            "legend_labels_fontSize": legend_labels_fontSize,
            "legend_labels_fontStyle": legend_labels_fontStyle,
            "legend_labels_fontColor": legend_labels_fontColor,
            "legend_labels_fontFamily": legend_labels_fontFamily,
            "legend_labels_padding": legend_labels_padding,

            //Tooltip Configuration
            "tooltips_enabled": tooltips_enabled,
            "tooltips_mode": tooltips_mode,
            "tooltips_backgroundColor": tooltips_backgroundColor,
            "tooltips_titleFontFamily": tooltips_titleFontFamily,
            "tooltips_titleFontSize": tooltips_titleFontSize,
            "tooltips_titleFontStyle": tooltips_titleFontStyle,
            "tooltips_titleFontColor": tooltips_titleFontColor,
            "tooltips_titleMarginBottom": tooltips_titleMarginBottom,
            "tooltips_bodyFontFamily": tooltips_bodyFontFamily,
            "tooltips_bodyFontSize": tooltips_bodyFontSize,
            "tooltips_bodyFontStyle": tooltips_bodyFontStyle,
            "tooltips_bodyFontColor": tooltips_bodyFontColor,
            "tooltips_footerFontFamily": tooltips_footerFontFamily,
            "tooltips_footerFontSize": tooltips_footerFontSize,
            "tooltips_footerFontStyle": tooltips_footerFontStyle,
            "tooltips_footerFontColor": tooltips_footerFontColor,
            "tooltips_footerMarginTop": tooltips_footerMarginTop,
            "tooltips_xPadding": tooltips_xPadding,
            "tooltips_yPadding": tooltips_yPadding,
            "tooltips_caretSize": tooltips_caretSize,
            "tooltips_cornerRadius": tooltips_cornerRadius,
            "tooltips_multiKeyBackground": tooltips_multiKeyBackground,
            "tooltips_beforeTitle": tooltips_beforeTitle,
            "tooltips_afterTitle": tooltips_afterTitle,
            "tooltips_beforeBody": tooltips_beforeBody,
            "tooltips_afterBody": tooltips_afterBody,
            "tooltips_beforeLabel": tooltips_beforeLabel,
            "tooltips_afterLabel": tooltips_afterLabel,
            "tooltips_beforeValue": tooltips_beforeValue,
            "tooltips_afterValue": tooltips_afterValue,
            "tooltips_beforeFooter": tooltips_beforeFooter,
            "tooltips_footer": tooltips_footer,
            "tooltips_afterFooter": tooltips_afterFooter,

            //Hover Configuration
            "hover_animationDuration": hover_animationDuration,

            //Animation Configuration
            "animation_duration": animation_duration,
            "animation_easing": animation_easing,
            "animation_instantiation_event": animation_instantiation_event,

            //Misc Configuration
            "elements_rectangle_borderSkipped": elements_rectangle_borderSkipped,
            "half_pie_doughnut": half_pie_doughnut,
            "indexAxis": indexAxis,
            "thousands_separator": thousands_separator,
            "decimal_separator": decimal_separator,

            //Scales Common Configuration X
            scales_xAxes_type: scales_xAxes_type,
            scales_xAxes_display: scales_xAxes_display,
            scales_xAxes_position: scales_xAxes_position,
            scales_xAxes_stacked: scales_xAxes_stacked,

            //Scales Grid Line Configuration X
            scales_xAxes_gridLines_display: scales_xAxes_gridLines_display,
            scales_xAxes_gridLines_color: scales_xAxes_gridLines_color,
            scales_xAxes_gridLines_lineWidth: scales_xAxes_gridLines_lineWidth,
            scales_xAxes_gridLines_drawBorder: scales_xAxes_gridLines_drawBorder,
            scales_xAxes_gridLines_drawOnChartArea: scales_xAxes_gridLines_drawOnChartArea,
            scales_xAxes_gridLines_drawTicks: scales_xAxes_gridLines_drawTicks,
            scales_xAxes_gridLines_tickMarkLength: scales_xAxes_gridLines_tickMarkLength,
            scales_xAxes_gridLines_zeroLineWidth: scales_xAxes_gridLines_zeroLineWidth,
            scales_xAxes_gridLines_zeroLineColor: scales_xAxes_gridLines_zeroLineColor,
            scales_xAxes_gridLines_offsetGridLines: scales_xAxes_gridLines_offsetGridLines,

            //Scales Title Configuration X
            scales_xAxes_scaleLabel_display: scales_xAxes_scaleLabel_display,
            scales_xAxes_scaleLabel_labelString: scales_xAxes_scaleLabel_labelString,
            scales_xAxes_scaleLabel_fontColor: scales_xAxes_scaleLabel_fontColor,
            scales_xAxes_scaleLabel_fontFamily: scales_xAxes_scaleLabel_fontFamily,
            scales_xAxes_scaleLabel_fontSize: scales_xAxes_scaleLabel_fontSize,
            scales_xAxes_scaleLabel_fontStyle: scales_xAxes_scaleLabel_fontStyle,

            //Scales Tick Configuration X
            scales_xAxes_ticks_autoskip: scales_xAxes_ticks_autoskip,
            scales_xAxes_ticks_display: scales_xAxes_ticks_display,
            scales_xAxes_ticks_fontColor: scales_xAxes_ticks_fontColor,
            scales_xAxes_ticks_fontFamily: scales_xAxes_ticks_fontFamily,
            scales_xAxes_ticks_fontSize: scales_xAxes_ticks_fontSize,
            scales_xAxes_ticks_fontStyle: scales_xAxes_ticks_fontStyle,
            scales_xAxes_ticks_labelOffset: scales_xAxes_ticks_labelOffset,
            scales_xAxes_ticks_maxRotation: scales_xAxes_ticks_maxRotation,
            scales_xAxes_ticks_minRotation: scales_xAxes_ticks_minRotation,
            scales_xAxes_ticks_reverse: scales_xAxes_ticks_reverse,
            scales_xAxes_ticks_prefix: scales_xAxes_ticks_prefix,
            scales_xAxes_ticks_suffix: scales_xAxes_ticks_suffix,
            scales_xAxes_ticks_round: scales_xAxes_ticks_round,

            //Scale Configuration Options X
            scales_xAxes_ticks_min: scales_xAxes_ticks_min,
            scales_xAxes_ticks_max: scales_xAxes_ticks_max,
            scales_xAxes_ticks_beginAtZero: scales_xAxes_ticks_beginAtZero,
            scales_xAxes_ticks_maxTicksLimit: scales_xAxes_ticks_maxTicksLimit,
            scales_xAxes_ticks_stepSize: scales_xAxes_ticks_stepSize,
            scales_xAxes_ticks_suggestedMax: scales_xAxes_ticks_suggestedMax,
            scales_xAxes_ticks_suggestedMin: scales_xAxes_ticks_suggestedMin,
            scales_xAxes_categoryPercentage: scales_xAxes_categoryPercentage,
            scales_xAxes_barPercentage: scales_xAxes_barPercentage,

            //Time Scale Configuration Options X
            scales_xAxes_time_format: scales_xAxes_time_format,
            scales_xAxes_time_tooltipFormat: scales_xAxes_time_tooltipFormat,
            scales_xAxes_time_unit_format: scales_xAxes_time_unit_format,
            scales_xAxes_time_unit: scales_xAxes_time_unit,
            scales_xAxes_time_unitStepSize: scales_xAxes_time_unitStepSize,
            scales_xAxes_time_max: scales_xAxes_time_max,
            scales_xAxes_time_min: scales_xAxes_time_min,

            //Scales Common Configuration Y
            scales_yAxes_type: scales_yAxes_type,
            scales_yAxes_display: scales_yAxes_display,
            scales_yAxes_position: scales_yAxes_position,
            scales_yAxes_stacked: scales_yAxes_stacked,

            //Scales Grid Line Configuration Y
            scales_yAxes_gridLines_display: scales_yAxes_gridLines_display,
            scales_yAxes_gridLines_color: scales_yAxes_gridLines_color,
            scales_yAxes_gridLines_lineWidth: scales_yAxes_gridLines_lineWidth,
            scales_yAxes_gridLines_drawBorder: scales_yAxes_gridLines_drawBorder,
            scales_yAxes_gridLines_drawOnChartArea: scales_yAxes_gridLines_drawOnChartArea,
            scales_yAxes_gridLines_drawTicks: scales_yAxes_gridLines_drawTicks,
            scales_yAxes_gridLines_tickMarkLength: scales_yAxes_gridLines_tickMarkLength,
            scales_yAxes_gridLines_zeroLineWidth: scales_yAxes_gridLines_zeroLineWidth,
            scales_yAxes_gridLines_zeroLineColor: scales_yAxes_gridLines_zeroLineColor,
            scales_yAxes_gridLines_offsetGridLines: scales_yAxes_gridLines_offsetGridLines,

            //Scales Title Configuration Y
            scales_yAxes_scaleLabel_display: scales_yAxes_scaleLabel_display,
            scales_yAxes_scaleLabel_labelString: scales_yAxes_scaleLabel_labelString,
            scales_yAxes_scaleLabel_fontColor: scales_yAxes_scaleLabel_fontColor,
            scales_yAxes_scaleLabel_fontFamily: scales_yAxes_scaleLabel_fontFamily,
            scales_yAxes_scaleLabel_fontSize: scales_yAxes_scaleLabel_fontSize,
            scales_yAxes_scaleLabel_fontStyle: scales_yAxes_scaleLabel_fontStyle,

            //Scales Tick Configuration Y
            scales_yAxes_ticks_autoskip: scales_yAxes_ticks_autoskip,
            scales_yAxes_ticks_display: scales_yAxes_ticks_display,
            scales_yAxes_ticks_fontColor: scales_yAxes_ticks_fontColor,
            scales_yAxes_ticks_fontFamily: scales_yAxes_ticks_fontFamily,
            scales_yAxes_ticks_fontSize: scales_yAxes_ticks_fontSize,
            scales_yAxes_ticks_fontStyle: scales_yAxes_ticks_fontStyle,
            scales_yAxes_ticks_maxRotation: scales_yAxes_ticks_maxRotation,
            scales_yAxes_ticks_minRotation: scales_yAxes_ticks_minRotation,
            scales_yAxes_ticks_mirror: scales_yAxes_ticks_mirror,
            scales_yAxes_ticks_padding: scales_yAxes_ticks_padding,
            scales_yAxes_ticks_reverse: scales_yAxes_ticks_reverse,
            scales_yAxes_ticks_prefix: scales_yAxes_ticks_prefix,
            scales_yAxes_ticks_suffix: scales_yAxes_ticks_suffix,
            scales_yAxes_ticks_round: scales_yAxes_ticks_round,

            //Scale Configuration Options Y
            scales_yAxes_ticks_min: scales_yAxes_ticks_min,
            scales_yAxes_ticks_max: scales_yAxes_ticks_max,
            scales_yAxes_ticks_beginAtZero: scales_yAxes_ticks_beginAtZero,
            scales_yAxes_ticks_maxTicksLimit: scales_yAxes_ticks_maxTicksLimit,
            scales_yAxes_ticks_stepSize: scales_yAxes_ticks_stepSize,
            scales_yAxes_ticks_suggestedMax: scales_yAxes_ticks_suggestedMax,
            scales_yAxes_ticks_suggestedMin: scales_yAxes_ticks_suggestedMin,
            scales_yAxes_categoryPercentage: scales_yAxes_categoryPercentage,
            scales_yAxes_barPercentage: scales_yAxes_barPercentage,

            //Scales Common Configuration Y2
            scales_y2Axes_type: scales_y2Axes_type,
            scales_y2Axes_display: scales_y2Axes_display,
            scales_y2Axes_position: scales_y2Axes_position,

            //Scales Grid Line Configuration Y2
            scales_y2Axes_gridLines_display: scales_y2Axes_gridLines_display,
            scales_y2Axes_gridLines_color: scales_y2Axes_gridLines_color,
            scales_y2Axes_gridLines_lineWidth: scales_y2Axes_gridLines_lineWidth,
            scales_y2Axes_gridLines_drawBorder: scales_y2Axes_gridLines_drawBorder,
            scales_y2Axes_gridLines_drawOnChartArea: scales_y2Axes_gridLines_drawOnChartArea,
            scales_y2Axes_gridLines_drawTicks: scales_y2Axes_gridLines_drawTicks,
            scales_y2Axes_gridLines_tickMarkLength: scales_y2Axes_gridLines_tickMarkLength,
            scales_y2Axes_gridLines_zeroLineWidth: scales_y2Axes_gridLines_zeroLineWidth,
            scales_y2Axes_gridLines_zeroLineColor: scales_y2Axes_gridLines_zeroLineColor,
            scales_y2Axes_gridLines_offsetGridLines: scales_y2Axes_gridLines_offsetGridLines,

            //Scales Title Configuration Y2
            scales_y2Axes_scaleLabel_display: scales_y2Axes_scaleLabel_display,
            scales_y2Axes_scaleLabel_labelString: scales_y2Axes_scaleLabel_labelString,
            scales_y2Axes_scaleLabel_fontColor: scales_y2Axes_scaleLabel_fontColor,
            scales_y2Axes_scaleLabel_fontFamily: scales_y2Axes_scaleLabel_fontFamily,
            scales_y2Axes_scaleLabel_fontSize: scales_y2Axes_scaleLabel_fontSize,
            scales_y2Axes_scaleLabel_fontStyle: scales_y2Axes_scaleLabel_fontStyle,

            //Scales Tick Configuration Y2
            scales_y2Axes_ticks_autoskip: scales_y2Axes_ticks_autoskip,
            scales_y2Axes_ticks_display: scales_y2Axes_ticks_display,
            scales_y2Axes_ticks_fontColor: scales_y2Axes_ticks_fontColor,
            scales_y2Axes_ticks_fontFamily: scales_y2Axes_ticks_fontFamily,
            scales_y2Axes_ticks_fontSize: scales_y2Axes_ticks_fontSize,
            scales_y2Axes_ticks_fontStyle: scales_y2Axes_ticks_fontStyle,
            scales_y2Axes_ticks_maxRotation: scales_y2Axes_ticks_maxRotation,
            scales_y2Axes_ticks_minRotation: scales_y2Axes_ticks_minRotation,
            scales_y2Axes_ticks_mirror: scales_y2Axes_ticks_mirror,
            scales_y2Axes_ticks_padding: scales_y2Axes_ticks_padding,
            scales_y2Axes_ticks_reverse: scales_y2Axes_ticks_reverse,
            scales_y2Axes_ticks_prefix: scales_y2Axes_ticks_prefix,
            scales_y2Axes_ticks_suffix: scales_y2Axes_ticks_suffix,
            scales_y2Axes_ticks_round: scales_y2Axes_ticks_round,

            //Scale Configuration Options Y2
            scales_y2Axes_ticks_min: scales_y2Axes_ticks_min,
            scales_y2Axes_ticks_max: scales_y2Axes_ticks_max,
            scales_y2Axes_ticks_beginAtZero: scales_y2Axes_ticks_beginAtZero,
            scales_y2Axes_ticks_maxTicksLimit: scales_y2Axes_ticks_maxTicksLimit,
            scales_y2Axes_ticks_stepSize: scales_y2Axes_ticks_stepSize,
            scales_y2Axes_ticks_suggestedMax: scales_y2Axes_ticks_suggestedMax,
            scales_y2Axes_ticks_suggestedMin: scales_y2Axes_ticks_suggestedMin,

            /* RL Scale Common Configuration */
            scales_rl_display: scales_rl_display,

            /* RL Scale Grid Line Configuration */
            scales_rl_gridLines_display: scales_rl_gridLines_display,
            scales_rl_gridLines_color: scales_rl_gridLines_color,
            scales_rl_gridLines_lineWidth: scales_rl_gridLines_lineWidth,

            /* RL Scale Angle Line Configuration */
            scales_rl_angleLines_display: scales_rl_angleLines_display,
            scales_rl_angleLines_color: scales_rl_angleLines_color,
            scales_rl_angleLines_lineWidth: scales_rl_angleLines_lineWidth,

            /* RL Scale Point Label Configuration */
            scales_rl_pointLabels_fontSize: scales_rl_pointLabels_fontSize,
            scales_rl_pointLabels_fontColor: scales_rl_pointLabels_fontColor,
            scales_rl_pointLabels_fontFamily: scales_rl_pointLabels_fontFamily,
            scales_rl_pointLabels_fontStyle: scales_rl_pointLabels_fontStyle,

            /* RL Scale Tick Configuration */
            scales_rl_ticks_display: scales_rl_ticks_display,
            scales_rl_ticks_autoskip: scales_rl_ticks_autoskip,
            scales_rl_ticks_reverse: scales_rl_ticks_reverse,
            scales_rl_ticks_prefix: scales_rl_ticks_prefix,
            scales_rl_ticks_suffix: scales_rl_ticks_suffix,
            scales_rl_ticks_round: scales_rl_ticks_round,
            scales_rl_ticks_fontSize: scales_rl_ticks_fontSize,
            scales_rl_ticks_fontColor: scales_rl_ticks_fontColor,
            scales_rl_ticks_fontFamily: scales_rl_ticks_fontFamily,
            scales_rl_ticks_fontStyle: scales_rl_ticks_fontStyle,

            /* RL Scale Configuration Options */
            scales_rl_ticks_min: scales_rl_ticks_min,
            scales_rl_ticks_max: scales_rl_ticks_max,
            scales_rl_ticks_suggestedMin: scales_rl_ticks_suggestedMin,
            scales_rl_ticks_suggestedMax: scales_rl_ticks_suggestedMax,
            scales_rl_ticks_stepSize: scales_rl_ticks_stepSize,
            scales_rl_ticks_maxTicksLimit: scales_rl_ticks_maxTicksLimit,
            scales_rl_ticks_beginAtZero: scales_rl_ticks_beginAtZero,
            scales_rl_ticks_showLabelBackdrop: scales_rl_ticks_showLabelBackdrop,
            scales_rl_ticks_backdropColor: scales_rl_ticks_backdropColor,
            scales_rl_ticks_backdropPaddingX: scales_rl_ticks_backdropPaddingX,
            scales_rl_ticks_backdropPaddingY: scales_rl_ticks_backdropPaddingY,

            /* Source */
            source_type: source_type,
            source_url: source_url,
            source_google_sheets_spreadsheet_id: source_google_sheets_spreadsheet_id,

            /* Performance */
            transient_expiration: transient_expiration,

            "chart_data": chart_data

        };

        const validation_result = chart_is_valid(data);
        if(validation_result === true){

            //set ajax in synchronous mode
            jQuery.ajaxSetup({async:false});

            //send ajax request
            $.post(window.DAEXTDAUC_PARAMETERS.ajax_url, data, function(data) {

                if(reload_menu === true){

                    //reload the dashboard menu
                    window.location.replace(window.DAEXTDAUC_PARAMETERS.admin_url + 'admin.php?page=dauc-charts');

                }

            });

            //set ajax in asynchronous mode
            jQuery.ajaxSetup({async:true});

            return true;

        }else{

            return validation_result;

        }

    }

    /*
    Moves the data structure section on the bottom of the chart section when the screen width goes below a specific
    value.
     */
    function responsive_sidebar_container(){

        if( $('#wpcontent').width() < 1528 ){

            $('.sidebar-container').addClass('sidebar-container-below-breakpoint');

        }else{

            $('.sidebar-container').removeClass('sidebar-container-below-breakpoint');

        }

    }

    /**
     * Update the selection of a specific select2 field (field) based on the
     * provided value (selected_value).
     * @param selector
     * @param selected_value
     */
    function update_select2_field(selector, selected_value){

        $(selector).val(selected_value);
        $(selector).select2().trigger('change');

    }

    /*
    Initializes Select2 on all the select elements
     */
    function initialize_select2(){

        //initialize select2 on all the select elements ------------------------
        const select2_elements = [];
        select2_elements.push('#load-model');
        select2_elements.push('#type');
        select2_elements.push('#defaultFontStyle');
        select2_elements.push('#canvas-transparent-background');
        select2_elements.push('#responsive');
        select2_elements.push('#maintainAspectRatio');
        select2_elements.push('#is-model');
        select2_elements.push('#title-display');
        select2_elements.push('#title-position');
        select2_elements.push('#title-fullWidth');
        select2_elements.push('#title-fontStyle');
        select2_elements.push('#legend-display');
        select2_elements.push('#legend-position');
        select2_elements.push('#legend-fullWidth');
        select2_elements.push('#legend-toggle-dataset');
        select2_elements.push('#legend-labels-fontStyle');
        select2_elements.push('#tooltips-enabled');
        select2_elements.push('#tooltips-mode');
        select2_elements.push('#tooltips-titleFontStyle');
        select2_elements.push('#tooltips-bodyFontStyle');
        select2_elements.push('#tooltips-footerFontStyle');
        select2_elements.push('#hover-mode');
        select2_elements.push('#animation-easing');
        select2_elements.push('#animation-instantiation-event');
        select2_elements.push('#defaultFontStyle');
        select2_elements.push('#elements-rectangle-borderSkipped');
        select2_elements.push('#half-pie-doughnut');
        select2_elements.push('#indexAxis');
        select2_elements.push('#elements-line-borderCapStyle');
        select2_elements.push('#elements-line-borderJoinStyle');
        select2_elements.push('#elements-line-capBezierPoints');
        select2_elements.push('#elements-line-fill');
        select2_elements.push('#elements-line-stepped');
        select2_elements.push('#elements-point-pointStyle');
        select2_elements.push('#scales-xAxes-type');
        select2_elements.push('#scales-xAxes-display');
        select2_elements.push('#scales-xAxes-position');
        select2_elements.push('#scales-xAxes-stacked');
        select2_elements.push('#scales-xAxes-gridLines-display');
        select2_elements.push('#scales-xAxes-gridLines-drawBorder');
        select2_elements.push('#scales-xAxes-gridLines-drawOnChartArea');
        select2_elements.push('#scales-xAxes-gridLines-drawTicks');
        select2_elements.push('#scales-xAxes-gridLines-offsetGridLines');
        select2_elements.push('#scales-xAxes-scaleLabel-display');
        select2_elements.push('#scales-xAxes-scaleLabel-fontStyle');
        select2_elements.push('#scales-xAxes-ticks-autoskip');
        select2_elements.push('#scales-xAxes-ticks-display');
        select2_elements.push('#scales-xAxes-ticks-fontStyle');
        select2_elements.push('#scales-xAxes-ticks-reverse');
        select2_elements.push('#scales-xAxes-ticks-beginAtZero');
        select2_elements.push('#scales-xAxes-time-unit');
        select2_elements.push('#scales-yAxes-type');
        select2_elements.push('#scales-yAxes-display');
        select2_elements.push('#scales-yAxes-position');
        select2_elements.push('#scales-yAxes-stacked');
        select2_elements.push('#scales-yAxes-gridLines-display');
        select2_elements.push('#scales-yAxes-gridLines-drawBorder');
        select2_elements.push('#scales-yAxes-gridLines-drawOnChartArea');
        select2_elements.push('#scales-yAxes-gridLines-drawTicks');
        select2_elements.push('#scales-yAxes-gridLines-offsetGridLines');
        select2_elements.push('#scales-yAxes-scaleLabel-display');
        select2_elements.push('#scales-yAxes-scaleLabel-fontStyle');
        select2_elements.push('#scales-yAxes-ticks-autoskip');
        select2_elements.push('#scales-yAxes-ticks-display');
        select2_elements.push('#scales-yAxes-ticks-fontStyle');
        select2_elements.push('#scales-yAxes-ticks-mirror');
        select2_elements.push('#scales-yAxes-ticks-reverse');
        select2_elements.push('#scales-yAxes-ticks-beginAtZero');
        select2_elements.push('#scales-y2Axes-type');
        select2_elements.push('#scales-y2Axes-display');
        select2_elements.push('#scales-y2Axes-position');
        select2_elements.push('#scales-y2Axes-gridLines-display');
        select2_elements.push('#scales-y2Axes-gridLines-drawBorder');
        select2_elements.push('#scales-y2Axes-gridLines-drawOnChartArea');
        select2_elements.push('#scales-y2Axes-gridLines-drawTicks');
        select2_elements.push('#scales-y2Axes-gridLines-offsetGridLines');
        select2_elements.push('#scales-y2Axes-scaleLabel-display');
        select2_elements.push('#scales-y2Axes-scaleLabel-fontStyle');
        select2_elements.push('#scales-y2Axes-ticks-autoskip');
        select2_elements.push('#scales-y2Axes-ticks-display');
        select2_elements.push('#scales-y2Axes-ticks-fontStyle');
        select2_elements.push('#scales-y2Axes-ticks-mirror');
        select2_elements.push('#scales-y2Axes-ticks-reverse');
        select2_elements.push('#scales-y2Axes-ticks-beginAtZero');
        select2_elements.push('#scales-rl-display');
        select2_elements.push('#scales-rl-gridLines-display');
        select2_elements.push('#scales-rl-angleLines-display');
        select2_elements.push('#scales-rl-pointLabels-fontStyle');
        select2_elements.push('#scales-rl-ticks-display');
        select2_elements.push('#scales-rl-ticks-autoskip');
        select2_elements.push('#scales-rl-ticks-reverse');
        select2_elements.push('#scales-rl-ticks-fontStyle');
        select2_elements.push('#scales-rl-ticks-beginAtZero');
        select2_elements.push('#scales-rl-ticks-showLabelBackdrop');
        select2_elements.push('#source-type');
        select2_elements.push('#data-structure-fill');
        select2_elements.push('#data-structure-borderCapStyle');
        select2_elements.push('#data-structure-borderJoinStyle');
        select2_elements.push('#data-structure-showLine');
        select2_elements.push('#data-structure-spanGaps');
        select2_elements.push('#data-structure-plotY2');
        select2_elements.push('#data-structure-hidden');

        jQuery(select2_elements.join(',')).select2();

    }

    /*
    Initialize the handsontable table
     */
    function initialize_handsontable(){

        /*
         If the form is in edit mode retrieve the data of the chart based on the chart id, otherwise initialize an empty
         table.
         */
        if(parseInt($('#update-id').val())>0){

            //prepare ajax request
            const data = {
                "action": "retrieve_chart_data",
                "security": window.DAEXTDAUC_PARAMETERS.nonce,
                "chart_id": $('#update-id').val()
            };

            //set ajax in synchronous mode
            jQuery.ajaxSetup({async:false});

            //send ajax request
            $.post(window.DAEXTDAUC_PARAMETERS.ajax_url, data, function(data_json) {

                //initialize the table with the retrieved data
                const data_obj = JSON.parse(data_json);

                $.each(data_obj, function( index, value ) {
                    dauc_data.push(value);
                });

                dauc_max_rows = parseInt($('#rows').val(), 10) + 1;
                dauc_max_columns = parseInt($('#columns').val(), 10);

            });

            //set ajax in asynchronous mode
            jQuery.ajaxSetup({async:true});

        }else{

            //initialize an empty table
            dauc_data = [
                ['Label 1','Label 2','Label 3','Label 4','Label 5','Label 6','Label 7','Label 8','Label 9','Label 10'],
                ['0','0','0','0','0','0','0','0','0','0'],
                ['0','0','0','0','0','0','0','0','0','0'],
                ['0','0','0','0','0','0','0','0','0','0'],
                ['0','0','0','0','0','0','0','0','0','0'],
                ['0','0','0','0','0','0','0','0','0','0'],
                ['0','0','0','0','0','0','0','0','0','0'],
                ['0','0','0','0','0','0','0','0','0','0'],
                ['0','0','0','0','0','0','0','0','0','0'],
                ['0','0','0','0','0','0','0','0','0','0'],
                ['0','0','0','0','0','0','0','0','0','0']
            ];

            dauc_max_rows = 11;
            dauc_max_columns = 10;

        }

        //Instantiate the handsontable table
        const dauc_container = document.getElementById('dauc-table');
        dauc_hot = new Handsontable(dauc_container,
            {

                afterSelectionEnd: function(start_row_index) {
                    if(start_row_index > 0){
                        display_data_structure(start_row_index);
                    }
                },

                data: dauc_data,

                //set the new maximum number of rows and columns
                maxRows: dauc_max_rows,
                maxCols: dauc_max_columns,

                //Do not allow to add more than 20 characters. If more than 20 characters
                //are added, the text is truncated.
                validator: function (value, callback) {
                    if (value.length > 20) {
                        this.instance.setDataAtCell(this.row, this.col, value.substring(0, 20), null);
                    }
                    callback(true);
                }

            });


        /*
         Set table in read-only mode if the table is disabled.
         While in read-only mode the table style is also changed.
         */
        if( parseInt( $('#dauc-table').attr('data-disabled'), 10) == 1 ){

            dauc_hot.updateSettings({
                readOnly: true,
                contextMenu: false
            });

            $('#dauc-table td').css('background', '#f7f7f7').css('color', '#ccc');

        }

    }

    /*
     Disables ctrl+z
     The reason why this function is useful is that clicking ctrl+z while editing the handsontable generates problems.
     */
    function disable_ctrl_z(){

        $("body").keydown(function(e){
            const zKey = 90;
            if ((e.ctrlKey || e.metaKey) && e.keyCode == zKey) {
                e.preventDefault();
                return false;
            }
        });

    }

});