<commit_before>/**
 * @param {Object} $ The jQuery library
 * @param {Object} Chart The ChartJS library
 * @param {Object} document
 */
(function($, Chart, document) {

  /**
   * @param {Object} options (Optional)
   * @return {selector}
   */
  $.fn.chart = function(data, options) {

    if (typeof data === 'undefined') {
      throw new Error('jQuery Chart requries a data array');
    }

    if (data &&
        !Array.isArray(data)) {
      throw new Error("'data' parameter must be an Array");
    }

    if (typeof options !== 'object' ||
        typeof options.type !== 'string') {
      throw new Error('jQuery Chart requires a chart type option to be set');
    }

    // TODO Add control on data values

    /**
     * @type {Object}
     * @private
     */
    var _settings = $.extend({}, $.fn.chart.defaults, options);

    /**
     * The sum of the values of all the chart's sections
     *
     * @type {Number}
     */
    var _total = 0;

    data.forEach(function(item) {
      _total += item.value;
    });

    // If the chart is empty and skipIfEmpty options is set to 'true' then don't do anything
    if (_total === 0 && _settings.skipIfEmpty) {
      return this;
    }

    if (options.type == 'pie') {
      return this.each(function() {
        var target = this;

        // Set some default settings for the pie chart
        _settings.animationSteps = _settings.animationTime / 18;
        _settings.onAnimationComplete = function() {
          if (_settings.showTooltips) {
            var chartOptions = this;
            // Remove tooltips for segments with zero value

            $.each(chartOptions.segments, function(segmentIndex) {
              if (this.value === 0) {
                chartOptions.segments.splice(segmentIndex, 1);
              }
            });

            this.showTooltip(this.segments, true);
          }
        };
        _settings.percentageInnerCutout = 60;
        _settings.tooltipEvents = [];
        _settings.tooltipRadialShift = 140;

        // Creating a div with position relative. This is because otherwise when new elements are added to the page
        // and the chart moves around, the tooltips would remain in the old place instead of the new one.
        var $wrapper = $('<div></div>').css('position', 'relative');
        var $canvas = $(document.createElement('canvas')).appendTo(
          $wrapper.appendTo(target)
        );

        // If the background color was not specified then use the container's one
        if (_settings.backgroundColor === '') {
          _settings.backgroundColor = $(target).css('background-color') ;
        }

        // Set the background color of the chart
        $canvas.css('background-color', _settings.backgroundColor);
        // We can't just use the transparent stroke color as it's drawn on the top of segments.
        // So we use the same color as used for the background.
        _settings.segmentStrokeColor = _settings.backgroundColor;

        $canvas.height(_settings.height ? _settings.height : $(target).height());
        $canvas.width(_settings.width ? _settings.width : $(target).width());

        if (_settings.innerTextTemplate) {
          var $innerText = $('<div />')
            .text(_settings.innerTextTemplate)
            .addClass('chartjs-inner-text')
            .appendTo($wrapper)
            .css({
              left: $canvas.width() / 2 + $canvas.position().left + 'px',
              top: $canvas.width() / 2 + $canvas.position().top + 'px'
          });
        }

        Chart.defaults.global.customTooltips = function(tooltip) {
          if (!tooltip || Number.parseInt(tooltip.text.replace('%', '')) === 0) {
            return;
          }

          // TODO The position of the tooltip should be inside the chart size, so we need to resize the chart itself
          // TODO to match this request
          // Tooltip Element
          var $tooltip = $('<div />');
          $tooltip.addClass('chartjs-tooltip').html(tooltip.text).appendTo($wrapper);
          var deltaX = tooltip.x - $canvas.width() / 2;
          var deltaY = tooltip.y - $canvas.height() / 2;
          var tooltipPosition = {
            left: tooltip.chart.canvas.offsetLeft + tooltip.x + (deltaX * _settings.tooltipRadialShift / 100 - deltaX),
            top: tooltip.chart.canvas.offsetTop + tooltip.y + (deltaY * _settings.tooltipRadialShift / 100 - deltaY)
          };

          // Display, position, and set styles for font
          $tooltip.css({
            left: tooltipPosition.left  + 'px',
            top: tooltipPosition.top + 'px'
          });
        };

        // Automatically adapts the font-size to make the inner text fit the space inside the doughnut

        // Maximum (and default) font size
        var maxFontSize = 30;

        // Calculates the width of the space inside the doughnut
        var innerTextContainerMaxWidth = $(this).width() / 100 * _settings.percentageInnerCutout;
        // Gets the inner text DIV container
        var innerTextContainer = $(this).find(".chartjs-inner-text");
        // Sets the width of the innerTextContainer to which the font size will be adaptated
        innerTextContainer.width(innerTextContainerMaxWidth);
        // Set the height of the innerTextContainer so the text with max font size would fit it
        innerTextContainer.height(maxFontSize);
        // Apply the font size adaptation plugin to the inner text container DIV
        innerTextContainer.boxfit({
          maximum_font_size: maxFontSize + "px",<commit_msg>[[FIX]] Add 5px margin between the inner text and the inner pie chart circle<commit_after>/**
 * @param {Object} $ The jQuery library
 * @param {Object} Chart The ChartJS library
 * @param {Object} document
 */
(function($, Chart, document) {

  /**
   * @param {Object} options (Optional)
   * @return {selector}
   */
  $.fn.chart = function(data, options) {

    if (typeof data === 'undefined') {
      throw new Error('jQuery Chart requries a data array');
    }

    if (data &&
        !Array.isArray(data)) {
      throw new Error("'data' parameter must be an Array");
    }

    if (typeof options !== 'object' ||
        typeof options.type !== 'string') {
      throw new Error('jQuery Chart requires a chart type option to be set');
    }

    // TODO Add control on data values

    /**
     * @type {Object}
     * @private
     */
    var _settings = $.extend({}, $.fn.chart.defaults, options);

    /**
     * The sum of the values of all the chart's sections
     *
     * @type {Number}
     */
    var _total = 0;

    data.forEach(function(item) {
      _total += item.value;
    });

    // If the chart is empty and skipIfEmpty options is set to 'true' then don't do anything
    if (_total === 0 && _settings.skipIfEmpty) {
      return this;
    }

    if (options.type == 'pie') {
      return this.each(function() {
        var target = this;

        // Set some default settings for the pie chart
        _settings.animationSteps = _settings.animationTime / 18;
        _settings.onAnimationComplete = function() {
          if (_settings.showTooltips) {
            var chartOptions = this;
            // Remove tooltips for segments with zero value

            $.each(chartOptions.segments, function(segmentIndex) {
              if (this.value === 0) {
                chartOptions.segments.splice(segmentIndex, 1);
              }
            });

            this.showTooltip(this.segments, true);
          }
        };
        _settings.percentageInnerCutout = 60;
        _settings.tooltipEvents = [];
        _settings.tooltipRadialShift = 140;

        // Creating a div with position relative. This is because otherwise when new elements are added to the page
        // and the chart moves around, the tooltips would remain in the old place instead of the new one.
        var $wrapper = $('<div></div>').css('position', 'relative');
        var $canvas = $(document.createElement('canvas')).appendTo(
          $wrapper.appendTo(target)
        );

        // If the background color was not specified then use the container's one
        if (_settings.backgroundColor === '') {
          _settings.backgroundColor = $(target).css('background-color') ;
        }

        // Set the background color of the chart
        $canvas.css('background-color', _settings.backgroundColor);
        // We can't just use the transparent stroke color as it's drawn on the top of segments.
        // So we use the same color as used for the background.
        _settings.segmentStrokeColor = _settings.backgroundColor;

        $canvas.height(_settings.height ? _settings.height : $(target).height());
        $canvas.width(_settings.width ? _settings.width : $(target).width());

        if (_settings.innerTextTemplate) {
          var $innerText = $('<div />')
            .text(_settings.innerTextTemplate)
            .addClass('chartjs-inner-text')
            .appendTo($wrapper)
            .css({
              left: $canvas.width() / 2 + $canvas.position().left + 'px',
              top: $canvas.width() / 2 + $canvas.position().top + 'px'
          });
        }

        Chart.defaults.global.customTooltips = function(tooltip) {
          if (!tooltip || Number.parseInt(tooltip.text.replace('%', '')) === 0) {
            return;
          }

          // TODO The position of the tooltip should be inside the chart size, so we need to resize the chart itself
          // TODO to match this request
          // Tooltip Element
          var $tooltip = $('<div />');
          $tooltip.addClass('chartjs-tooltip').html(tooltip.text).appendTo($wrapper);
          var deltaX = tooltip.x - $canvas.width() / 2;
          var deltaY = tooltip.y - $canvas.height() / 2;
          var tooltipPosition = {
            left: tooltip.chart.canvas.offsetLeft + tooltip.x + (deltaX * _settings.tooltipRadialShift / 100 - deltaX),
            top: tooltip.chart.canvas.offsetTop + tooltip.y + (deltaY * _settings.tooltipRadialShift / 100 - deltaY)
          };

          // Display, position, and set styles for font
          $tooltip.css({
            left: tooltipPosition.left  + 'px',
            top: tooltipPosition.top + 'px'
          });
        };

        // Automatically adapts the font-size to make the inner text fit the space inside the doughnut

        // Maximum (and default) font size
        var maxFontSize = 30;
        // The minimum distante between the inner text and chart's inner circle in pixels
        var innerTextMargin = 5;

        // Calculates the width of the space inside the doughnut
        var innerTextContainerMaxWidth = $(this).width() / 100 * _settings.percentageInnerCutout - (innerTextMargin * 2);
        // Gets the inner text DIV container
        var innerTextContainer = $(this).find(".chartjs-inner-text");
        // Sets the width of the innerTextContainer to which the font size will be adaptated
        innerTextContainer.width(innerTextContainerMaxWidth);
        // Set the height of the innerTextContainer so the text with max font size would fit it
        innerTextContainer.height(maxFontSize);
        // Apply the font size adaptation plugin to the inner text container DIV
        innerTextContainer.boxfit({
          maximum_font_size: maxFontSize + "px",
{'fraction_non_alphanumeric': 0.1145962184131472, 'fraction_numerical': 0.00503622548153384, 'mean_word_length': 2.191147448548069, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '172125', 'n_tokens_mistral': 3071, 'n_tokens_neox': 2950, 'n_words': 960}