<commit_before>/*eslint-env browser */
/*global $, sorted_courts, precedentTypes */

var hash = window.location.hash.substr(1),
    court_data = [],
    chartData = [];

function drawGraph(data) {
    var entry = {},
        courtName = court_data[hash].short_name;
    chartData = [];

    for (var item in data.annual_counts) {
        if (data.annual_counts.hasOwnProperty(item)) {
            entry = {};
            entry.x = parseInt(item, 10);
            entry.y = data.annual_counts[item];
            chartData.push(entry);
        }
    }
    chartData.sort(function(a, b) {
        return a.x - b.x;
    });
    $('#coverageChart').empty();

    function getXDataValue(d) {
        return d.x;
    }

    function getYDataValue(d) {
        return d.y;
    }

    // Scales
    if (chartData.length > 10) {
        var xScale = new Plottable.Scale.Linear();
        var xAxis  = new Plottable.Axis.Numeric(xScale, 'bottom');
    } else {
        var xScale = new Plottable.Scale.Ordinal();
        var xAxis  = new Plottable.Axis.Category(xScale, 'bottom');
    }
    var yScale = new Plottable.Scale.Linear();

    // Plot Components
    var title  = new Plottable.Component.TitleLabel(parseInt(data.total, 10).toLocaleString() + ' Opinions');
    var yLabel = new Plottable.Component.Label('Number of Opinions', 'left');
    var xLabel = new Plottable.Component.Label(courtName);
    var yAxis  = new Plottable.Axis.Numeric(yScale, 'left');
    var plot   = new Plottable.Plot.Bar(xScale, yScale, true)
        .addDataset(chartData)
        .animate(true)
        .project("x", getXDataValue, xScale)
        .project("y", getYDataValue, yScale)
        .hoverMode('line') // need to do performance check on this setting or comment out
        .barLabelsEnabled(true);


    yAxis.formatter(function (d) {
        return d.toLocaleString();
    });

    var table = new Plottable.Component.Table([
        [null, null, title],
        [yLabel, yAxis, plot],
        [null, null, xAxis],
        [null, null, xLabel]
    ]);

    // Render it
    table.renderTo('#coverageChart');

    var hover = new Plottable.Interaction.Hover();
    hover.onHoverOver(function(hoverData) {
        var xString = hoverData.data[0].x;
        var yString = hoverData.data[0].y.toLocaleString();
        title.text(yString + " opinions in "+ xString);
    });
    hover.onHoverOut(function() {
        title.text(parseInt(data.total, 10).toLocaleString() + ' Opinions');
    });
    plot.registerInteraction(hover);

    var click = new Plottable.Interaction.Click();
    click.callback(function(p) {
        var bars = plot.getBars(p.x, p.y),
            year,
            prec = '',
            i;
        if (bars[0].length) {
            year = bars.data()[0].x;
            for (i = 0; i < precedentTypes.length; i++) {
                prec += '&' + precedentTypes[i] + '=on';
            }
            window.location.href = '/?type=o' +
                prec +
                '&filed_after=' + year +
                '-01-01&filed_before=' + (year + 1) +
                '-12-31&order_by=score+desc' + ((hash !== 'all') ? '&court=' + hash : '');
        }
    });
    plot.registerInteraction(click);
}

// Do this when the hash of the page changes (i.e. at page load or when a select is chosen.
$(window).hashchange(function() {
    hash = window.location.hash.substr(1);<commit_msg>Tweaks to the coverage js discovered in prod.<commit_after>/*eslint-env browser */
/*global $, sorted_courts, precedentTypes */

var hash = window.location.hash.substr(1),
    court_data = [],
    chartData = [];

function drawGraph(data) {
    var entry = {},
        courtName = court_data[hash].short_name;
    chartData = [];

    for (var item in data.annual_counts) {
        if (data.annual_counts.hasOwnProperty(item)) {
            entry = {};
            entry.x = parseInt(item, 10);
            entry.y = data.annual_counts[item];
            chartData.push(entry);
        }
    }
    chartData.sort(function(a, b) {
        return a.x - b.x;
    });
    $('#coverageChart').empty();

    function getXDataValue(d) {
        return d.x;
    }

    function getYDataValue(d) {
        return d.y;
    }

    // Scales
    if (chartData.length > 10) {
        var xScale = new Plottable.Scale.Linear();
        var xAxis  = new Plottable.Axis.Numeric(xScale, 'bottom');
    } else {
        var xScale = new Plottable.Scale.Ordinal();
        var xAxis  = new Plottable.Axis.Category(xScale, 'bottom');
    }
    var yScale = new Plottable.Scale.Linear();

    // Plot Components
    var title  = new Plottable.Component.TitleLabel(parseInt(data.total, 10).toLocaleString() + ' Opinions');
    var yLabel = new Plottable.Component.Label('Number of Opinions', 'left');
    var xLabel = new Plottable.Component.Label(courtName);
    var yAxis  = new Plottable.Axis.Numeric(yScale, 'left');
    var plot   = new Plottable.Plot.Bar(xScale, yScale, true)
        .addDataset(chartData)
        .animate(true)
        .project("x", getXDataValue, xScale)
        .project("y", getYDataValue, yScale)
        //.hoverMode('line') // need to do performance check on this setting or comment out
        .barLabelsEnabled(chartData.length < 11);


    yAxis.formatter(function (d) {
        return d.toLocaleString();
    });

    var table = new Plottable.Component.Table([
        [null, null, title],
        [yLabel, yAxis, plot],
        [null, null, xAxis],
        [null, null, xLabel]
    ]);

    // Render it
    table.renderTo('#coverageChart');

    var hover = new Plottable.Interaction.Hover();
    hover.onHoverOver(function(hoverData) {
        var xString = hoverData.data[0].x;
        var yString = hoverData.data[0].y.toLocaleString();
        title.text(yString + " opinions in "+ xString);
    });
    hover.onHoverOut(function() {
        title.text(parseInt(data.total, 10).toLocaleString() + ' Opinions');
    });
    plot.registerInteraction(hover);

    var click = new Plottable.Interaction.Click();
    click.callback(function(p) {
        var bars = plot.getBars(p.x, p.y),
            year,
            prec = '',
            i;
        if (bars[0].length) {
            year = bars.data()[0].x;
            for (i = 0; i < precedentTypes.length; i++) {
                prec += '&' + precedentTypes[i] + '=on';
            }
            window.location.href = '/?filed_after=' + year +
                '&filed_before=' + year + 
                prec + 
                ((hash !== 'all') ? '&court=' + hash : '');
        }
    });
    plot.registerInteraction(click);
}

// Do this when the hash of the page changes (i.e. at page load or when a select is chosen.
$(window).hashchange(function() {
    hash = window.location.hash.substr(1);
{'fraction_non_alphanumeric': 0.14600591715976333, 'fraction_numerical': 0.00606508875739645, 'mean_word_length': 2.2256679389312977, 'pattern_counts': {'":': 0, '<': 6, '<?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': '7575782', 'n_tokens_mistral': 2202, 'n_tokens_neox': 2139, 'n_words': 458}