<commit_before>var d3 = require( 'd3' );

var headers = {
    'Access-Control-Allow-Origin': '*',
    'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept',
    'Access-Control-Request-Method': '*',
    'Access-Control-Allow-Methods': '*',
    'Content-Type': 'image/svg+xml'
};

var style = "svg {  \
  font: 10px sans-serif;    \
  fill:rgb(50%, 50%, 50%);  \
}   \
    \
.axis path, \
.axis line {    \
  fill: none;   \
  stroke: rgb(50%, 50%, 50%); \
  shape-rendering: crispEdges;  \
}   \
    \
.x.axis path {  \
  display: none;    \
}   \
    \
.line { \
  fill: none;   \
  stroke: steelblue;    \
  stroke-width: 1.5px;  \
}   \
.xtick { \
  transform: rotate(-35deg);  \
  text-anchor: end; \
}   \
";

module.exports = function (res, dataPath ) {
    var cached = dataCache[dataPath];

    if (!cached) {
        dataCache[dataPath] = {isUpdating: true};
    }

    if (cached && cached.render) {
        
        headers["Cache-Control"] = "public, max-age=30";
        headers["Expires"] = (new Date(Date.now() + 30000)).toUTCString(); 
        
        res.writeHead( 200, headers );
        res.end( cached.render );
        
        if ( cached.renderDate < Date.now() - 65000 ) {
            updateCache(dataPath);
        }
        
    } else {    
        d3.csv(dataPath, 
            function(error, data) { 
                if (error) {
                    return;
                };
                prepareData(data, dataPath);
                
                cached = dataCache[dataPath];
                
                headers["Cache-Control"] = "public, max-age=30";
                headers["Expires"] = (new Date(Date.now() + 30000)).toUTCString(); 
                
                res.writeHead( 200, headers );

                res.end( cached.render );
            }
        );
    }
}

function updateCache(dataPath) {
    var entry = dataCache[dataPath];
    if (!entry.isUpdating && (entry.renderDate || 0) < Date.now() - 10000) {
        entry.isUpdating = true;
        d3.csv(dataPath, 
            function(error, data) { 
                if (error) {
                    return;
                };
                prepareData(data, dataPath);
            }
        );
    }
}

function prepareData(data, dataPath) {


var document = require( 'jsdom' ).jsdom();
var margin = {top: 10, right: 0, bottom: 50, left: 40},
        width = 888 - margin.left - margin.right,
        height = 300 - margin.top - margin.bottom;

var parseDate = d3.time.format("%Y-%m-%d").parse;
<commit_msg>Closer margins<commit_after>var d3 = require( 'd3' );

var headers = {
    'Access-Control-Allow-Origin': '*',
    'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept',
    'Access-Control-Request-Method': '*',
    'Access-Control-Allow-Methods': '*',
    'Content-Type': 'image/svg+xml'
};

var style = "svg {  \
  font: 10px sans-serif;    \
  fill:rgb(50%, 50%, 50%);  \
}   \
    \
.axis path, \
.axis line {    \
  fill: none;   \
  stroke: rgb(50%, 50%, 50%); \
  shape-rendering: crispEdges;  \
}   \
    \
.x.axis path {  \
  display: none;    \
}   \
    \
.line { \
  fill: none;   \
  stroke: steelblue;    \
  stroke-width: 1.5px;  \
}   \
.xtick { \
  transform: rotate(-35deg);  \
  text-anchor: end; \
}   \
";

module.exports = function (res, dataPath ) {
    var cached = dataCache[dataPath];

    if (!cached) {
        dataCache[dataPath] = {isUpdating: true};
    }

    if (cached && cached.render) {
        
        headers["Cache-Control"] = "public, max-age=30";
        headers["Expires"] = (new Date(Date.now() + 30000)).toUTCString(); 
        
        res.writeHead( 200, headers );
        res.end( cached.render );
        
        if ( cached.renderDate < Date.now() - 65000 ) {
            updateCache(dataPath);
        }
        
    } else {    
        d3.csv(dataPath, 
            function(error, data) { 
                if (error) {
                    return;
                };
                prepareData(data, dataPath);
                
                cached = dataCache[dataPath];
                
                headers["Cache-Control"] = "public, max-age=30";
                headers["Expires"] = (new Date(Date.now() + 30000)).toUTCString(); 
                
                res.writeHead( 200, headers );

                res.end( cached.render );
            }
        );
    }
}

function updateCache(dataPath) {
    var entry = dataCache[dataPath];
    if (!entry.isUpdating && (entry.renderDate || 0) < Date.now() - 10000) {
        entry.isUpdating = true;
        d3.csv(dataPath, 
            function(error, data) { 
                if (error) {
                    return;
                };
                prepareData(data, dataPath);
            }
        );
    }
}

function prepareData(data, dataPath) {


var document = require( 'jsdom' ).jsdom();
var margin = {top: 10, right: -20, bottom: 50, left: 35},
        width = 888 - margin.left - margin.right,
        height = 300 - margin.top - margin.bottom;

var parseDate = d3.time.format("%Y-%m-%d").parse;

{'fraction_non_alphanumeric': 0.15756508122920337, 'fraction_numerical': 0.026423957721667644, 'mean_word_length': 1.6164874551971327, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '4898622', 'n_tokens_mistral': 1795, 'n_tokens_neox': 1623, 'n_words': 317}