<commit_before>/**
 * @name C3 angularjs directive
 * @desc Generic directive along with directives for commonly used charts
 */

var counter = Math.ceil((Math.random() * 1000));
(function () {
  angular.module('c3-angularjs', [])
    .directive('c3Chart', function () {
      return {
        restrict: "AE",
        scope: {
          data: "=",
          axis: "=",
          chartid: "@",
          color: "=",
          size: "=",
          padding: "=",
          grid: "=",
          legend: "=",
          point: "=",
          regions: "=",
          tooltip: "=",
          line: "=",
          area: "=",
          bar: "=",
          pie: "=",
          donut: "=",
          gauge: "="
        },
        template: "<div></div>",
        link: function (scope, elem, attrs) {

          var chart;
          scope_dir = scope;

          //set the id if given or add a random one
          var generateChartId = function () {
            if (scope.chartid) {
              elem[0].childNodes[0].id = scope.chartid;
            }
            else {
              elem[0].childNodes[0].id = scope.chartid = 'c3' + counter;
              counter++;
            }
          };

          //generate the chart
          scope.generateChart = function () {
            axis = scope.axis || {};
            color = scope.color || {};
            size = scope.size || {};
            padding = scope.padding || {};
            grid = scope.grid || {};
            chart = c3.generate({
              bindto: '#' + scope.chartid,
              data: scope.data,
              axis: axis,
              color: color,
              size: size,
              padding: padding,
              grid: grid,
              legend: scope.legend || {},
              point: scope.point || {},
              regions: scope.regions || {},
              tooltip: scope.tooltip || {},
              line: scope.line || {},
              area: scope.area || {},
              bar: scope.bar || {},
              pie: scope.pie || {},
              donut: scope.donut || {},
              gauge: scope.gauge || {}
            });
          };

          scope.$watch('axis', function (newVal, oldVal) {
            if (scope.axis && chart) {
              var labels = {};
              if (newVal.x.label) { labels.x = newVal.x.label; }
              if (newVal.y.label) { labels.y = newVal.y.label; }
              chart.axis.labels(labels);

              var range = {min: {}, max: {}};
              if (newVal.x.min) { range.min.x = newVal.x.min; } // else { range.min.x = undefined; }
              if (newVal.y.min) { range.min.y = newVal.y.min; } // else { range.min.y = undefined; }
              if (newVal.x.max) { range.max.x = newVal.x.max; } // else { range.max.x = undefined; }
              if (newVal.y.max) { range.max.y = newVal.y.max; } // else { range.max.y = undefined; }

              console.log(range);
              chart.axis.range(range);
            }
          }, true);

          //update
          scope.$watchGroup(['data', 'grid'], function (newVal, oldVal) {
            generateChartId();
            if (newVal && newVal == oldVal) {
              scope.generateChart();
            }
            else if (newVal != oldVal) {
              chart.load(newVal);
	          scope.generateChart();
            }
          }, true);
        }
      }
    })
    .directive('c3Donut', function () {
      return {
        restrict: "AE",
        scope: {
          data: "=",
          pie: "@"<commit_msg>Split watcher for data because it didnt work for data part<commit_after>/**
 * @name C3 angularjs directive
 * @desc Generic directive along with directives for commonly used charts
 */

var counter = Math.ceil((Math.random() * 1000));
(function () {
  angular.module('c3-angularjs', [])
    .directive('c3Chart', function () {
      return {
        restrict: "AE",
        scope: {
          data: "=",
          axis: "=",
          chartid: "@",
          color: "=",
          size: "=",
          padding: "=",
          grid: "=",
          legend: "=",
          point: "=",
          regions: "=",
          tooltip: "=",
          line: "=",
          area: "=",
          bar: "=",
          pie: "=",
          donut: "=",
          gauge: "="
        },
        template: "<div></div>",
        link: function (scope, elem, attrs) {

          var chart;
          scope_dir = scope;

          //set the id if given or add a random one
          var generateChartId = function () {
            if (scope.chartid) {
              elem[0].childNodes[0].id = scope.chartid;
            }
            else {
              elem[0].childNodes[0].id = scope.chartid = 'c3' + counter;
              counter++;
            }
          };

          //generate the chart
          scope.generateChart = function () {
            axis = scope.axis || {};
            color = scope.color || {};
            size = scope.size || {};
            padding = scope.padding || {};
            grid = scope.grid || {};
            chart = c3.generate({
              bindto: '#' + scope.chartid,
              data: scope.data,
              axis: axis,
              color: color,
              size: size,
              padding: padding,
              grid: grid,
              legend: scope.legend || {},
              point: scope.point || {},
              regions: scope.regions || {},
              tooltip: scope.tooltip || {},
              line: scope.line || {},
              area: scope.area || {},
              bar: scope.bar || {},
              pie: scope.pie || {},
              donut: scope.donut || {},
              gauge: scope.gauge || {}
            });
          };

          scope.$watch('axis', function (newVal, oldVal) {
            if (scope.axis && chart) {
              var labels = {};
              if (newVal.x.label) { labels.x = newVal.x.label; }
              if (newVal.y.label) { labels.y = newVal.y.label; }
              chart.axis.labels(labels);

              var range = {min: {}, max: {}};
              if (newVal.x.min) { range.min.x = newVal.x.min; } // else { range.min.x = undefined; }
              if (newVal.y.min) { range.min.y = newVal.y.min; } // else { range.min.y = undefined; }
              if (newVal.x.max) { range.max.x = newVal.x.max; } // else { range.max.x = undefined; }
              if (newVal.y.max) { range.max.y = newVal.y.max; } // else { range.max.y = undefined; }

              console.log(range);
              chart.axis.range(range);
            }
          }, true);

          //update
          scope.$watch('data', updateGraph, true);
          scope.$watch('grid', updateGraph, true);

          function updateGraph(newVal, oldVal) {
            generateChartId();
            if (newVal && newVal == oldVal) {
              scope.generateChart();
            }
            else if (newVal != oldVal) {
              chart.load(newVal);
              scope.generateChart();
            }
          }
        }
      }
    })
    .directive('c3Donut', function () {
      return {
        restrict: "AE",
        scope: {
          data: "=",
          pie: "@"
{'fraction_non_alphanumeric': 0.1581148912437256, 'fraction_numerical': 0.0039040713887339654, 'mean_word_length': 1.2492944496707432, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2301085', 'n_tokens_mistral': 2075, 'n_tokens_neox': 2039, 'n_words': 431}