<commit_before>(function (window) {

	var opts = {
		width: 600,
		height: 400,
		topMargin: 15,
		outerMargin: 15,
		labelSpace: 0,
		gapSpaceBars: 2,
		baseColor: "#a7b6c1",
		highlightColor: "#a14538",
		dataRange: 29000,
		titleLabel: "",
		titleFont: "bold 10pt Arial,sans-serif",
		showValues: true,
		valuesFont: "bold 8pt Arial,sans-serif",
		formatValues: undefined,
		leftLabel: "",
		leftLabelFont: "bold 8pt Arial,sans-serif",
		rightLabel: "",
		rightLabelFont: "bold 8pt Arial,sans-serif",
		showCategory: true,
		categoryFont: "8pt Arial,sans-serif",
		mouseHoverBars: undefined,
		clickAction: undefined,
	};

	/**
	 * Overwrites obj1's values with obj2's and adds obj2's if non existent in obj1
	 * @param obj1
	 * @param obj2
	 * @returns obj3 a new object based on obj1 and obj2
	 */
	function _mergeOptions(obj1, obj2){
	    var obj3 = {};
	    for (var attrname in obj1) { if(obj1[attrname]!=undefined) obj3[attrname] = obj1[attrname]; }
	    for (var attrname in obj2) { if(obj2[attrname]!=undefined) obj3[attrname] = obj2[attrname]; }
	    return obj3;
	}

	_processChartData = function(data){
		var chartData=[];
		var max = 0;
		for(var i=0;i<data.resultset.length;i++){
			var maxRow = ((data.resultset[i][1]>data.resultset[i][2])?data.resultset[i][1]:data.resultset[i][2]);
			max = max>maxRow?max:maxRow;
			chartData.push({ "sharedLabel": data.resultset[i][0], "barData1": data.resultset[i][1], "barData2": data.resultset[i][2]});
		}
		return [chartData,max];
	};

	function PyramidChart(options) {
		this.options = _mergeOptions(opts, options||opts);
		if(!this.options.data){ console.log("No data found!"); throw "No data found!";}
		var dataProcessed = _processChartData(this.options.data);
		this.options.chartData = dataProcessed[0];
		this.options.dataRange = dataProcessed[1]*2.5;
	}

	PyramidChart.prototype.update = function(options){
		if(options) this.options = _mergeOptions(this.options, options||this.options);
		window.document.getElementById(this.options.htmlObjectChart).textContent = "";
		this.render();
	};

	PyramidChart.prototype.render = function(){
		if(this.options.leftLabel == "" && this.options.rightLabel == ""){
			this.options.leftLabel = this.options.data.metadata[1].colName;
			this.options.rightLabel = this.options.data.metadata[2].colName;
		}
		if(!this.options.showCategory){
			this.options.labelSpace = 0;
		}
		this.options.innerMargin = (this.options.width/2) + this.options.labelSpace;

		var options = this.options;

		/* edit with care */
		var chartWidth = (options.width-options.innerMargin-options.outerMargin)*2,
			barWidth = (options.height)/options.chartData.length,
			yScale = pv.Scale.linear(0, options.chartData.length).range(0, options.height-options.topMargin),
			total = pv.Scale.linear(0, options.dataRange).range(0,chartWidth),
			commas = pv.Format.number(),
			activeBar = -1
			currObj = null;

		/* main panel */
		var vis = new pv.Panel().width(options.width).height(options.height).canvas(options.htmlObjectChart)
			.event("mousemove", pv.Behavior.point(Infinity).collapse("x"))
			.event("click", function() {
				if(typeof options.clickAction=="function"){
			    	return options.clickAction(currObj);
				}
				return
			});
			
			/* barData1 label */
			vis.add(pv.Label)
				.data([options.leftLabel])
				.top(options.topMargin-3)
				.left(options.width-options.innerMargin) 
				.textAlign("right")		
				.font(options.leftLabelFont);
				
			/* barData2 label */
			vis.add(pv.Label)
				.data([options.rightLabel])<commit_msg>Improve Comparison Chart / Pyramid #25 issue fixed<commit_after>(function (window) {

	var opts = {
		width: 600,
		height: 400,
		topMargin: 50,
		outerMargin: 15,
		labelSpace: 0,
		gapSpaceBars: 2,
		baseColor: "#a7b6c1",
		highlightColor: "#a14538",
		dataRange: 29000,
		titleLabel: "",
		titleFont: "bold 10pt Arial,sans-serif",
		showValues: true,
		valuesFont: "bold 8pt Arial,sans-serif",
		formatValues: undefined,
		leftLabel: "",
		leftLabelFont: "bold 8pt Arial,sans-serif",
		rightLabel: "",
		rightLabelFont: "bold 8pt Arial,sans-serif",
		showCategory: true,
		categoryFont: "8pt Arial,sans-serif",
		mouseHoverBars: undefined,
		clickAction: undefined,
	};

	/**
	 * Overwrites obj1's values with obj2's and adds obj2's if non existent in obj1
	 * @param obj1
	 * @param obj2
	 * @returns obj3 a new object based on obj1 and obj2
	 */
	function _mergeOptions(obj1, obj2){
	    var obj3 = {};
	    for (var attrname in obj1) { if(obj1[attrname]!=undefined) obj3[attrname] = obj1[attrname]; }
	    for (var attrname in obj2) { if(obj2[attrname]!=undefined) obj3[attrname] = obj2[attrname]; }
	    return obj3;
	}

	_processChartData = function(data){
		var chartData=[];
		var max = 0;
		for(var i=0;i<data.resultset.length;i++){
			var maxRow = ((data.resultset[i][1]>data.resultset[i][2])?data.resultset[i][1]:data.resultset[i][2]);
			max = max>maxRow?max:maxRow;
			chartData.push({ "sharedLabel": data.resultset[i][0], "barData1": data.resultset[i][1], "barData2": data.resultset[i][2]});
		}
		return [chartData,max];
	};

	function PyramidChart(options) {
		this.options = _mergeOptions(opts, options||opts);
		if(!this.options.data){ console.log("No data found!"); throw "No data found!";}
		var dataProcessed = _processChartData(this.options.data);
		this.options.chartData = dataProcessed[0];
		this.options.dataRange = dataProcessed[1]*2.5;
	}

	PyramidChart.prototype.update = function(options){
		if(options) this.options = _mergeOptions(this.options, options||this.options);
		window.document.getElementById(this.options.htmlObjectChart).textContent = "";
		this.render();
	};

	PyramidChart.prototype.render = function(){
		if(this.options.leftLabel == "" && this.options.rightLabel == ""){
			this.options.leftLabel = this.options.data.metadata[1].colName;
			this.options.rightLabel = this.options.data.metadata[2].colName;
		}
		if(!this.options.showCategory){
			this.options.labelSpace = 0;
		}
		this.options.innerMargin = (this.options.width/2) + this.options.labelSpace;

		var options = this.options;

		/* edit with care */
		var chartWidth = (options.width-options.innerMargin-options.outerMargin)*2,
			barWidth = (options.height)/options.chartData.length,
			yScale = pv.Scale.linear(0, options.chartData.length).range(0, options.height-options.topMargin),
			total = pv.Scale.linear(0, options.dataRange).range(0,chartWidth),
			commas = pv.Format.number(),
			activeBar = -1
			currObj = null;

		/* main panel */
		var vis = new pv.Panel().width(options.width).height(options.height).canvas(options.htmlObjectChart)
			.event("mousemove", pv.Behavior.point(Infinity).collapse("x"))
			.event("click", function() {
				if(typeof options.clickAction=="function"){
			    	return options.clickAction(currObj);
				}
				return
			});

			vis.add(pv.Label)
				.top(15)
				.textAlign("center")
				.data([options.titleLabel])
				.font(options.titleFont);
			
			/* barData1 label */
			vis.add(pv.Label)
				.data([options.leftLabel])
				.top(options.topMargin-3)
				.left(options.width-options.innerMargin) 
				.textAlign("right")		
				.font(options.leftLabelFont);
				
			/* barData2 label */
			vis.add(pv.Label)
				.data([options.rightLabel])
{'fraction_non_alphanumeric': 0.1585787363472971, 'fraction_numerical': 0.022673855938061663, 'mean_word_length': 4.174535050071531, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 7, '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': '365179', 'n_tokens_mistral': 2876, 'n_tokens_neox': 2516, 'n_words': 450}