<commit_before>(function (exports) {
    catcorr.version = "0.2.0";

    exports.catcorr = catcorr;
    function catcorr(div_id, data) {
        var questions = data.questions;
        var responses = data.responses;

        // create the label2index lookup for quickly calculating the
        // x-coordinate on survey answers
        var label2index = {};
        questions.forEach(function (q) {
            label2index[q.number] = {};
            q.choices.forEach(function (choice, j) {
                label2index[q.number][choice] = j;
            });
        });

        // re-cast non-numeric answers into the corresponding number in
        // label2index so that this whole crossfilter bizness works
        responses.forEach(function (r) {
            questions.forEach(function (q) {
                r[q.number] = label2index[q.number][r[q.number]];
            });
        });

        // add the questions text
        questions.forEach(function (q) {
            d3.select(div_id)
                .append("div")
                .attr("id", q.number+"-chart")
                .attr("class", "catcorr chart")
                .append("div")
                .attr("class", "title")
                .text(q.number+'. '+q.text);
        });

        // Various formatters.
        var formatNumber = d3.format(",d");

        // Create the crossfilter for the relevant dimensions and groups.
        var respondents = crossfilter(responses),
        all = respondents.groupAll();
        var dimensions = [];
        var groups = [];
        questions.forEach(function (q, i) {
            dimensions.push(respondents.dimension(function(d){return d[q.number]}));
            groups.push(dimensions[i].group());
        });

        // record the total number of respondents in each group. this is
        // used later to correctly figure out the proportionPath lines
        // below
        groups.forEach(function (g) {
            g.__all__ = g.all().map(function (o) {return o.value});
        });

        // create a chart for each dimension
        var xscales = [], xscale;
	var yscale = d3.scale.linear().range([100,0]);
	var tooltips = [], tooltip;
        var charts = [], chart;
        var bar_width = 80;
	var bar_gap = 2;
        questions.forEach(function (q, i) {

            // get the labels for this axis
            var labels = {};
            q.choices.forEach(function (choice, c) {
                labels[c] = choice;
            });

	    // initialize the tooltips if d3.tip is included
	    if (d3.tip) {
		tooltip = d3.tip()
		    .attr('class', 'd3-tip')
		    .direction('s')
		    .html(function (d) {return "awesome " + d});
		tooltips.push(tooltip);
	    }

            // create the scale
            var a=0, b=q.choices.length-1;
            xscale = d3.scale.linear()
                .domain([-0.5, b+0.5])
                .rangeRound([0, bar_width*((b-a)+1)])
            xscale.labels = labels;
            xscales.push(xscale);

            // update the yscale to have the maximal possible domain
            // so that heights (and areas) on each of the charts mean
            // the same thing
	    yscale.domain([0, d3.max([
		yscale.domain()[1], groups[i].top(1)[0].value
	    ])])

            // create the chart
            chart = barChart(q).dimension(dimensions[i])
                .group(groups[i])
                .x(xscale);
            charts.push(chart);

        });

        // Given our array of charts, which we assume are in the same
        // order as the .chart elements in the DOM, bind the charts to
        // the DOM and render them.  We also listen to the chart's
        // brush events to update the display.
        var chart = d3.selectAll(".catcorr.chart")
            .data(charts)
            .each(function(chart) {
                chart.on("brush", renderAll)
                    .on("brushend", renderAll);
            });

        // add an <aside> element that displays fraction of elements
        // currently selected
        var legend = d3.select(div_id)
            .append("aside")
            .attr("id", "legend")
            .attr("class", "catcorr")
            .html("<div style='clear:both;margin-top:20px'></div>"+
		  "you've selected <br/> <span id='active'>-</span> "+
		  "<span>/</span> <span id='total'>-</span> <br/> respondents");
	var legend_width=200, legend_height=120;
	var legend_svg = legend.insert("svg", "div")
            .attr("width", legend_width)
            .attr("height", legend_height)
            .append("g")
            .attr("transform", "translate(0,0)");

	// draw the bars on the legend
	legend_svg.selectAll(".bar")
            .data(["all_background", "background", "foreground",
                   "all_proportion"])
            .enter().append("path")
            .attr("class", function(d, i) {
                if (i===0){
                    return "catcorr "+d+" all_bar outcome";
                }
                else if(i===3) {
                    return "catcorr "+d+" all_bar outcome";
                }
                return "catcorr "+d+" bar outcome";
            });
	legend_svg.select(".all_background.all_bar")
	    .attr("d", ["M",(legend_width-(bar_width-2*bar_gap))/2,",",10,"v",100,"h",bar_width-2*bar_gap,"v",-100].join(""));
	legend_svg.select(".foreground.bar")
	    .attr("d", ["M",(legend_width-(bar_width-2*bar_gap))/2,",",80,"v",30,"h",bar_width-2*bar_gap,"v",-30].join(""));
	legend_svg.select(".all_proportion.all_bar")
	    .attr("d", ["M",(legend_width-(bar_width-2*bar_gap))/2,",",40,"h",bar_width-2*bar_gap, "M", legend_width/2,",",15,"v",44].join(""));

	// display all respondents label
	legend_svg.append("text")
	    .attr("class", "catcorr legend")
	    .attr("x", legend_width/2+bar_width/2+bar_gap)
	    .attr("y", 10)
	    .text("all");
	legend_svg.append("path")
	    .attr("class", "catcorr legend")
	    .attr("d", ["M",legend_width/2+bar_width/2,",",7,
			"h",-15,"l",-7,",",7].join(""));

	// display selected respondents label
	legend_svg.append("text")
	    .attr("class", "catcorr legend")
	    .attr("x", legend_width/2+bar_width/2+bar_gap)
	    .attr("y", 116)
	    .text("selected");
	legend_svg.append("path")
	    .attr("class", "catcorr legend")
	    .attr("d", ["M",legend_width/2+bar_width/2,",",113,
			"h",-15,"l",-7,",",-7].join(""));

	// display expected selected respondents label
	legend_svg.append("text")
	    .attr("class", "catcorr legend")
	    .attr("x", legend_width/2+bar_width/2+bar_gap)
	    .attr("y", 50)
	    .text("expected");
	legend_svg.append("path")
	    .attr("class", "catcorr legend")
	    .attr("d", ["M",legend_width/2+bar_width/2,",",47,
			"h",-15,"l",-7,",",-7].join(""));

	// display variation in expected selected respondents label
	legend_svg.append("text")
	    .attr("class", "catcorr legend")
	    .attr("x", legend_width/2-bar_width/2-20)
	    .attr("y", 39)
	    .attr("text-anchor", "end")
	    .text("variation");
	legend_svg.append("path")
	    .attr("class", "catcorr legend")
	    .attr("d", ["M",legend_width/2-bar_width/2-18,",",36,
			"h",15,"v",22,"h",42,
			"M",legend_width/2-bar_width/2-3,",",36,
			"v",-22,"h",42].join(""));

	    // .attr("d", ["M",(legend_width-(bar_width-2*bar_gap))/2,",",40,"h",bar_width-2*bar_gap, "M", legend_width/2,",",15,"v",45].join(""));


        // Render the total.
        d3.selectAll("aside.catcorr #total")
            .text(formatNumber(respondents.size()));

        renderAll();

        // Renders the specified chart or list.
        function render(method) {
            d3.select(this).call(method);
        }

        // Whenever the brush moves, re-rendering everything.
        function renderAll() {
            chart.each(render);
            d3.select("aside.catcorr #active").text(formatNumber(all.value()));
        }

        window.filter = function(filters) {
            filters.forEach(function(d, i) { charts[i].filter(d); });
            renderAll();<commit_msg>more copy for @misterburton<commit_after>(function (exports) {
    catcorr.version = "0.2.0";

    exports.catcorr = catcorr;
    function catcorr(div_id, data) {
        var questions = data.questions;
        var responses = data.responses;

        // create the label2index lookup for quickly calculating the
        // x-coordinate on survey answers
        var label2index = {};
        questions.forEach(function (q) {
            label2index[q.number] = {};
            q.choices.forEach(function (choice, j) {
                label2index[q.number][choice] = j;
            });
        });

        // re-cast non-numeric answers into the corresponding number in
        // label2index so that this whole crossfilter bizness works
        responses.forEach(function (r) {
            questions.forEach(function (q) {
                r[q.number] = label2index[q.number][r[q.number]];
            });
        });

        // add the questions text
        questions.forEach(function (q) {
            d3.select(div_id)
                .append("div")
                .attr("id", q.number+"-chart")
                .attr("class", "catcorr chart")
                .append("div")
                .attr("class", "title")
                .text(q.number+'. '+q.text);
        });

        // Various formatters.
        var formatNumber = d3.format(",d");

        // Create the crossfilter for the relevant dimensions and groups.
        var respondents = crossfilter(responses),
        all = respondents.groupAll();
        var dimensions = [];
        var groups = [];
        questions.forEach(function (q, i) {
            dimensions.push(respondents.dimension(function(d){return d[q.number]}));
            groups.push(dimensions[i].group());
        });

        // record the total number of respondents in each group. this is
        // used later to correctly figure out the proportionPath lines
        // below
        groups.forEach(function (g) {
            g.__all__ = g.all().map(function (o) {return o.value});
        });

        // create a chart for each dimension
        var xscales = [], xscale;
	var yscale = d3.scale.linear().range([100,0]);
	var tooltips = [], tooltip;
        var charts = [], chart;
        var bar_width = 80;
	var bar_gap = 2;
        questions.forEach(function (q, i) {

            // get the labels for this axis
            var labels = {};
            q.choices.forEach(function (choice, c) {
                labels[c] = choice;
            });

	    // initialize the tooltips if d3.tip is included
	    if (d3.tip) {
		tooltip = d3.tip()
		    .attr('class', 'd3-tip')
		    .direction('s')
		    .html(function (d) {return "awesome " + d});
		tooltips.push(tooltip);
	    }

            // create the scale
            var a=0, b=q.choices.length-1;
            xscale = d3.scale.linear()
                .domain([-0.5, b+0.5])
                .rangeRound([0, bar_width*((b-a)+1)])
            xscale.labels = labels;
            xscales.push(xscale);

            // update the yscale to have the maximal possible domain
            // so that heights (and areas) on each of the charts mean
            // the same thing
	    yscale.domain([0, d3.max([
		yscale.domain()[1], groups[i].top(1)[0].value
	    ])])

            // create the chart
            chart = barChart(q).dimension(dimensions[i])
                .group(groups[i])
                .x(xscale);
            charts.push(chart);

        });

        // Given our array of charts, which we assume are in the same
        // order as the .chart elements in the DOM, bind the charts to
        // the DOM and render them.  We also listen to the chart's
        // brush events to update the display.
        var chart = d3.selectAll(".catcorr.chart")
            .data(charts)
            .each(function(chart) {
                chart.on("brush", renderAll)
                    .on("brushend", renderAll);
            });

        // add an <aside> element that displays fraction of elements
        // currently selected
        var legend = d3.select(div_id)
            .append("aside")
            .attr("id", "legend")
            .attr("class", "catcorr")
            .html("<div style='clear:both;margin-top:20px'></div>"+
		  "you've selected <br/> <span id='active'>-</span> "+
		  "<span>/</span> <span id='total'>-</span> <br/> respondents");
	var legend_width=200, legend_height=120;
	var legend_svg = legend.insert("svg", "div")
            .attr("width", legend_width)
            .attr("height", legend_height)
            .append("g")
            .attr("transform", "translate(0,0)");

	// draw the bars on the legend
	legend_svg.selectAll(".bar")
            .data(["all_background", "background", "foreground",
                   "all_proportion"])
            .enter().append("path")
            .attr("class", function(d, i) {
                if (i===0){
                    return "catcorr "+d+" all_bar outcome";
                }
                else if(i===3) {
                    return "catcorr "+d+" all_bar outcome";
                }
                return "catcorr "+d+" bar outcome";
            });
	legend_svg.select(".all_background.all_bar")
	    .attr("d", ["M",(legend_width-(bar_width-2*bar_gap))/2,",",10,"v",100,"h",bar_width-2*bar_gap,"v",-100].join(""));
	legend_svg.select(".foreground.bar")
	    .attr("d", ["M",(legend_width-(bar_width-2*bar_gap))/2,",",80,"v",30,"h",bar_width-2*bar_gap,"v",-30].join(""));
	legend_svg.select(".all_proportion.all_bar")
	    .attr("d", ["M",(legend_width-(bar_width-2*bar_gap))/2,",",40,"h",bar_width-2*bar_gap, "M", legend_width/2,",",15,"v",44].join(""));

	// display all respondents label
	legend_svg.append("text")
	    .attr("class", "catcorr legend")
	    .attr("x", legend_width/2+bar_width/2+bar_gap)
	    .attr("y", 10)
	    .text("all respondents");
	legend_svg.append("path")
	    .attr("class", "catcorr legend")
	    .attr("d", ["M",legend_width/2+bar_width/2,",",7,
			"h",-15,"l",-7,",",7].join(""));

	// display selected respondents label
	legend_svg.append("text")
	    .attr("class", "catcorr legend")
	    .attr("x", legend_width/2+bar_width/2+bar_gap)
	    .attr("y", 116)
	    .text("selected respondents");
	legend_svg.append("path")
	    .attr("class", "catcorr legend")
	    .attr("d", ["M",legend_width/2+bar_width/2,",",113,
			"h",-15,"l",-7,",",-7].join(""));

	// display expected selected respondents label
	legend_svg.append("text")
	    .attr("class", "catcorr legend")
	    .attr("x", legend_width/2+bar_width/2+bar_gap)
	    .attr("y", 50)
	    .text("expected number of selected respondents");
	legend_svg.append("path")
	    .attr("class", "catcorr legend")
	    .attr("d", ["M",legend_width/2+bar_width/2,",",47,
			"h",-15,"l",-7,",",-7].join(""));

	// display variation in expected selected respondents label
	legend_svg.append("text")
	    .attr("class", "catcorr legend")
	    .attr("x", legend_width/2-bar_width/2-20)
	    .attr("y", 39)
	    .attr("text-anchor", "end")
	    .text("variation in expected number of respondents");
	legend_svg.append("path")
	    .attr("class", "catcorr legend")
	    .attr("d", ["M",legend_width/2-bar_width/2-18,",",36,
			"h",15,"v",22,"h",42,
			"M",legend_width/2-bar_width/2-3,",",36,
			"v",-22,"h",42].join(""));

	    // .attr("d", ["M",(legend_width-(bar_width-2*bar_gap))/2,",",40,"h",bar_width-2*bar_gap, "M", legend_width/2,",",15,"v",45].join(""));


        // Render the total.
        d3.selectAll("aside.catcorr #total")
            .text(formatNumber(respondents.size()));

        renderAll();

        // Renders the specified chart or list.
        function render(method) {
            d3.select(this).call(method);
        }

        // Whenever the brush moves, re-rendering everything.
        function renderAll() {
            chart.each(render);
            d3.select("aside.catcorr #active").text(formatNumber(all.value()));
        }

        window.filter = function(filters) {
            filters.forEach(function(d, i) { charts[i].filter(d); });
            renderAll();
{'fraction_non_alphanumeric': 0.17487393388532652, 'fraction_numerical': 0.019672539376206187, 'mean_word_length': 2.136887326694005, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '162564', 'n_tokens_mistral': 5427, 'n_tokens_neox': 4934, 'n_words': 1031}