<commit_before>'use strict';

function getLayout(count, rect) {
  var entryHeight = 20;
  var left = rect.left;
  var result = [];
  var totalPerEntry = rect.height / count;
  for (var i = 0; i < count; i += 1) {
    result.push({
      top: (totalPerEntry - entryHeight) / 2 + rect.top + totalPerEntry * i,
      left: left
    });
  }
  return result;
}

function drawLegendEntry(ctx, data, layout) {
  ctx.fillStyle = '#444';
  ctx.font = '13px Verdana';
  ctx.textAlign = 'left';
  ctx.fillText(data.label, layout.left + 25, layout.top + 10);

  ctx.fillStyle = data.strokeColor;
  ctx.fillRect(layout.left, layout.top, 20, 20);
}

function drawLegend(ctx, rect, data) {
  var layout = getLayout(data.length, rect);
  data.forEach(function (d, i) {
    drawLegendEntry(ctx, d, layout[i]);
  });
}

function generateChart(labels, dataset) {
  var Canvas = require('canvas');
  var canvas = new Canvas(800, 500);
  var ctx = canvas.getContext('2d');
  var Chart = require('nchart');
  var data = {
    labels: labels,
    datasets: dataset
  };
  new Chart(ctx).Line(data);
  var legendSize = {
    left: 40,
    top: 12,
    width: 190,
    height: 70
  };
  drawLegend(ctx, legendSize, dataset);
  return canvas;
}

var fs = require('fs');
var ChartRenderer = {
  generate: function () {
  },
  save: function (filename, chart) {
    chart.toBuffer(function (err, buf) {
      if (err) {
        throw err;
      }
      if (!fs.existsSync(filename)) {
        fs.mkdirSync(filename);
      }
      fs.writeFileSync(filename, buf);
    });
  }
};

module.exports = ChartRenderer;
<commit_msg>Update the rendering functionality<commit_after>'use strict';

function getLayout(count, rect) {
  var entryHeight = 20;
  var left = rect.left;
  var result = [];
  var totalPerEntry = rect.height / count;
  for (var i = 0; i < count; i += 1) {
    result.push({
      top: (totalPerEntry - entryHeight) / 2 + rect.top + totalPerEntry * i,
      left: left
    });
  }
  return result;
}

function drawLegendEntry(ctx, data, layout) {
  ctx.fillStyle = '#444';
  ctx.font = '13px Verdana';
  ctx.textAlign = 'left';
  ctx.fillText(data.label, layout.left + 25, layout.top + 10);

  ctx.fillStyle = data.strokeColor;
  ctx.fillRect(layout.left, layout.top, 20, 20);
}

function drawLegend(ctx, rect, data) {
  var layout = getLayout(data.length, rect);
  data.forEach(function (d, i) {
    drawLegendEntry(ctx, d, layout[i]);
  });
}

function generateChart(labels, dataset) {
  var Canvas = require('canvas');
  var canvas = new Canvas(800, 500);
  var ctx = canvas.getContext('2d');
  var Chart = require('nchart');
  var data = {
    labels: labels,
    datasets: dataset
  };
  new Chart(ctx).Line(data);
  var legendSize = {
    left: 40,
    top: 12,
    width: 190,
    height: 70
  };
  drawLegend(ctx, legendSize, dataset);
  return canvas;
}

var colors = [{
  fillColor: 'rgba(220,220,220,0.3)',
  strokeColor: 'rgba(220,220,220,1)',
  pointColor: 'rgba(220,220,220,1)',
  pointStrokeColor: '#fff',
  pointHighlightFill: '#fff',
  pointHighlightStroke: 'rgba(220,220,220,1)',
}, {
  fillColor: 'rgba(151,187,205,0.3)',
  strokeColor: 'rgba(151,187,205,1)',
  pointColor: 'rgba(151,187,205,1)',
  pointStrokeColor: '#fff',
  pointHighlightFill: '#fff',
  pointHighlightStroke: 'rgba(151,187,205,1)',
}];

var fs = require('fs');
var ChartRenderer = {
  generate: function (labels, datasets) {
    var color = 0;
    datasets = datasets.map(function (s) {
      var c = colors[color];
      var result = {};
      color += 1;
      for (var prop in c) {
        result[prop] = c[prop];
      }
      result.data = s.values;
      result.label = s.label;
      return result;
    });
    return generateChart(labels, datasets);
  },
  save: function (filename, chart) {
    chart.toBuffer(function (err, buf) {
      if (err) {
        throw err;
      }
      if (!fs.existsSync(filename)) {
        fs.mkdirSync(filename);
      }
      fs.writeFileSync(filename, buf);
    });
  }
};

module.exports = ChartRenderer;

{'fraction_non_alphanumeric': 0.15680914512922464, 'fraction_numerical': 0.03777335984095427, 'mean_word_length': 3.1239754098360657, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1264059', 'n_tokens_mistral': 1521, 'n_tokens_neox': 1407, 'n_words': 336}