<commit_before>
barchart = {}

barchart.draw = function(data, at) {

	getv = function(d, metric) {
		var mi = metric.split("/")
		if(mi.length == 1) {
			return d[metric]
		} else {
			return (d[mi[1]] != 0) ? (d[mi[0]] / d[mi[1]]) : 0
		}
	}
		
	var CHEIGHT = 600;
	var BWIDTH = 5;
	var BGAP = 2;
	var LEFTSPACE = 40;

	data.sort(function(da, db) { return getv(db, at.sort) - getv(da, at.sort)} )

	d3.selectAll("svg").remove();
	var chart = d3.select("#chart-wrapper").append("svg")
		.attr("class", "chart")
		.attr("width", (BWIDTH + BGAP) * data.length + LEFTSPACE)
		.attr("height", CHEIGHT + 5); /* to accomodate bottom label */
		
	var xscale = d3.scale.linear()
		.domain([0, data.length])
		.rangeRound([LEFTSPACE, (BWIDTH + BGAP) * data.length + LEFTSPACE])
		
	var yscale = d3.scale.linear()
		.domain([0, d3.max(data, function(d) { return getv(d, at.height) })])
		.rangeRound([CHEIGHT-1, 1]);

	var fscale = d3.scale.linear()
		.domain([0, d3.max(data, function(d) { return getv(d, at.shade) })])
		.range([100, 0]);

	var yaxis = d3.svg.axis()
		.scale(yscale)
		.orient("left")
		.ticks(10);
		
	chart.selectAll("line")
		.data(yscale.ticks(10))
		.enter().append("line")
		.attr("x1", function(td) { return xscale(0) })
		.attr("x2", function(td) { return xscale(data.length) })
		.attr("y1", yscale)
		.attr("y2", yscale)
		.style("stroke", "#ccc");

	chart.selectAll("rect")
		.data(data)
		.enter().append("rect")
		.attr("x", function(d, i) { return xscale(i) })
		.attr("y", function(d) { return yscale(getv(d, at.height)) })
		.attr("height", function(d) { return CHEIGHT -yscale(getv(d, at.height)) })
		.attr("width", BWIDTH)
		.attr("shape-rendering", "crispEdges")
		.style("fill", function(d) { return "hsl(200, 80%, " + fscale(getv(d, at.shade)) + "%)" })
		.call(tooltip());
				
	chart.append("g")
		.attr("class", "axis")
		.attr("transform", "translate(" + LEFTSPACE + ", 0)")
		.call(yaxis);
}
<commit_msg>Switched to helper function.<commit_after>
barchart = {}

barchart.draw = function(data, at) {

	var CHEIGHT = 600;
	var BWIDTH = 5;
	var BGAP = 2;
	var LEFTSPACE = 40;

	data.sort(function(da, db) { return CPM.getv(db, at.sort) - CPM.getv(da, at.sort)} )

	d3.selectAll("svg").remove();
	var chart = d3.select("#chart-wrapper").append("svg")
		.attr("class", "chart")
		.attr("width", (BWIDTH + BGAP) * data.length + LEFTSPACE)
		.attr("height", CHEIGHT + 5); /* to accomodate bottom label */
		
	var xscale = d3.scale.linear()
		.domain([0, data.length])
		.rangeRound([LEFTSPACE, (BWIDTH + BGAP) * data.length + LEFTSPACE])
		
	var yscale = d3.scale.linear()
		.domain([0, d3.max(data, function(d) { return CPM.getv(d, at.height) })])
		.rangeRound([CHEIGHT-1, 1]);

	var fscale = d3.scale.linear()
		.domain([0, d3.max(data, function(d) { return CPM.getv(d, at.shade) })])
		.range([100, 0]);

	var yaxis = d3.svg.axis()
		.scale(yscale)
		.orient("left")
		.ticks(10);
		
	chart.selectAll("line")
		.data(yscale.ticks(10))
		.enter().append("line")
		.attr("x1", function(td) { return xscale(0) })
		.attr("x2", function(td) { return xscale(data.length) })
		.attr("y1", yscale)
		.attr("y2", yscale)
		.style("stroke", "#ccc");

	chart.selectAll("rect")
		.data(data)
		.enter().append("rect")
		.attr("x", function(d, i) { return xscale(i) })
		.attr("y", function(d) { return yscale(CPM.getv(d, at.height)) })
		.attr("height", function(d) { return CHEIGHT -yscale(CPM.getv(d, at.height)) })
		.attr("width", BWIDTH)
		.attr("shape-rendering", "crispEdges")
		.style("fill", function(d) { return "hsl(200, 80%, " + fscale(CPM.getv(d, at.shade)) + "%)" })
		.call(tooltip());
				
	chart.append("g")
		.attr("class", "axis")
		.attr("transform", "translate(" + LEFTSPACE + ", 0)")
		.call(yaxis);
}

{'fraction_non_alphanumeric': 0.22931126534970636, 'fraction_numerical': 0.022957821676454885, 'mean_word_length': 3.859922178988327, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3697369', 'n_tokens_mistral': 1683, 'n_tokens_neox': 1526, 'n_words': 292}