<commit_before>/**
 * @fileOverview Public Trust Chart directive
 * @author <a href='mailto:<EMAIL>'><NAME></a>
 */
define(['jquery', 'd3'], function ($, d3) {
    'use strict';

    /**
     * Line Graph Chart directive
     */
    var ChartPublicTrustDirective = function () {
        return {
            restrict: 'A',
            replace: true,
            scope: true,
            controller: ChartPublicTrustController,
            link: ChartPublicTrustLinkFn
        };
    };

    /**
     * Controller for Public Trust Chart directive
     * @constructor
     */
    var ChartPublicTrustController = function (
        $scope,
        $timeout
        )
    {
        this._$scope = $scope;
        this._$timeout = $timeout;
    };

    /**
     * Array of dependencies to be injected into controller
     * @type {Array}
     */
    ChartPublicTrustController.$inject = [
        '$scope',
        '$timeout'
    ];

  /**
   * Link function for Public Trust Chart directive
   * @param {object} scope      Angular scope.
   * @param {JQuery} iElem      jQuery element.
   * @param {object} iAttrs     Directive attributes.
   * @param {object} controller Controller reference.
   */
  var ChartPublicTrustLinkFn = function (scope, iElem, iAttrs, controller) {
    controller._$timeout( function() {
      var data = controller._$scope.issue.getInfographic().getDataPoints();
      var lineData = data.lineGraphData;
      var id = controller._$scope.issue.getId();
      var lineGraph = d3.select('#' + id + ' .infographic__wrapper div');
      var numDatasets = lineData[0].data.length;

      var graphWidth = $('#' + id + ' .infographic__wrapper div').width();
      var margin = {top: 20, right: 20, bottom: 50, left: 20};
      var width = graphWidth;
      var height = graphWidth * 0.7;

      var svg = lineGraph.append('svg')
        .attr('class', 'linegraph__svg')
        .attr('width', width)
        .attr('height', height);

      drawPattern();
      drawLegend();
      drawData();

      function drawLegend() {
        var legend = svg.append('g')
          .attr('class', 'linegraph__legend')
          .attr('x', width-margin.right)
          .attr('y', margin.top/3)
          .attr('height', 100)
          .attr('width', 300);

        legend.selectAll('g')
          .data(data.dataLabels)
          .enter()
          .append('g')
            .attr('class', 'linegraph__legendLabel');

        var legendLabel = legend.selectAll('.linegraph__legendLabel');

        legendLabel.selectAll('circle')
          .data(data.dataLabels)
          .enter()
          .append('circle')
            .attr('class', function(d, i) { return 'linegraph__point_' + i + '_circle';})
            .attr('cx', function(d, i) {return width - margin.right - i*80 - (margin.right*5);})
            .attr('cy', margin.top/3)
            .attr('r', 3);

        legendLabel.selectAll('text')
          .data(data.dataLabels)
          .enter()
          .append('text')
              .attr('class', 'linegraph__legendtext')
              .attr('x', function(d, i) {return width - margin.right - i*80 - (margin.right*5) + 6;})
              .attr('y', margin.top/3+4)
              .text(function(d) { return d; });
      }

      function drawLabel() {
        var x = d3.scale.linear()
          .range([margin.left, width-margin.right])
          .domain([
            d3.min( lineData, function(d) { return d.label; }),
            d3.max( lineData, function(d) { return d.label; })
          ]);

        var xAxis = d3.svg.axis()
          .scale(x)
          .orient('bottom')
          .tickFormat( function(d) { return d.toString(); })
          .tickValues( lineData.map( function (d) { return d.label; }) )
          .tickSize(0);

        svg.append('g')
          .attr('class', 'linegraph__xaxis_year')
          .attr('transform', 'translate(0,' + (height-margin.bottom) + ')')
          .call(xAxis);

          return x;
      }

      function drawData() {
        var x = drawLabel();
<commit_msg>minor bug fix for public trust line graph<commit_after>/**
 * @fileOverview Public Trust Chart directive
 * @author <a href='mailto:<EMAIL>'><NAME></a>
 */
define(['jquery', 'd3'], function ($, d3) {
    'use strict';

    /**
     * Line Graph Chart directive
     */
    var ChartPublicTrustDirective = function () {
        return {
            restrict: 'A',
            replace: true,
            scope: true,
            controller: ChartPublicTrustController,
            link: ChartPublicTrustLinkFn
        };
    };

    /**
     * Controller for Public Trust Chart directive
     * @constructor
     */
    var ChartPublicTrustController = function (
        $scope,
        $timeout
        )
    {
        this._$scope = $scope;
        this._$timeout = $timeout;
    };

    /**
     * Array of dependencies to be injected into controller
     * @type {Array}
     */
    ChartPublicTrustController.$inject = [
        '$scope',
        '$timeout'
    ];

  /**
   * Link function for Public Trust Chart directive
   * @param {object} scope      Angular scope.
   * @param {JQuery} iElem      jQuery element.
   * @param {object} iAttrs     Directive attributes.
   * @param {object} controller Controller reference.
   */
  var ChartPublicTrustLinkFn = function (scope, iElem, iAttrs, controller) {
    controller._$timeout( function() {
      var data = controller._$scope.issue.getInfographic().getDataPoints();
      var lineData = data.lineGraphData;
      var id = controller._$scope.issue.getId();
      var lineGraph = d3.select('#' + id + ' .infographic__wrapper div');
      var numDatasets = lineData[0].data.length;

      var graphWidth = $('#' + id + ' .infographic__wrapper div').width();
      var mobileStyle = graphWidth < 420 ? true : false;
      var margin = {top: 20, right: 20, bottom: 50, left: 20};
      var width = graphWidth;
      var height = graphWidth * 0.7;

      var svg = lineGraph.append('svg')
        .attr('class', 'linegraph__svg')
        .attr('width', width)
        .attr('height', height);

      drawPattern();
      drawLegend();
      drawData();

      function drawLegend() {
        var legend = svg.append('g')
          .attr('class', 'linegraph__legend')
          .attr('x', width-margin.right)
          .attr('y', margin.top/3)
          .attr('height', 100)
          .attr('width', 300);

        legend.selectAll('g')
          .data(data.dataLabels)
          .enter()
          .append('g')
            .attr('class', 'linegraph__legendLabel');

        var legendLabel = legend.selectAll('.linegraph__legendLabel');

        legendLabel.selectAll('circle')
          .data(data.dataLabels)
          .enter()
          .append('circle')
            .attr('class', function(d, i) { return 'linegraph__point_' + i + '_circle';})
            .attr('cx', function(d, i) {return width - margin.right - i*80 - (margin.right*5);})
            .attr('cy', margin.top/3)
            .attr('r', 3);

        legendLabel.selectAll('text')
          .data(data.dataLabels)
          .enter()
          .append('text')
              .attr('class', 'linegraph__legendtext')
              .attr('x', function(d, i) {return width - margin.right - i*80 - (margin.right*5) + 6;})
              .attr('y', margin.top/3+4)
              .text(function(d) { return d; });
      }

      function drawLabel() {
        var x = d3.scale.linear()
          .range([margin.left, width-margin.right])
          .domain([
            d3.min( lineData, function(d) { return d.label; }),
            d3.max( lineData, function(d) { return d.label; })
          ]);

        var xAxis;
        if (mobileStyle) {
            xAxis = d3.svg.axis()
            .scale(x)
            .orient('bottom')
            .tickFormat( function(d, i) {
                if (i%2 === 0) {
                    return d.toString();
                }
                else {
                    return null;
                }
            })
            .tickValues( lineData.map( function (d, i) {
                if (i%2 === 0) {
                    return d.label;
                }
                else {
                    return null;
                }
            }))
            .tickSize(0);
        } else {
            xAxis = d3.svg.axis()
            .scale(x)
            .orient('bottom')
            .tickFormat( function(d) { return d.toString(); })
            .tickValues( lineData.map( function (d) { return d.label; }))
            .tickSize(0);
        }

        // filter out null values (d3 scales are terrible sometimes)
        for(var i = xAxis.tickValues.length-1; i--;){
            if (xAxis.tickValues[i] === null) {
                xAxis.tickValues.splice(i, 1);
            }
            if (xAxis.tickFormat[i] === null) {
                xAxis.tickFormat.splice(i, 1);
            }
        }

        svg.append('g')
          .attr('class', 'linegraph__xaxis_year')
          .attr('transform', 'translate(0,' + (height-margin.bottom) + ')')
          .call(xAxis);

          return x;
      }

      function drawData() {
        var x = drawLabel();

{'fraction_non_alphanumeric': 0.14750874125874125, 'fraction_numerical': 0.00972465034965035, 'mean_word_length': 1.777845220030349, 'pattern_counts': {'":': 0, '<': 12, '<?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': '2486196', 'n_tokens_mistral': 2757, 'n_tokens_neox': 2636, 'n_words': 599}