<commit_before>var legendspacing = {x: 25, y: 15};

var group_axis = d3.svg.axis()
	.scale(d3.scale.ordinal()
		.domain(["V", "P"])
		.rangeRoundPoints([15,40]))
	.orient("left");

var mismatch_axis = d3.svg.axis() //axis for stacked bar charts
	.scale(d3.scale.linear()
		.domain([0,1])
		.range([0, barwidth]))
	.orient("bottom")
	.ticks(5)
	.tickFormat(d3.format(".0%"));

var sites_svg = d3.select(".stacked-bars-export-zone") //holds all the stacked bar charts
	.append("svg")
	/*.attr("width", barchartwidth + barchartmargin.left + barchartmargin.right)
	.attr("height", 0)*/
	.attr('viewBox', "0 0 " + (barchartwidth + barchartmargin.left + barchartmargin.right) + " 0")
    .attr('preserveAspectRatio',"xMinYMin meet")
	.attr("title", "Amino Acid Site Mismatches")
	.attr("version", 1.1)
	.attr("xmlns", "http://www.w3.org/2000/svg")
	.attr("shape-rendering", "crispEdges");

sites_svg.append("style")
	.attr("type", "text/css")
	.text("text { font-size: 10px; font-family: sans-serif;}" +
		".aatitle { font-weight: bold; }" +
		".axis line, .axis path { stroke: #000; fill: none; }");
// The styling goes here instead of the CSS file so that the SVG
// will export with it.

var export_button = d3.select("#export-charts")
	.on("click", export_AAsites);
var color_selector = d3.select("#color_selector")
	.on("input", update_aasite_colors);

function update_AAsites(sites)
{
	/*	This is the main routine to build the collection of stacked bar charts.
		Given a list of sites, it adds charts for new sites, removes charts
		for missing sites, and does nothing for the rest.	*/
	selected_sites = sites;
	//Use enter() and exit() to create, move, and remove AA site charts around
	var AAsites = sites_svg.selectAll(".AAsite")
		.data(sites, function(d) { return d; });
	sites_svg.transition() //makes the svg resize to fit charts
		.attr("viewBox", "0 0 " + (barchartwidth + barchartmargin.left + barchartmargin.right) + " " + AAsites[0].length*(barchartheight + barchartmargin.top + barchartmargin.bottom));
		/*.attr("height", AAsites[0].length*(barchartheight + barchartmargin.top + barchartmargin.bottom));*/
	
	AAsites.transition() //moves charts which are staying to accomadate new/removed charts
		.attr("transform", AAsite_translate);
	
	AAsites.exit().transition() //animates a removal by pushing chart downwards while scaling y component to 0
		.attr("transform", function(d, i) { return AAsite_shrink(d,i+1); })
		.remove();
		
	AAsites.enter().append("g")
		.attr("class", "AAsite")
		.attr("transform", AAsite_shrink) //start with 0 y scaling
		.each(create_AAsite_chart)
		.transition()
		.attr("transform", AAsite_translate); //scale y component from 0 to 1
}

function create_AAsite_chart(site)
{
	//Create a viz of two stacked horizontal stacked bar charts.
	//Passed the location to append viz and the index of the site of interest
	var prev = {}; //stores joint prevelance
	var vacnest = d3.nest()
	//count aas of each type at this site
	//Returns an array [{key: AA, values: count}, ...]
		.key(function(d) { return d; })
		.rollup(function(d) { return d.length; })
		.entries(sequences.vaccine[site].filter(function(d) {
			return d != vaccine.sequence[site];
		}));
	var placnest = d3.nest()
		.key(function(d, i) { return d; })
		.rollup(function(d) { return d.length; })
		.entries(sequences.placebo[site].filter(function(d) {
			return d!= vaccine.sequence[site];
		}));
	
		//compute joint prevalence
		vacnest.forEach(function(d)
		{
			prev[d.key] = d.values;
		});
		placnest.forEach(function(d)
		{
			if (prev[d.key])
			{
				prev[d.key] += d.values;
			} else {
				prev[d.key] = d.values;
			}
		});
	
	vacnest.sort(sort_nest);
	placnest.sort(sort_nest);
	var svg = d3.select(this);
	
	svg.append("g")
		.attr("class", "group axis")
		.call(group_axis);
	create_stacked_bar(svg, vacnest, vac_scale, 0);
	create_stacked_bar(svg, placnest, plac_scale, 25);
	svg.append("g")
		.attr("transform", "translate(10,55)")
		.attr("class", "mismatch axis")
		.call(mismatch_axis);
	
	//Create title
	svg.append("text")
		.attr("class", "aatitle")
		.attr("text-anchor", "middle")
		.attr("x", barchartwidth/2)
		.attr("y", 0)
		.text("Env " + display_idx_map[site] + " (" + vaccine.sequence[site]+ ") Mismatches (p=" + siteStats[dist_metric]["pvalue"][site].toPrecision(2) + ")");
	
	//Create legend
	var acids = d3.set(); //assemble list of amino acids present in chart
	vacnest.forEach(function(d) { acids.add(d.key); });
	placnest.forEach(function(d) { acids.add(d.key); });
	acids = acids.values().sort(sort_keys); //output and sort the final array (which now has no duplicates)
	var legend = svg.append("g")<commit_msg>Fix protein label on stacked bars<commit_after>var legendspacing = {x: 25, y: 15};

var group_axis = d3.svg.axis()
	.scale(d3.scale.ordinal()
		.domain(["V", "P"])
		.rangeRoundPoints([15,40]))
	.orient("left");

var mismatch_axis = d3.svg.axis() //axis for stacked bar charts
	.scale(d3.scale.linear()
		.domain([0,1])
		.range([0, barwidth]))
	.orient("bottom")
	.ticks(5)
	.tickFormat(d3.format(".0%"));

var sites_svg = d3.select(".stacked-bars-export-zone") //holds all the stacked bar charts
	.append("svg")
	/*.attr("width", barchartwidth + barchartmargin.left + barchartmargin.right)
	.attr("height", 0)*/
	.attr('viewBox', "0 0 " + (barchartwidth + barchartmargin.left + barchartmargin.right) + " 0")
    .attr('preserveAspectRatio',"xMinYMin meet")
	.attr("title", "Amino Acid Site Mismatches")
	.attr("version", 1.1)
	.attr("xmlns", "http://www.w3.org/2000/svg")
	.attr("shape-rendering", "crispEdges");

sites_svg.append("style")
	.attr("type", "text/css")
	.text("text { font-size: 10px; font-family: sans-serif;}" +
		".aatitle { font-weight: bold; }" +
		".axis line, .axis path { stroke: #000; fill: none; }");
// The styling goes here instead of the CSS file so that the SVG
// will export with it.

var export_button = d3.select("#export-charts")
	.on("click", export_AAsites);
var color_selector = d3.select("#color_selector")
	.on("input", update_aasite_colors);

function update_AAsites(sites)
{
	/*	This is the main routine to build the collection of stacked bar charts.
		Given a list of sites, it adds charts for new sites, removes charts
		for missing sites, and does nothing for the rest.	*/
	selected_sites = sites;
	//Use enter() and exit() to create, move, and remove AA site charts around
	var AAsites = sites_svg.selectAll(".AAsite")
		.data(sites, function(d) { return d; });
	sites_svg.transition() //makes the svg resize to fit charts
		.attr("viewBox", "0 0 " + (barchartwidth + barchartmargin.left + barchartmargin.right) + " " + AAsites[0].length*(barchartheight + barchartmargin.top + barchartmargin.bottom));
		/*.attr("height", AAsites[0].length*(barchartheight + barchartmargin.top + barchartmargin.bottom));*/
	
	AAsites.transition() //moves charts which are staying to accomadate new/removed charts
		.attr("transform", AAsite_translate);
	
	AAsites.exit().transition() //animates a removal by pushing chart downwards while scaling y component to 0
		.attr("transform", function(d, i) { return AAsite_shrink(d,i+1); })
		.remove();
		
	AAsites.enter().append("g")
		.attr("class", "AAsite")
		.attr("transform", AAsite_shrink) //start with 0 y scaling
		.each(create_AAsite_chart)
		.transition()
		.attr("transform", AAsite_translate); //scale y component from 0 to 1
}

function create_AAsite_chart(site)
{
	//Create a viz of two stacked horizontal stacked bar charts.
	//Passed the location to append viz and the index of the site of interest
	var prev = {}; //stores joint prevelance
	var vacnest = d3.nest()
	//count aas of each type at this site
	//Returns an array [{key: AA, values: count}, ...]
		.key(function(d) { return d; })
		.rollup(function(d) { return d.length; })
		.entries(sequences.vaccine[site].filter(function(d) {
			return d != vaccine.sequence[site];
		}));
	var placnest = d3.nest()
		.key(function(d, i) { return d; })
		.rollup(function(d) { return d.length; })
		.entries(sequences.placebo[site].filter(function(d) {
			return d!= vaccine.sequence[site];
		}));
	
		//compute joint prevalence
		vacnest.forEach(function(d)
		{
			prev[d.key] = d.values;
		});
		placnest.forEach(function(d)
		{
			if (prev[d.key])
			{
				prev[d.key] += d.values;
			} else {
				prev[d.key] = d.values;
			}
		});
	
	vacnest.sort(sort_nest);
	placnest.sort(sort_nest);
	var svg = d3.select(this);
	
	svg.append("g")
		.attr("class", "group axis")
		.call(group_axis);
	create_stacked_bar(svg, vacnest, vac_scale, 0);
	create_stacked_bar(svg, placnest, plac_scale, 25);
	svg.append("g")
		.attr("transform", "translate(10,55)")
		.attr("class", "mismatch axis")
		.call(mismatch_axis);
	
	//Create title
	svg.append("text")
		.attr("class", "aatitle")
		.attr("text-anchor", "middle")
		.attr("x", barchartwidth/2)
		.attr("y", 0)
		.text(protein + " " + display_idx_map[site] + " (" + vaccine.sequence[site]+ ") Mismatches (p=" + siteStats[dist_metric]["pvalue"][site].toPrecision(2) + ")");
	
	//Create legend
	var acids = d3.set(); //assemble list of amino acids present in chart
	vacnest.forEach(function(d) { acids.add(d.key); });
	placnest.forEach(function(d) { acids.add(d.key); });
	acids = acids.values().sort(sort_keys); //output and sort the final array (which now has no duplicates)
	var legend = svg.append("g")
{'fraction_non_alphanumeric': 0.1736103673556817, 'fraction_numerical': 0.012852093820284889, 'mean_word_length': 4.228443449048152, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5473194', 'n_tokens_mistral': 3650, 'n_tokens_neox': 3325, 'n_words': 816}