<commit_before>(function() {
  'use strict';
  angular.module('civic.pages')
    .directive('countsByEvidenceLevel', countsByEvidenceLevel)
    .controller('countsByEvidenceLevelController', countsByEvidenceLevelController);

  // @ngInject
  function countsByEvidenceLevel() {
    var directive = {
      restrict: 'E',
      scope: {
        options: '=',
        palette: '='
      },
      templateUrl: 'app/pages/statistics/directives/chartPie.tpl.html',
      controller: countsByEvidenceLevelController
    };
    return directive;
  }

  // @ngInject
  function countsByEvidenceLevelController($scope,
                                           $window,
                                           $rootScope,
                                           $element,
                                           d3,
                                           dimple,
                                           _) {
    console.log('countsByEvidenceLevel loaded.');
    var options = $scope.options;

    var svg = d3.select($element[0])
        .selectAll('.chart-pie')
        .append('svg')
        .attr('width', options.width)
        .attr('height', options.height)
        .attr('id', options.id)
        .style('overflow', 'visible');

    // title
    svg.append('text')
      .attr('x', options.margin.left)
      .attr('y', options.margin.top - 10)
      .style('text-anchor', 'left')
      .style('font-family', 'sans-serif')
      .style('font-weight', 'bold')
      .text(options.title);

    var chart = new dimple.chart(svg)
      .setMargins(0,25,0,25);

    // chart.setBounds(20, 20, 460, 360);
    var p = chart.addMeasureAxis('p', 'Count');
    p.tickFormat = d3.format(',.0f');
    chart.addSeries('Level', dimple.plot.pie);
    var l = chart.addLegend('100%', 25, 90, 300, 'left');
    // override legend sorting
    l._getEntries_old = l._getEntries;
    l._getEntries = function() {
      return _.sortBy(l._getEntries_old.apply(this, arguments), 'key');
    };


    chart.data = _.map(options.data, function(key, value) {
      return {
        Level: _.capitalize(value),
        Count: key
      };
    });
    chart.draw();

    var onResize = function () { chart.draw(0, true); };

    angular.element($window).on('resize', onResize);
    $scope.$on('$destroy', function () {
      angular.element($window).off('resize', onResize);
    });

    $scope.chart = chart;
  }
})();<commit_msg>evidence level pie chart now uses CIViC level colors<commit_after>(function() {
  'use strict';
  angular.module('civic.pages')
    .directive('countsByEvidenceLevel', countsByEvidenceLevel)
    .controller('countsByEvidenceLevelController', countsByEvidenceLevelController);

  // @ngInject
  function countsByEvidenceLevel() {
    var directive = {
      restrict: 'E',
      scope: {
        options: '=',
        palette: '='
      },
      templateUrl: 'app/pages/statistics/directives/chartPie.tpl.html',
      controller: countsByEvidenceLevelController
    };
    return directive;
  }

  // @ngInject
  function countsByEvidenceLevelController($scope,
                                           $window,
                                           $rootScope,
                                           $element,
                                           d3,
                                           dimple,
                                           _) {
    console.log('countsByEvidenceLevel loaded.');
    var options = $scope.options;

    var svg = d3.select($element[0])
        .selectAll('.chart-pie')
        .append('svg')
        .attr('width', options.width)
        .attr('height', options.height)
        .attr('id', options.id)
        .style('overflow', 'visible');

    // title
    svg.append('text')
      .attr('x', options.margin.left)
      .attr('y', options.margin.top - 10)
      .style('text-anchor', 'left')
      .style('font-family', 'sans-serif')
      .style('font-weight', 'bold')
      .text(options.title);

    var chart = new dimple.chart(svg)
      .setMargins(0,25,0,25);

    var p = chart.addMeasureAxis('p', 'Count');
    p.tickFormat = d3.format(',.0f');
    chart.addSeries('Level', dimple.plot.pie);

    // colors
    var levelColors = [
      {
        val: 'A',
        color: '#33b358'
      },
      {
        val: 'B',
        color: '#08b1e6'
      },
      {
        val: 'C',
        color: '#616eb2'
      },
      {
        val: 'D',
        color: '#f68f47'
      },
      {
        val: 'E',
        color: '#e24759'
      },
      {
        val: 'F',
        color: '#fce452'
      }
    ];

    _.map(levelColors, function(c) {
      chart.assignColor(c.val, c.color);
    });

    // legend
    var l = chart.addLegend('100%', 25, 50, 300, 'left');
    // override legend sorting
    l._getEntries_old = l._getEntries;
    l._getEntries = function() {
      return _.sortBy(l._getEntries_old.apply(this, arguments), 'key');
    };


    chart.data = _.map(options.data, function(key, value) {
      return {
        Level: _.capitalize(value),
        Count: key
      };
    });
    chart.draw();

    var onResize = function () { chart.draw(0, true); };

    angular.element($window).on('resize', onResize);
    $scope.$on('$destroy', function () {
      angular.element($window).off('resize', onResize);
    });

    $scope.chart = chart;
  }
})();
{'fraction_non_alphanumeric': 0.15462373642830401, 'fraction_numerical': 0.015537251965555972, 'mean_word_length': 1.8225039619651346, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6985735', 'n_tokens_mistral': 1660, 'n_tokens_neox': 1573, 'n_words': 280}