<commit_before>'use strict';

(function () {
  var chartjs = angular.module('chartjs', []),
    chartTypes = {
      line: 'Line',
      bar: 'Bar',
      radar: 'Radar',
      polar: 'PolarArea',
      pie: 'Pie',
      doughnut: 'Doughnut'
    },
    makeChartDirective = function (chartType) {
      var upper = chartType.charAt(0).toUpperCase() + chartType.slice(1);
      chartjs.directive('cjs' + upper, function (chartFactory) {
        return new chartFactory(chartType)
      });
    },
    sizeChart = function (width, height, canvas) {
      var oW = canvas.width,
          oH = canvas.height;
      if (oW !== width || oH !== height) {
        canvas.width = width;
        canvas.height = height;
        return true;
      }
      return false;
    },
    fitChart = function (canvas, element) {
      var w = element.parent().prop('offsetWidth'),
          h = element.parent().prop('offsetHeight');
      return sizeChart(w, h, canvas);
    };

  for (var c in chartTypes) {
    makeChartDirective(c);
  }

  chartjs.factory('chartFactory', function () {
    return function (chartType) {

      var chartType = chartTypes[chartType],
        extractSpecOpts = function (opts, attrs) {
          var i = opts.length,
            extracted = {},
            cv;

          while (i--) {
            cv = attrs[opts[i]];
            if (typeof(cv) !== 'undefined') {
              extracted[opts[i]] = cv;
            }
          }
          return extracted;
        };

      if (typeof(chartType) === 'undefined') {
        return;
      }

      return {
        restrict: 'EAC',
        template: '<canvas></canvas>',
        replace: true,
        scope: {
          dataset: '=',
          options: '=',
          autofit: '='
        },
        link: function postLink(scope, element, attrs) {
          var ctx = element[0].getContext('2d'),
              chart = new Chart(ctx),
              chartOpts = {},
              specOpts = [],
              autofit = scope.autofit,
              bound = false,
              drawChart = function (value, forceRedraw) {
                if ((autofit && fitChart(ctx.canvas, element)) || forceRedraw) {
                  chart = new Chart(ctx);
                  chart[chartType](value, chartOpts);
                }

                if (!bound) {
                  angular.element(window).bind('resize', function () {
                    drawChart(value);
                  });
                  bound = true;
                }
              };

          // HACK: to get default params out of protected scope from ChartJS
          try {
            chart[chartType]([], {});
          } catch (e) {}
          // Chart.js < 1.0.0
          if (chart[chartType].defaults) {
            specOpts = Object.keys(chart[chartType].defaults);
          }
          // Chart.js >= 1.0.0
          else if(Chart.defaults[chartType]) {
            specOpts = Object.keys(Chart.defaults[chartType]);
          }
          // ENDHACK

          angular.extend(chartOpts, scope.options, extractSpecOpts(specOpts, attrs));

          scope.$watch('dataset', function (value) {
            if (!value) {
              return;
            }
            drawChart(value, true);
          }, true);
        }
      }
    }
  });
})();
<commit_msg>Handle minification correctly<commit_after>'use strict';

(function () {
  var chartjs = angular.module('chartjs', []),
    chartTypes = {
      line: 'Line',
      bar: 'Bar',
      radar: 'Radar',
      polar: 'PolarArea',
      pie: 'Pie',
      doughnut: 'Doughnut'
    },
    makeChartDirective = function (chartType) {
      var upper = chartType.charAt(0).toUpperCase() + chartType.slice(1);
      chartjs.directive('cjs' + upper, ['chartFactory', function (chartFactory) {
        return new chartFactory(chartType)
      }]);
    },
    sizeChart = function (width, height, canvas) {
      var oW = canvas.width,
          oH = canvas.height;
      if (oW !== width || oH !== height) {
        canvas.width = width;
        canvas.height = height;
        return true;
      }
      return false;
    },
    fitChart = function (canvas, element) {
      var w = element.parent().prop('offsetWidth'),
          h = element.parent().prop('offsetHeight');
      return sizeChart(w, h, canvas);
    };

  for (var c in chartTypes) {
    makeChartDirective(c);
  }

  chartjs.factory('chartFactory', function () {
    return function (chartType) {

      var chartType = chartTypes[chartType],
        extractSpecOpts = function (opts, attrs) {
          var i = opts.length,
            extracted = {},
            cv;

          while (i--) {
            cv = attrs[opts[i]];
            if (typeof(cv) !== 'undefined') {
              extracted[opts[i]] = cv;
            }
          }
          return extracted;
        };

      if (typeof(chartType) === 'undefined') {
        return;
      }

      return {
        restrict: 'EAC',
        template: '<canvas></canvas>',
        replace: true,
        scope: {
          dataset: '=',
          options: '=',
          autofit: '='
        },
        link: function postLink(scope, element, attrs) {
          var ctx = element[0].getContext('2d'),
              chart = new Chart(ctx),
              chartOpts = {},
              specOpts = [],
              autofit = scope.autofit,
              bound = false,
              drawChart = function (value, forceRedraw) {
                if ((autofit && fitChart(ctx.canvas, element)) || forceRedraw) {
                  chart = new Chart(ctx);
                  chart[chartType](value, chartOpts);
                }

                if (!bound) {
                  angular.element(window).bind('resize', function () {
                    drawChart(value);
                  });
                  bound = true;
                }
              };

          // HACK: to get default params out of protected scope from ChartJS
          try {
            chart[chartType]([], {});
          } catch (e) {}
          // Chart.js < 1.0.0
          if (chart[chartType].defaults) {
            specOpts = Object.keys(chart[chartType].defaults);
          }
          // Chart.js >= 1.0.0
          else if(Chart.defaults[chartType]) {
            specOpts = Object.keys(Chart.defaults[chartType]);
          }
          // ENDHACK

          angular.extend(chartOpts, scope.options, extractSpecOpts(specOpts, attrs));

          scope.$watch('dataset', function (value) {
            if (!value) {
              return;
            }
            drawChart(value, true);
          }, true);
        }
      }
    }
  });
})();

{'fraction_non_alphanumeric': 0.1373642943305187, 'fraction_numerical': 0.0030156815440289505, 'mean_word_length': 1.5278201219512195, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '1321533', 'n_tokens_mistral': 1861, 'n_tokens_neox': 1858, 'n_words': 397}