/**
 * Partials for the Chart.js configuration.
 */
window.daextdaucConfigPartials = {

  /**
   * Applies the title configuration.
   *
   * See: https://www.chartjs.org/docs/latest/configuration/title.html
   *
   * @param chart
   * @returns {{}}
   */
  addTitleConfiguration: function(currentConfig, chart) {

    'use strict';

    currentConfig.plugins = {
      title: {
        display: daextdaucUtility.booleanString(chart.title_display),
        text: chart.name,
        position: chart.title_position,
        fullSize: daextdaucUtility.booleanString(chart.title_fullWidth),
        font: {
          size: parseInt(chart.title_fontSize, 10),
          family: chart.title_fontFamily,
          style: chart.title_fontStyle,
        },
        color: chart.title_fontColor,
        padding: parseInt(chart.title_padding, 10),
      }
    };

    return currentConfig;

  },

  /**
   * Applies the configuration required for the horizontal bar chart.
   *
   * See: https://www.chartjs.org/docs/latest/charts/bar.html#horizontal-bar-chart
   *
   * @param chart
   * @returns {{}}
   */
  addHorizontalBarConfiguration: function(currentConfig, chart){

    'use strict';

    if(chart.type === 'bar' && chart.indexAxis === 'y') {

      currentConfig = Object.assign(currentConfig,
          {
            indexAxis: 'y',
          },
      );

    }

    return currentConfig;

  },

  /**
   * Display an half Pie/Doughnut if enabled with the Half Pie/Doughnut option.
   *
   * @param chart
   * @returns {{}}
   */
  addHalfPieConfiguration: function(currentConfig, chart) {

    'use strict';

    if ((chart.type == 'pie' || chart.type == 'doughnut') &&
        parseInt(chart.half_pie_doughnut, 10) === 1) {

      currentConfig.rotation = 270;
      currentConfig.circumference = 180;

      return currentConfig;

    } else {

      return currentConfig;

    }

  },

  /**
   * Add Common configuration.
   *
   * @param currentConfig
   * @param chart
   * @returns {any}
   */
  addCommonConfiguration: function(currentConfig, chart) {

    'use strict';

    //Common Chart Configuration
    if ((typeof window.DAEXTDAUC_ISPREVIEW !== 'undefined')) {
      currentConfig.responsive = true;
      currentConfig.maintainAspectRatio = true;
    } else {
      currentConfig.responsive = daextdaucUtility.booleanString(chart.responsive);
      currentConfig.maintainAspectRatio = daextdaucUtility.booleanString(
          chart.maintainAspectRatio);
    }

    //Animation Configuration
    currentConfig.animation = {};
    currentConfig.animation.duration = parseInt(
        chart.animation_duration, 10);
    currentConfig.animation.easing = chart.animation_easing;
    currentConfig.transitions = {
      resize: {
        animation: {
          duration: parseInt(chart.responsiveAnimationDuration, 10)
        }
      }
    };

    return currentConfig;

  },

  /**
   * Add the legend configuration.
   *
   * @param currentConfig
   * @param chart
   * @returns {any}
   */
  addLegendConfiguration: function(currentConfig, chart){

    'use strict';

    currentConfig.plugins = Object.assign(currentConfig.plugins,
        {
          legend: {
            display: daextdaucUtility.booleanString(chart.legend_display),
            position: chart.legend_position,
            fullSize: daextdaucUtility.booleanString(chart.legend_fullWidth),
            labels: {
              boxWidth: parseInt(chart.legend_labels_boxWidth, 10),
              padding: parseInt(chart.legend_labels_padding, 10),
              color: chart.legend_labels_fontColor,
              font: {
                size: parseInt(chart.legend_labels_fontSize, 10),
                style: chart.legend_labels_fontStyle,
                family: chart.legend_labels_fontFamily,
              },
            }
          },
        },
    );

    //Make the legend clickable or disabled
    if (parseInt(chart.legend_toggle_dataset, 10) === 0) {

      currentConfig.plugins.legend = Object.assign(currentConfig.plugins.legend,
          {
            onClick: function () {
              return;
            },
          },
      );

    }

    return currentConfig;

  },

  /**
   * Add the tooltips configuration.
   *
   * @param currentConfig
   * @param chart
   * @returns {any}
   */
  addTooltipsConfiguration: function(currentConfig, chart) {

    'use strict';

    let callbacks = {};

    if (chart.tooltips_beforeTitle.trim().length > 0) {
      callbacks = Object.assign(callbacks, {
        beforeTitle: function() {
          return chart.tooltips_beforeTitle;
        },
      });
    }

    if (chart.tooltips_afterTitle.trim().length > 0) {
      callbacks = Object.assign(callbacks, {
        afterTitle: function() {
          return chart.tooltips_afterTitle;
        },
      });
    }

    if (chart.tooltips_beforeBody.trim().length > 0) {
      callbacks = Object.assign(callbacks, {
        beforeBody: function() {
          return chart.tooltips_beforeBody;
        },
      });
    }

    if (chart.tooltips_afterBody.trim().length > 0) {
      callbacks = Object.assign(callbacks, {
        afterBody: function() {
          return chart.tooltips_afterBody;
        },
      });
    }

    if (chart.tooltips_beforeLabel.trim().length > 0) {
      callbacks = Object.assign(callbacks, {
        beforeLabel: function() {
          return chart.tooltips_beforeLabel;
        },
      });
    }

    if (chart.tooltips_afterLabel.trim().length > 0) {
      callbacks = Object.assign(callbacks, {
        afterLabel: function() {
          return chart.tooltips_afterLabel;
        },
      });
    }

    callbacks = Object.assign(callbacks, {
      label: function(tooltipItems, data) {

        'use strict';

        let value = null;

        switch (chart.type) {

          case 'bar':

            if(chart.indexAxis === 'y'){

              //Horizontal Bar
              value = daextdaucUtility.formatValue(chart,
                  tooltipItems.parsed.x);
              return tooltipItems.dataset.label + ': ' +
                  chart.tooltips_beforeValue + value + chart.tooltips_afterValue;

            }else{

              //Bar
              value = daextdaucUtility.formatValue(chart, tooltipItems.parsed.y);
              return tooltipItems.dataset.label + ': ' +
                  chart.tooltips_beforeValue + value + chart.tooltips_afterValue;

            }

            break;

          case 'polarArea':

            value = daextdaucUtility.formatValue(chart, tooltipItems.parsed.r);
            return tooltipItems.label + ': ' +
                chart.tooltips_beforeValue + value + chart.tooltips_afterValue;

            break;

          case 'doughnut':
          case 'pie':

            value = daextdaucUtility.formatValue(chart,
                tooltipItems.parsed);
            return tooltipItems.label + ': ' +
                chart.tooltips_beforeValue + value + chart.tooltips_afterValue;

            break;

          case 'bubble':

            const valueX = daextdaucUtility.formatValue(chart,
                tooltipItems.dataset.data[tooltipItems.dataIndex].x);
            const valueY = daextdaucUtility.formatValue(chart,
                tooltipItems.dataset.data[tooltipItems.dataIndex].y);
            const valueR = daextdaucUtility.formatValue(chart,
                tooltipItems.dataset.data[tooltipItems.dataIndex].r);
            return tooltipItems.dataset.label + ': ' +
                chart.tooltips_beforeValue + '(' + valueX + ', ' + valueY +
                ', ' + valueR + ')' + chart.tooltips_afterValue;

            break;

          case 'radar':

            value = daextdaucUtility.formatValue(chart, tooltipItems.parsed.r);
            return tooltipItems.dataset.label + ': ' +
                chart.tooltips_beforeValue + value + chart.tooltips_afterValue;

            break;

          default:

            value = daextdaucUtility.formatValue(chart, tooltipItems.parsed.y);
            return tooltipItems.dataset.label + ': ' +
                chart.tooltips_beforeValue + value + chart.tooltips_afterValue;

            break;

        }

      },
    });

    if (chart.tooltips_beforeFooter.trim().length > 0) {

      callbacks = Object.assign(callbacks, {
        beforeFooter: function() {

          'use strict';

          return chart.tooltips_beforeFooter;

        },
      });

    }

    if (chart.tooltips_footer.trim().length > 0) {

      callbacks = Object.assign(callbacks, {
        footer: function() {

          'use strict';

          return chart.tooltips_footer;

        },
      });

    }

    if (chart.tooltips_afterFooter.trim().length > 0) {

      callbacks = Object.assign(callbacks, {
        afterFooter: function() {

          'use strict';

          return chart.tooltips_afterFooter;

        },
      });

    }

    currentConfig.plugins = Object.assign(currentConfig.plugins,
        {
          tooltip: {
            callbacks: callbacks,
            enabled: daextdaucUtility.booleanString(chart.tooltips_enabled),
            mode: chart.tooltips_mode,
            backgroundColor: chart.tooltips_backgroundColor,
            titleFont: {
              family: chart.tooltips_titleFontFamily,
              size: parseInt(chart.tooltips_titleFontSize, 10),
              style: chart.tooltips_titleFontStyle
            },
            titleColor: chart.tooltips_titleFontColor,
            titleMarginBottom: parseInt(chart.tooltips_titleMarginBottom, 10),
            bodyFont: {
              family: chart.tooltips_bodyFontFamily,
              size: parseInt(chart.tooltips_bodyFontSize, 10),
              style: chart.tooltips_bodyFontStyle
            },
            bodyColor: chart.tooltips_bodyFontColor,
            footerFont: {
              family: chart.tooltips_footerFontFamily,
              size: parseInt(chart.tooltips_footerFontSize, 10),
              style: chart.tooltips_footerFontStyle
            },
            footerColor: chart.tooltips_footerFontColor,
            footerMarginTop: parseInt(chart.tooltips_footerMarginTop, 10),
            padding: {
              left: parseInt(chart.tooltips_xPadding, 10),
              right: parseInt(chart.tooltips_xPadding, 10),
              top: parseInt(chart.tooltips_yPadding, 10),
              bottom: parseInt(chart.tooltips_yPadding, 10),
            },
            caretSize: parseInt(chart.tooltips_caretSize, 10),
            cornerRadius: parseInt(chart.tooltips_cornerRadius, 10),
            animation: {
              duration: parseInt(chart.hover_animationDuration, 10)
            },
            multiKeyBackground: chart.tooltips_multiKeyBackground,
            displayColors: false
          }
        }
    );

    return currentConfig;

  },

  /**
   * Set the side of the skipped border based on the dedicated option. Note that
   * this settings affects the bar and horizontalBar charts.
   *
   * @param currentConfig
   * @param chart
   */
  addElementsConfiguration: function (currentConfig, chart){

    'use strict';

    if (chart.type == 'bar') {

      return Object.assign(currentConfig, {
        elements: {
          bar: {
            borderSkipped: chart.elements_rectangle_borderSkipped,
          },
        },
      });

    }else{

      return currentConfig;

    }

  },

  /**
   * Add the settings for the radial scale.
   *
   * @param currentConfig
   * @param chart
   * @returns {any}
   */
  generateScaleRAxis: function(chart){

    'use strict';

    let config = {};

    if ((chart.type == 'radar' || chart.type == 'polarArea') &&
    parseInt(chart.scales_rl_display, 10) === 1) {

      //RL Scale Common
      config.display = true;

      //R Scale Grid Line
      config.grid = {
        display: daextdaucUtility.booleanString(
            chart.scales_rl_gridLines_display),
        color: daextdaucUtility.outputColor(
            chart.scales_rl_gridLines_color, chart.type,
            'scales_rl_gridLines_color'),
        lineWidth: daextdaucUtility.outputNumber(
            chart.scales_rl_gridLines_lineWidth, chart.type,
            'scales_rl_gridLines_lineWidth'),
      };

      //RL Scale Angle Line
      config.angleLines = {
        display: daextdaucUtility.booleanString(
            chart.scales_rl_angleLines_display),
        color: daextdaucUtility.outputColor(
            chart.scales_rl_angleLines_color, chart.type,
            'scales_rl_angleLines_color'),
        lineWidth: daextdaucUtility.outputNumber(
            chart.scales_rl_angleLines_lineWidth, chart.type,
            'scales_rl_angleLines_lineWidth'),
      };

      //RL Scale Point Label
      config.pointLabels = {
        font: {
          size: parseInt(chart.scales_rl_pointLabels_fontSize, 10),
          family: chart.scales_rl_pointLabels_fontFamily,
          style: chart.scales_rl_pointLabels_fontStyle,
        },
        color: daextdaucUtility.outputColor(
            chart.scales_rl_pointLabels_fontColor, chart.type,
            'scales_rl_pointLabels_fontColor'),
      };

      //RL Scale Tick
      config.reverse = daextdaucUtility.booleanString(
          chart.scales_rl_ticks_reverse),
          config.ticks = {

            display: daextdaucUtility.booleanString(
                chart.scales_rl_ticks_display),
            autoskip: daextdaucUtility.booleanString(
                chart.scales_rl_ticks_autoskip),
            font: {
              size: parseInt(chart.scales_rl_ticks_fontSize, 10),
              family: chart.scales_rl_ticks_fontFamily,
              style: chart.scales_rl_ticks_fontStyle,
            },
            color: daextdaucUtility.outputColor(
                chart.scales_rl_ticks_fontColor, chart.type,
                'scales_rl_ticks_fontColor')
          };

      //RL Scale Options (specific for the radial linear scale)
      if (chart.scales_rl_ticks_min.trim().length > 0) {
        config.min = chart.scales_rl_ticks_min;
      }
      if (chart.scales_rl_ticks_max.trim().length > 0) {
        config.max = parseFloat(chart.scales_rl_ticks_max);
      }
      if (chart.scales_rl_ticks_suggestedMin.trim().length) {
        config.suggestedMin = parseFloat(
            chart.scales_rl_ticks_suggestedMin);
      }
      if (chart.scales_rl_ticks_suggestedMax.trim().length > 0) {
        config.suggestedMax = parseFloat(
            chart.scales_rl_ticks_suggestedMax);
      }
      if (chart.scales_rl_ticks_stepSize.trim().length > 0) {
        config.ticks.stepSize = parseFloat(chart.scales_rl_ticks_stepSize);
      }
      if (chart.scales_rl_ticks_maxTicksLimit.trim().length > 0) {
        config.ticks.maxTicksLimit = parseInt(
            chart.scales_rl_ticks_maxTicksLimit, 10);
      }
      config.ticks.showLabelBackdrop = daextdaucUtility.booleanString(
          chart.scales_rl_ticks_showLabelBackdrop);
      config.ticks.backdropColor = daextdaucUtility.outputColor(
          chart.scales_rl_ticks_backdropColor, chart.type,
          'scales_rl_ticks_backdropColor');
      config.ticks.backdropPadding = {
        x: parseInt(chart.scales_rl_ticks_backdropPaddingX, 10),
        y: parseInt(chart.scales_rl_ticks_backdropPaddingY, 10)
      };

      config.ticks.callback = function(tick) {

        'use strict';

        let tick_output = null;

        if (chart.scales_rl_ticks_round.trim().length > 0) {
          tick_output = tick.toFixed(
              parseInt(chart.scales_rl_ticks_round, 10)).toString();
        } else {
          tick_output = tick.toString();
        }

        tick_output = daextdaucUtility.formatValue(chart, tick_output);

        return chart.scales_rl_ticks_prefix + tick_output +
            chart.scales_rl_ticks_suffix;

      };

      if(chart.type === 'radar'){

        config.beginAtZero = daextdaucUtility.booleanString(
            chart.scales_rl_ticks_beginAtZero);

      }

    }else{

      config.display = false;

    }

    return config;

  },

  /**
   * Add the settings for the scale of the X axis.
   *
   * @param chart
   * @returns {{}}
   */
  generateScaleXAxis: function(chart){

    'use strict';

    let config = {};

    //scales_xAxes_display
    if (parseInt(chart.scales_xAxes_display, 10)) {

      config.display = true;

      //scales_xAxes_type
      config.type = chart.scales_xAxes_type;

      //scales_xAxes_position
      config.position = chart.scales_xAxes_position;

      //scales_xAxes_stacked
      config.stacked = daextdaucUtility.booleanString(
          chart.scales_xAxes_stacked);

      //Scale Grid Line config scales_xAxes_gridLines -----------------------------
      config.grid = {
        display: daextdaucUtility.booleanString(
            chart.scales_xAxes_gridLines_display),
        
        //Scriptable option
        color: function (context) {
          if (context.index === 0) {
            return daextdaucUtility.outputColor(
                chart.scales_xAxes_gridLines_zeroLineColor, chart.type,
                'scales_xAxes_gridLines_zeroLineColor');
          } else {
            return daextdaucUtility.outputColor(
                chart.scales_xAxes_gridLines_color, chart.type,
                'scales_xAxes_gridLines_color');
          }
        },

        //Scriptable option
        lineWidth: function (context) {
          if (context.index === 0) {
            return parseInt(
                chart.scales_xAxes_gridLines_zeroLineWidth, 10);
          } else {
            return daextdaucUtility.outputNumber(
                chart.scales_xAxes_gridLines_lineWidth, chart.type,
                'scales_xAxes_gridLines_lineWidth');
          }
        },

        drawBorder: daextdaucUtility.booleanString(
            chart.scales_xAxes_gridLines_drawBorder),
        drawOnChartArea: daextdaucUtility.booleanString(
            chart.scales_xAxes_gridLines_drawOnChartArea),
        drawTicks: daextdaucUtility.booleanString(
            chart.scales_xAxes_gridLines_drawTicks),
        tickLength: parseInt(
            chart.scales_xAxes_gridLines_tickMarkLength, 10),
        offset: daextdaucUtility.booleanString(
            chart.scales_xAxes_gridLines_offsetGridLines),
      };

      //Scale Title config scales_xAxes_scaleLabel --------------------------------
      config.title = {
        display: daextdaucUtility.booleanString(chart.scales_xAxes_scaleLabel_display),
        text: chart.scales_xAxes_scaleLabel_labelString,
        font: {
          size: parseInt(chart.scales_xAxes_scaleLabel_fontSize, 10),
          family: chart.scales_xAxes_scaleLabel_fontFamily,
          style: chart.scales_xAxes_scaleLabel_fontStyle,
        },
        color: daextdaucUtility.outputColor(
            chart.scales_xAxes_scaleLabel_fontColor, chart.type,
            'scales_xAxes_scaleLabel_fontColor'),
      };

      //Scale Tick config scales_xAxes_ticks --------------------------------------
      config.ticks = {};

      /**
       * If there is a logarithmic scale active this function is used to display the real
       * value on the xAxis.
       * Note that this function with this specific content should be used only with the
       * logarithmic scale. Other versions of this function might be used to customize the
       * string representation of the tick value
       */
      switch(chart.scales_xAxes_type){

        case 'logarithmic':

          config.ticks.callback = function(tick) {

            'use strict';

            let tick_output = null;
            const remain = tick /
                (Math.pow(10, Math.floor(Chart.helpers.log10(tick))));

            //this determines how many ticks are shown
            if (remain === 1 || remain === 2 || remain === 5) {

              if (chart.scales_xAxes_ticks_round.trim().length > 0) {
                tick_output = tick.toFixed(
                    parseInt(chart.scales_xAxes_ticks_round, 10)).
                    toString();

              } else {
                tick_output = tick.toString();

              }

              tick_output = daextdaucUtility.formatValue(chart,
                  tick_output);

              return chart.scales_xAxes_ticks_prefix + tick_output +
                  chart.scales_xAxes_ticks_suffix;

            }

            return '';

          };

          break;

        case 'category':

          //do nothing

          break;

        default:

          config.ticks.callback = function(tick) {

            let tick_output = null;

            if (chart.scales_xAxes_type == 'linear') {

              if (chart.scales_xAxes_ticks_round.trim().length > 0) {
                tick_output = tick.toFixed(
                    parseInt(chart.scales_xAxes_ticks_round, 10)).
                    toString();

              } else {
                tick_output = tick.toString();

              }

              tick_output = daextdaucUtility.formatValue(chart,
                  tick_output);

            } else {
              tick_output = tick.toString();
            }

            return chart.scales_xAxes_ticks_prefix + tick_output +
                chart.scales_xAxes_ticks_suffix;

          };

          break;

      }

      //Scale Tick config -----------------------------------------------------
      config.ticks.autoSkip = daextdaucUtility.booleanString(
          chart.scales_xAxes_ticks_autoskip);
      config.ticks.display = daextdaucUtility.booleanString(
          chart.scales_xAxes_ticks_display);
      config.ticks.font = {
        size: parseInt(chart.scales_xAxes_ticks_fontSize, 10),
        family: chart.scales_xAxes_ticks_fontFamily,
        style: chart.scales_xAxes_ticks_fontStyle,
      },
          config.ticks.color = daextdaucUtility.outputColor(
              chart.scales_xAxes_ticks_fontColor, chart.type,
              'scales_xAxes_ticks_fontColor'),
      config.ticks.labelOffset = parseInt(
          chart.scales_xAxes_ticks_labelOffset, 10);
      config.ticks.maxRotation = parseInt(
          chart.scales_xAxes_ticks_maxRotation, 10);
      config.ticks.minRotation = parseInt(
          chart.scales_xAxes_ticks_minRotation, 10);
      config.reverse = daextdaucUtility.booleanString(
          chart.scales_xAxes_ticks_reverse);

      //Scale config Options --------------------------------------------------
      if (chart.scales_xAxes_ticks_min.trim().length > 0) {
        config.min = parseFloat(chart.scales_xAxes_ticks_min);
      }
      if (chart.scales_xAxes_ticks_max.trim().length > 0) {
        config.max = parseFloat(chart.scales_xAxes_ticks_max);
      }

      //Scale Linear config Options -------------------------------------------
      if (chart.scales_xAxes_type == 'linear') {

        config.beginAtZero = daextdaucUtility.booleanString(
            chart.scales_xAxes_ticks_beginAtZero);
        if (chart.scales_xAxes_ticks_maxTicksLimit.trim().length > 0) {
          config.ticks.maxTicksLimit = parseInt(
              chart.scales_xAxes_ticks_maxTicksLimit, 10);
        }
        if (chart.scales_xAxes_ticks_stepSize.trim().length > 0) {
          config.ticks.stepSize = parseFloat(
              chart.scales_xAxes_ticks_stepSize);
        }
        if (chart.scales_xAxes_ticks_suggestedMax.trim().length > 0) {
          config.suggestedMax = parseFloat(
              chart.scales_xAxes_ticks_suggestedMax);
        }
        if (chart.scales_xAxes_ticks_suggestedMin.trim().length > 0) {
          config.suggestedMin = parseFloat(
              chart.scales_xAxes_ticks_suggestedMin);
        }

      }

      //Scale Time config Options ------------------------------------------------------
      if (chart.scales_xAxes_type == 'time') {

        config.time = {};

        config.time.parser = chart.scales_xAxes_time_format;
        config.time.tooltipFormat = chart.scales_xAxes_time_tooltipFormat;

        if (chart.scales_xAxes_time_max.trim().length > 0) {
          config.max = chart.scales_xAxes_time_max;
        }

        if (chart.scales_xAxes_time_min.trim().length > 0) {
          config.min = chart.scales_xAxes_time_min;
        }

        config.time.displayFormats = {
          [chart.scales_xAxes_time_unit]: chart.scales_xAxes_time_unit_format
        };

        config.time.unit = chart.scales_xAxes_time_unit;
        config.time.stepSize = parseFloat(chart.scales_xAxes_time_unitStepSize);

      }

    } else {

      config.display = false;

    }

    return config;

  },

  /**
   * Add the settings for the scale of the Y Axis.
   *
   * @param chart
   * @returns {{}}
   */
  generateScaleYAxis: function(chart){

    'use strict';

    const config = {};

    if (parseInt(chart.scales_yAxes_display, 10) === 1) {

      config.display = true;

      //scales_yAxes_type
      config.type = chart.scales_yAxes_type;

      //scales_yAxes_position
      config.position = chart.scales_yAxes_position;

      //scales_yAxes_stacked
      config.stacked = daextdaucUtility.booleanString(
          chart.scales_yAxes_stacked);//default: false

      //Scale Grid Line Configuration scales_yAxes_gridLines -----------------------------
      config.grid = {
        display: daextdaucUtility.booleanString(
            chart.scales_yAxes_gridLines_display),

        //Scriptable option
        color: function (context) {
          if (context.index === 0) {
            return daextdaucUtility.outputColor(
                chart.scales_yAxes_gridLines_zeroLineColor, chart.type,
                'scales_yAxes_gridLines_zeroLineColor');
          } else {
            return daextdaucUtility.outputColor(
                chart.scales_yAxes_gridLines_color, chart.type,
                'scales_yAxes_gridLines_color');
          }
        },

        //Scriptable option
        lineWidth: function (context) {
          if (context.index === 0) {
            return parseInt(
                chart.scales_yAxes_gridLines_zeroLineWidth, 10);
          } else {
            return daextdaucUtility.outputNumber(
                chart.scales_yAxes_gridLines_lineWidth, chart.type,
                'scales_yAxes_gridLines_lineWidth');
          }
        },
        
        drawBorder: daextdaucUtility.booleanString(
            chart.scales_yAxes_gridLines_drawBorder),
        drawOnChartArea: daextdaucUtility.booleanString(
            chart.scales_yAxes_gridLines_drawOnChartArea),
        drawTicks: daextdaucUtility.booleanString(
            chart.scales_yAxes_gridLines_drawTicks),
        tickLength: parseInt(
            chart.scales_yAxes_gridLines_tickMarkLength, 10),
        offset: daextdaucUtility.booleanString(
            chart.scales_yAxes_gridLines_offsetGridLines),
      };

      //Scale Title Configuration scales_yAxes_scaleLabel --------------------------------
      config.title = {
        display: daextdaucUtility.booleanString(chart.scales_yAxes_scaleLabel_display),
        text: chart.scales_yAxes_scaleLabel_labelString,
        font: {
          size: parseInt(chart.scales_yAxes_scaleLabel_fontSize, 10),
          family: chart.scales_yAxes_scaleLabel_fontFamily,
          style: chart.scales_yAxes_scaleLabel_fontStyle,
        },
        color: daextdaucUtility.outputColor(
            chart.scales_yAxes_scaleLabel_fontColor, chart.type,
            'scales_yAxes_scaleLabel_fontColor'),
      };

      //Scale Tick Configuration scales_yAxes_ticks --------------------------------------
      config.ticks = {};

      /**
       * If there is a logarithmic scale active this function is used to display the real
       * value on the yAxis.
       * Note that this function with this specific content should be used only with the
       * logarithmic scales. Other versions of this function might be used to customize the
       * string representation of the tick value.
       */
      switch(chart.scales_yAxes_type){

        case 'logarithmic':

          config.ticks.callback = function(tick) {

            let tick_output = null;

            const remain = tick /
                (Math.pow(10, Math.floor(Chart.helpers.log10(tick))));

            //this determines how many ticks are shown
            if (remain === 1 || remain === 2 || remain === 5) {

              if (chart.scales_yAxes_ticks_round.trim().length > 0) {
                tick_output = tick.toFixed(
                    parseInt(chart.scales_yAxes_ticks_round, 10)).
                toString();

              } else {
                tick_output = tick.toString();

              }

              tick_output = daextdaucUtility.formatValue(chart,
                  tick_output);

              return chart.scales_yAxes_ticks_prefix + tick_output +
                  chart.scales_yAxes_ticks_suffix;

            }

            return '';

          };

          break;

        case 'category':

          //do nothing
          break;

        default:

          config.ticks.callback = function(tick) {

            'use strict';

            let tick_output;

            if (chart.scales_yAxes_type == 'linear') {
              if (chart.scales_yAxes_ticks_round.trim().length > 0) {
                tick_output = tick.toFixed(
                    parseInt(chart.scales_yAxes_ticks_round, 10)).
                toString();

              } else {
                tick_output = tick.toString();
              }
              tick_output = daextdaucUtility.formatValue(chart,
                  tick_output);
            } else {
              tick_output = tick.toString();
            }

            return chart.scales_yAxes_ticks_prefix + tick_output +
                chart.scales_yAxes_ticks_suffix;

          };

          break;

      }

      //Scale Tick Configuration -----------------------------------------------------
      config.ticks.autoSkip = daextdaucUtility.booleanString(
          chart.scales_yAxes_ticks_autoskip);
      config.ticks.display = daextdaucUtility.booleanString(
          chart.scales_yAxes_ticks_display);
      config.ticks.font = {
        size: parseInt(
            chart.scales_yAxes_ticks_fontSize, 10),
            family: chart.scales_yAxes_ticks_fontFamily,
            style: chart.scales_yAxes_ticks_fontStyle,
      },
          config.ticks.color = daextdaucUtility.outputColor(
          chart.scales_yAxes_ticks_fontColor, chart.type,
          'scales_yAxes_ticks_fontColor'),
      config.ticks.maxRotation = parseInt(
          chart.scales_yAxes_ticks_maxRotation, 10);
      config.ticks.minRotation = parseInt(
          chart.scales_yAxes_ticks_minRotation, 10);
      config.ticks.mirror = daextdaucUtility.booleanString(
          chart.scales_yAxes_ticks_mirror);
      config.ticks.padding = parseInt(
          chart.scales_yAxes_ticks_padding, 10);
      config.reverse = daextdaucUtility.booleanString(
          chart.scales_yAxes_ticks_reverse);

      //Scale Configuration Options --------------------------------------------------
      if (chart.scales_yAxes_ticks_min.trim().length > 0) {
        config.min = parseInt(
            chart.scales_yAxes_ticks_min);
      }
      if (chart.scales_yAxes_ticks_max.trim().length > 0) {
        config.max = parseInt(
            chart.scales_yAxes_ticks_max);
      }

      //Scale Linear Configuration Options -------------------------------------------
      if (chart.scales_yAxes_type == 'linear') {

        config.beginAtZero = daextdaucUtility.booleanString(
            chart.scales_yAxes_ticks_beginAtZero);

        if (chart.scales_yAxes_ticks_maxTicksLimit.trim().length > 0) {
          config.ticks.maxTicksLimit = parseInt(
              chart.scales_yAxes_ticks_maxTicksLimit, 10);
        }

        if (chart.scales_yAxes_ticks_stepSize.trim().length > 0) {
          config.ticks.stepSize = parseFloat(
              chart.scales_yAxes_ticks_stepSize);
        }

        if (chart.scales_yAxes_ticks_suggestedMax.trim().length > 0) {
          config.suggestedMax = parseFloat(
              chart.scales_yAxes_ticks_suggestedMax);
        }

        if (chart.scales_yAxes_ticks_suggestedMin.trim().length > 0) {
          config.suggestedMin = parseFloat(
              chart.scales_yAxes_ticks_suggestedMin);
        }

      }

    } else {

      config.display = false;

    }

    return config;

  },

  /**
   * Add the settings for the scale of the Y2 axis.
   *
   * @param chart
   * @returns {{}}
   */
  generateScaleY2Axis: function(chart){

    'use strict';

    const config = {};

    if (parseInt(chart.scales_y2Axes_display, 10) === 1) {

      config.display = true;

      //scales_y2Axes_type
      config.type = chart.scales_y2Axes_type;

      //scales_y2Axes_position
      config.position = chart.scales_y2Axes_position;

      //Scale Grid Line Configuration scales_y2Axes_gridLines ----------------------------
      config.grid = {
        display: daextdaucUtility.booleanString(
            chart.scales_y2Axes_gridLines_display),

        //Scriptable option
        color: function (context) {
          if (context.index === 0) {
            return daextdaucUtility.outputColor(
                chart.scales_y2Axes_gridLines_zeroLineColor, chart.type,
                'scales_y2Axes_gridLines_zeroLineColor');
          } else {
            return daextdaucUtility.outputColor(
                chart.scales_y2Axes_gridLines_color, chart.type,
                'scales_y2Axes_gridLines_color');
          }
        },

        //Scriptable option
        lineWidth: function (context) {
          if (context.index === 0) {
            return parseInt(
                chart.scales_y2Axes_gridLines_zeroLineWidth, 10);
          } else {
            return daextdaucUtility.outputNumber(
                chart.scales_y2Axes_gridLines_lineWidth, chart.type,
                'scales_y2Axes_gridLines_lineWidth');
          }
        },

        drawBorder: daextdaucUtility.booleanString(
            chart.scales_y2Axes_gridLines_drawBorder),
        drawOnChartArea: daextdaucUtility.booleanString(
            chart.scales_y2Axes_gridLines_drawOnChartArea),
        drawTicks: daextdaucUtility.booleanString(
            chart.scales_y2Axes_gridLines_drawTicks),
        tickLength: parseInt(
            chart.scales_y2Axes_gridLines_tickMarkLength, 10),
        offset: daextdaucUtility.booleanString(
            chart.scales_y2Axes_gridLines_offsetGridLines),
      };

      //Scale Title Configuration scales_y2Axes_scaleLabel -------------------------------
      config.title = {
        display: daextdaucUtility.booleanString(chart.scales_y2Axes_scaleLabel_display),
        text: chart.scales_y2Axes_scaleLabel_labelString,
        font: {
          size: parseInt(chart.scales_y2Axes_scaleLabel_fontSize, 10),
          family: chart.scales_y2Axes_scaleLabel_fontFamily,
          style: chart.scales_y2Axes_scaleLabel_fontStyle,
        },
        color: daextdaucUtility.outputColor(
            chart.scales_y2Axes_scaleLabel_fontColor, chart.type,
            'scales_y2Axes_scaleLabel_fontColor'),
      };

      //Scale Tick Configuration scales_y2Axes_ticks -------------------------------------
      config.ticks = {};

      /**
       * If there is a logarithmic scale active this function is used to display the real
       * value on the y2Axis.
       * Note that this function with this specific content should be used only with the
       * logarithmic scales. Other versions of this function might be used to customize the
       * string representation of the tick value.
       */
      switch(chart.scales_y2Axes_type){

        case 'logarithmic':

          config.ticks.callback = function(tick) {

            let tick_output = null;
            const remain = tick /
                (Math.pow(10, Math.floor(Chart.helpers.log10(tick))));

            //this determines how many ticks are shown
            if (remain === 1 || remain === 2 || remain === 5) {

              if (chart.scales_y2Axes_ticks_round.trim().length > 0) {
                tick_output = tick.toFixed(
                    parseInt(chart.scales_y2Axes_ticks_round, 10)).
                toString();
              } else {
                tick_output = tick.toString();
              }

              tick_output = daextdaucUtility.formatValue(chart,
                  tick_output);

              return chart.scales_y2Axes_ticks_prefix + tick_output +
                  chart.scales_y2Axes_ticks_suffix;

            }
            return '';
          };

          break;

        case 'category':

          //do nothing

          break;

        default:

          config.ticks.callback = function(tick) {

            let tick_output = null;

            if (chart.scales_y2Axes_type == 'linear') {

              if (chart.scales_y2Axes_ticks_round.trim().length > 0) {
                tick_output = tick.toFixed(
                    parseInt(chartscales_y2Axes_ticks_round, 10)).
                toString();
              } else {
                tick_output = tick.toString();
              }

              tick_output = daextdaucUtility.formatValue(chart,
                  tick_output);

            } else {

              tick_output = tick.toString();

            }

            return chart.scales_y2Axes_ticks_prefix + tick_output +
                chart.scales_y2Axes_ticks_suffix;

          };

          break;

      }

      //Scale Tick Configuration -----------------------------------------------------
      config.ticks.autoSkip = daextdaucUtility.booleanString(
          chart.scales_y2Axes_ticks_autoskip);
      config.ticks.display = daextdaucUtility.booleanString(
          chart.scales_y2Axes_ticks_display);
      config.ticks.font = {
        size: parseInt(
            chart.scales_y2Axes_ticks_fontSize, 10),
        family: chart.scales_y2Axes_ticks_fontFamily,
        style: chart.scales_y2Axes_ticks_fontStyle,
      },
          config.ticks.color = daextdaucUtility.outputColor(
              chart.scales_y2Axes_ticks_fontColor, chart.type,
              'scales_y2Axes_ticks_fontColor'),
      config.ticks.maxRotation = parseInt(
          chart.scales_y2Axes_ticks_maxRotation, 10);
      config.ticks.minRotation = parseInt(
          chart.scales_y2Axes_ticks_minRotation, 10);
      config.ticks.mirror = daextdaucUtility.booleanString(
          chart.scales_y2Axes_ticks_mirror);
      config.ticks.padding = parseInt(
          chart.scales_y2Axes_ticks_padding, 10);
      config.ticks.reverse = daextdaucUtility.booleanString(
          chart.scales_y2Axes_ticks_reverse);

      //Scale Configuration Options --------------------------------------------------
      if (chart.scales_y2Axes_ticks_min.trim().length > 0) {
        config.min = parseFloat(
            chart.scales_y2Axes_ticks_min);
      }

      if (chart.scales_y2Axes_ticks_max.trim().length > 0) {
        config.max = parseFloat(
            chart.scales_y2Axes_ticks_max);
      }

      //Scale Linear Configuration Options -------------------------------------------
      if (chart.scales_y2Axes_type == 'linear') {

        config.beginAtZero = daextdaucUtility.booleanString(
            chart.scales_y2Axes_ticks_beginAtZero);

        if (chart.scales_y2Axes_ticks_maxTicksLimit.trim().length > 0) {
          config.ticks.maxTicksLimit = parseInt(
              chart.scales_y2Axes_ticks_maxTicksLimit, 10);
        }

        if (chart.scales_y2Axes_ticks_stepSize.trim().length > 0) {
          config.ticks.stepSize = parseFloat(
              chart.scales_y2Axes_ticks_stepSize);
        }

        if (chart.scales_y2Axes_ticks_suggestedMax.trim().length > 0) {
          config.suggestedMax = parseFloat(
              chart.scales_y2Axes_ticks_suggestedMax);
        }

        if (chart.scales_y2Axes_ticks_suggestedMin.trim().length > 0) {
          config.suggestedMin = parseFloat(
              chart.scales_y2Axes_ticks_suggestedMin);
        }

      }

    } else {

      config.display = false;

    }

    return config;

  },

};