<commit_before>(function(global) {
  'use strict';
  var app = global.app || {};
  var m = global.m;
  var util = global.util;

  var sortBy = util.sortBy;
  var startOfDay = util.startOfDay;
  var addDays = util.addDays;
  var diffDays = util.diffDays;

  var barChartTimelineView = function(ctrl) {
    var title = ctrl.title();
    var data = ctrl.data();
    var daysAgo = ctrl.daysAgo();
    var daysAfter = ctrl.daysAfter();
    var pixelsPerDay = ctrl.pixelsPerDay();
    var selectedIndex = ctrl.selectedIndex();

    var width = (daysAfter + daysAgo + 1) * pixelsPerDay + 1;
    var height = 160;
    var points = calcPoints(data, daysAgo, pixelsPerDay, height);

    return m('div.timeline.bar-chart', {style: 'width: ' + width + 'px;'}, [
      m('div.title', {
        config: function(element, isInitialized) {
          if (isInitialized)
            return;
          ctrl.dispatchEvent({
            type: 'init',
            titleElement: element
          });
        }
      }, title),
      m('svg.graph', {
        height: height,
        width: width,
        onmouseover: function(event) {
          var target = event.target;
          if (target.tagName !== 'rect')
            return;
          var className = target.getAttribute('class');
          var index = +className.match(/index-(\d+)/)[1];
          ctrl.dispatchEvent({
            type: 'select',
            selectedIndex: index
          });
        },
        onmouseout: function(event) {
          var target = event.target;
          if (target.tagName !== 'rect')
            return;
          ctrl.dispatchEvent({
            type: 'select',
            selectedIndex: -1
          });
        }
      }, [
        points.map(function(point, index) {
          return m('rect', {
            x: point.x,
            y: point.y,
            width: pixelsPerDay,
            height: height - point.y,
            className: 'index-' + index + (selectedIndex === index ? ' selected' : '')
          });
        }),
        tooltipView(selectedIndex, data, points, pixelsPerDay)
      ])
    ]);
  };

  var calcPoints = function(data, daysAgo, pixelsPerDay, height) {
    var dataSortedByValue = sortBy(data, 'value');
    var dataLength = data.length;
    var max = dataLength > 0 ? dataSortedByValue[dataLength - 1].value : 0;
    var beginDate = addDays(startOfDay(), -daysAgo);

    return sortBy(data, 'date').map(function(item) {
      return {
        x: (diffDays(item.date, beginDate)) * pixelsPerDay,
        y: (max - item.value) / max * (height - 24) + 24
      };
    });
  };

  var tooltipView = function(index, data, points, pixelsPerDay) {
    var value = index !== -1 ? data[index].value : '';
    var point = index !== -1 ? points[index] : {x: 0, y: 0};<commit_msg>Modify the bar width of bar chart<commit_after>(function(global) {
  'use strict';
  var app = global.app || {};
  var m = global.m;
  var util = global.util;

  var sortBy = util.sortBy;
  var startOfDay = util.startOfDay;
  var addDays = util.addDays;
  var diffDays = util.diffDays;

  var barChartTimelineView = function(ctrl) {
    var title = ctrl.title();
    var data = ctrl.data();
    var daysAgo = ctrl.daysAgo();
    var daysAfter = ctrl.daysAfter();
    var pixelsPerDay = ctrl.pixelsPerDay();
    var selectedIndex = ctrl.selectedIndex();

    var width = (daysAfter + daysAgo + 1) * pixelsPerDay + 1;
    var height = 160;
    var points = calcPoints(data, daysAgo, pixelsPerDay, height);

    return m('div.timeline.bar-chart', {style: 'width: ' + width + 'px;'}, [
      m('div.title', {
        config: function(element, isInitialized) {
          if (isInitialized)
            return;
          ctrl.dispatchEvent({
            type: 'init',
            titleElement: element
          });
        }
      }, title),
      m('svg.graph', {
        height: height,
        width: width,
        onmouseover: function(event) {
          var target = event.target;
          if (target.tagName !== 'rect')
            return;
          var className = target.getAttribute('class');
          var index = +className.match(/index-(\d+)/)[1];
          ctrl.dispatchEvent({
            type: 'select',
            selectedIndex: index
          });
        },
        onmouseout: function(event) {
          var target = event.target;
          if (target.tagName !== 'rect')
            return;
          ctrl.dispatchEvent({
            type: 'select',
            selectedIndex: -1
          });
        }
      }, [
        points.map(function(point, index) {
          return m('rect', {
            x: point.x,
            y: point.y,
            width: pixelsPerDay + 0.5,
            height: height - point.y,
            className: 'index-' + index + (selectedIndex === index ? ' selected' : '')
          });
        }),
        tooltipView(selectedIndex, data, points, pixelsPerDay)
      ])
    ]);
  };

  var calcPoints = function(data, daysAgo, pixelsPerDay, height) {
    var dataSortedByValue = sortBy(data, 'value');
    var dataLength = data.length;
    var max = dataLength > 0 ? dataSortedByValue[dataLength - 1].value : 0;
    var beginDate = addDays(startOfDay(), -daysAgo);

    return sortBy(data, 'date').map(function(item) {
      return {
        x: (diffDays(item.date, beginDate)) * pixelsPerDay,
        y: (max - item.value) / max * (height - 24) + 24
      };
    });
  };

  var tooltipView = function(index, data, points, pixelsPerDay) {
    var value = index !== -1 ? data[index].value : '';
    var point = index !== -1 ? points[index] : {x: 0, y: 0};
{'fraction_non_alphanumeric': 0.14162782359268555, 'fraction_numerical': 0.006812477590534241, 'mean_word_length': 2.0156756756756757, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4873774', 'n_tokens_mistral': 1723, 'n_tokens_neox': 1669, 'n_words': 408}