<commit_before>(function(){
	//you can make these global to inspect them
	var localResources = [],
		externalResources = [],
		allRessourcesCalc = [],
		fileTypes = [],
		fileTypesBySource = [],
		resources;

	//feature check gate
	if(window.performance && window.performance.getEntriesByType !== undefined) {
		resources = window.performance.getEntriesByType("resource");
	}else if(window.performance && window.performance.webkitGetEntriesByType !== undefined) {
		resources = window.performance.webkitGetEntriesByType("resource");
	}else{
		alert("Oups, looks like this browser does not support the Ressource Timing API\ncheck http://caniuse.com/#feat=resource-timing to see the ones supporting it \n\n");
		return;
	}
	
	//remove this bookmarklet from the result
	resources = resources.filter(function(currR){
		return !currR.name.match(/http[s]?\:\/\/nurun.github.io\/resourceTable\/.*/);
	});

	var newTag = function(tagName, id, text, css){
		var tag = document.createElement(tagName);
		tag.textContent = text || "";
		tag.style.cssText = css || "";
		tag.id = id || "";
		return tag;
	};

	var getItemCount = function(arr, keyName) {
		var counts = {},
			resultArr = [];

		arr.forEach(function(key){
			counts[key] = counts[key] ? counts[key]+1 : 1;
		});

		//pivot data
		for(var fe in counts){
			obj = {};
			obj[keyName||"key"] = fe;
			obj.count = counts[fe];

			resultArr.push(obj);
		}
		return resultArr.sort(function(a, b) {
			return a.count < b.count ? 1 : -1;
		});
	};


	function createPieChart(data, size){
		//inpired by http://jsfiddle.net/da5LN/62/

		var svgNs = "http://www.w3.org/2000/svg",
			chart = document.createElementNS(svgNs, "svg:svg"),
			unit = (Math.PI * 2) / 100,
			startAngle = 0; // init startAngle

		var getRandomColor = function() {
			var letters = '0123456789ABCDEF'.split(''),
				color = '#';
			for (var i = 0; i < 6; i++ ) {
				color += letters[Math.floor(Math.random() * 16)];
			}
			return color;
		};

		var createCircle = function(cx, cy, r, fill){
			var circle = document.createElementNS(svgNs, "circle");
			circle.setAttributeNS(null, "cx", cx);
			circle.setAttributeNS(null, "cy", cy);
			circle.setAttributeNS(null, "r",  r);
			circle.setAttributeNS(null, "fill", fill);
			return circle;
		};

		var createWedge = function(percentage, label, colour){
			var path = document.createElementNS(svgNs, "path"), // wedge path
				endAngle = startAngle + (percentage * unit - 0.001),
				x1 = (size/2) + (size/2) * Math.sin(startAngle),
				y1 = (size/2) - (size/2) * Math.cos(startAngle),
				x2 = (size/2) + (size/2) * Math.sin(endAngle),
				y2 = (size/2) - (size/2) * Math.cos(endAngle),
				big = (endAngle - startAngle > Math.PI) ? 1 : 0;

			var d = "M " + (size/2) + "," + (size/2) +	// Start at circle center
					" L " + x1 + "," + y1 +				// Draw line to (x1,y1)
					" A " + (size/2) + "," + (size/2) +	// Draw an arc of radius r
					" 0 " + big + " 1 " +				// Arc details...
					x2 + "," + y2 +						// Arc goes to to (x2,y2)
					" Z";								// Close path back to (cx,cy)
			path.setAttribute("d", d); // Set this path 
			path.setAttribute("fill", colour);

			var wedgeTitle = document.createElementNS(svgNs, "title");
			wedgeTitle.textContent = label;
			path.appendChild(wedgeTitle); // Add tile to wedge path

			// foreground circle
			startAngle = endAngle;

			return path;
		};
		
		//setup chart
		chart.setAttribute("width", size);
		chart.setAttribute("height", size);
		chart.setAttribute("viewBox", "0 0 " + size + " " + size);
		//chart.appendChild(createCircle(size/2, size/2, size/2, "#ebebeb")); // add Background circle

		//loop through data and create wedges
		data.forEach(function(dataObj){
			var label = dataObj.label + " (" + dataObj.count + ")";
			var wedge = createWedge(dataObj.perc, label, getRandomColor());
			chart.appendChild(wedge); // create and add wedge to chart
		});

		
		chart.appendChild(createCircle(size/2, size/2, (size*0.1), "#fff"));
		
		return chart;
	};


	//crunch the data
	allRessourcesCalc = resources.map(function(currR, i, arr){
		var urlFragments = currR.name.match(/:\/\/(.[^/]+)([^?]*)\??(.*)/),
			maybeFileName = urlFragments[2].split("/").pop(),
			fileExtension = maybeFileName.substr((Math.max(0, maybeFileName.lastIndexOf(".")) || Infinity) + 1);
		
		
		
		var currRes = {
			name : currR.name,
			domain : urlFragments[1],
			initiatorType : currR.initiatorType || fileExtension || "SourceMap or Not Defined",
			fileExtension : fileExtension || "XHR or Not Defined",
			loadtime : currR.duration,
			isLocalDomain : urlFragments[1] === location.host
		};

		if(currR.requestStart){
			currRes.requestStartDelay = currR.requestStart - currR.startTime;
			currRes.dns = currR.domainLookupEnd - currR.domainLookupStart;
			currRes.tcp = currR.connectEnd - currR.connectStart;
			currRes.ttfb = currR.responseStart - currR.startTime;
			currRes.requestDuration = currR.responseStart - currR.requestStart;
		}
		if(currR.secureConnectionStart){
			currRes.ssl = currR.connectEnd - currR.secureConnectionStart;
		}

		if(currRes.isLocalDomain){
			localResources.push(currRes);
		}else{<commit_msg>added lables to pie charts<commit_after>(function(){
	//you can make these global to inspect them
	var localResources = [],
		externalResources = [],
		allRessourcesCalc = [],
		fileTypes = [],
		fileTypesBySource = [],
		resources;

	//feature check gate
	if(window.performance && window.performance.getEntriesByType !== undefined) {
		resources = window.performance.getEntriesByType("resource");
	}else if(window.performance && window.performance.webkitGetEntriesByType !== undefined) {
		resources = window.performance.webkitGetEntriesByType("resource");
	}else{
		alert("Oups, looks like this browser does not support the Ressource Timing API\ncheck http://caniuse.com/#feat=resource-timing to see the ones supporting it \n\n");
		return;
	}
	var svgNs = "http://www.w3.org/2000/svg";

	//remove this bookmarklet from the result
	resources = resources.filter(function(currR){
		return !currR.name.match(/http[s]?\:\/\/nurun.github.io\/resourceTable\/.*/);
	});

	var newTag = function(tagName, id, text, css){
		var tag = document.createElement(tagName);
		tag.textContent = text || "";
		tag.style.cssText = css || "";
		tag.id = id || "";
		return tag;
	};

	var getItemCount = function(arr, keyName) {
		var counts = {},
			resultArr = [];

		arr.forEach(function(key){
			counts[key] = counts[key] ? counts[key]+1 : 1;
		});

		//pivot data
		for(var fe in counts){
			obj = {};
			obj[keyName||"key"] = fe;
			obj.count = counts[fe];

			resultArr.push(obj);
		}
		return resultArr.sort(function(a, b) {
			return a.count < b.count ? 1 : -1;
		});
	};


	function createPieChart(data, size){
		//inpired by http://jsfiddle.net/da5LN/62/

		var chart = document.createElementNS(svgNs, "svg:svg"),
			unit = (Math.PI * 2) / 100,
			startAngle = 0; // init startAngle

		var getRandomColor = function() {
			var letters = '0123456789ABCDEF'.split(''),
				color = '#';
			for (var i = 0; i < 6; i++ ) {
				color += letters[Math.floor(Math.random() * 16)];
			}
			return color;
		};

		var createCircle = function(cx, cy, r, fill){
			var circle = document.createElementNS(svgNs, "circle");
			circle.setAttributeNS(null, "cx", cx);
			circle.setAttributeNS(null, "cy", cy);
			circle.setAttributeNS(null, "r",  r);
			circle.setAttributeNS(null, "fill", fill);
			return circle;
		};

		var getNodeTextWidth = function(textNode){
			var tmp = document.createElementNS(svgNs, "svg:svg");
			tmp.style.visibility = "hidden";
			tmp.appendChild(textNode);
			document.body.appendChild(tmp);
			var nodeWidth = textNode.getBBox().width;
			tmp.parentNode.removeChild(tmp);
			return nodeWidth;
		};

		var createWedge = function(size, percentage, labelTxt, colour){
			var path = document.createElementNS(svgNs, "path"), // wedge path
				endAngle = startAngle + (percentage * unit - 0.001),
				labelAngle = startAngle + (percentage/2 * unit - 0.001),
				x1 = (size/2) + (size/2) * Math.sin(startAngle),
				y1 = (size/2) - (size/2) * Math.cos(startAngle),
				x2 = (size/2) + (size/2) * Math.sin(endAngle),
				y2 = (size/2) - (size/2) * Math.cos(endAngle),
				x3 = (size/2) + (size/2.3) * Math.sin(labelAngle),
				y3 = (size/2) - (size/2.3) * Math.cos(labelAngle),
				big = (endAngle - startAngle > Math.PI) ? 1 : 0;

			var d = "M " + (size/2) + "," + (size/2) +	// Start at circle center
					" L " + x1 + "," + y1 +				// Draw line to (x1,y1)
					" A " + (size/2) + "," + (size/2) +	// Draw an arc of radius r
					" 0 " + big + " 1 " +				// Arc details...
					x2 + "," + y2 +						// Arc goes to to (x2,y2)
					" Z";								// Close path back to (cx,cy)
			path.setAttribute("d", d); // Set this path 
			path.setAttribute("fill", colour);

			var wedgeTitle = document.createElementNS(svgNs, "title");
			wedgeTitle.textContent = labelTxt;
			path.appendChild(wedgeTitle); // Add tile to wedge path
			path.style.pointerEvents = "none"


			startAngle = endAngle;
			if(percentage > 10){
				var wedgeLabel = document.createElementNS(svgNs, "text");
				wedgeLabel.textContent = labelTxt;
				wedgeLabel.setAttribute("y", y3);
				wedgeLabel.style.textShadow = "0 0 2px #fff";
				wedgeLabel.style.pointerEvents = "none"

				if(endAngle < Math.PI){
					wedgeLabel.setAttribute("x", x3 - getNodeTextWidth(wedgeLabel));
				}else{
					wedgeLabel.setAttribute("x", x3);
				}

				return [path, wedgeLabel];
			}			
			return [path];
		};
		
		//setup chart
		chart.setAttribute("width", size);
		chart.setAttribute("height", size);
		chart.setAttribute("viewBox", "0 0 " + size + " " + size);
		var labelWrap = document.createElementNS(svgNs, "g");
		// chart.appendChild(createCircle(size/2, size/2, (size*0.05), "#fff"));

		//loop through data and create wedges
		data.forEach(function(dataObj){
			var label = dataObj.label + " (" + dataObj.count + ")";
			var wedgeAndLabel = createWedge(size, dataObj.perc, label, getRandomColor());
			chart.appendChild(wedgeAndLabel[0]);

			if(wedgeAndLabel[1]){
				labelWrap.appendChild(wedgeAndLabel[1]);
			}
		});

		// foreground circle
		chart.appendChild(createCircle(size/2, size/2, (size*0.05), "#fff"));
		chart.appendChild(labelWrap);
		return chart;
	};


	//crunch the data
	allRessourcesCalc = resources.map(function(currR, i, arr){
		var urlFragments = currR.name.match(/:\/\/(.[^/]+)([^?]*)\??(.*)/),
			maybeFileName = urlFragments[2].split("/").pop(),
			fileExtension = maybeFileName.substr((Math.max(0, maybeFileName.lastIndexOf(".")) || Infinity) + 1);
		
		var currRes = {
			name : currR.name,
			domain : urlFragments[1],
			initiatorType : currR.initiatorType || fileExtension || "SourceMap or Not Defined",
			fileExtension : fileExtension || "XHR or Not Defined",
			loadtime : currR.duration,
			isLocalDomain : urlFragments[1] === location.host
		};

		if(currR.requestStart){
			currRes.requestStartDelay = currR.requestStart - currR.startTime;
			currRes.dns = currR.domainLookupEnd - currR.domainLookupStart;
			currRes.tcp = currR.connectEnd - currR.connectStart;
			currRes.ttfb = currR.responseStart - currR.startTime;
			currRes.requestDuration = currR.responseStart - currR.requestStart;
		}
		if(currR.secureConnectionStart){
			currRes.ssl = currR.connectEnd - currR.secureConnectionStart;
		}

		if(currRes.isLocalDomain){
			localResources.push(currRes);
		}else{
{'fraction_non_alphanumeric': 0.16653526062198862, 'fraction_numerical': 0.01585632939115199, 'mean_word_length': 3.4128333977580207, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5127543', 'n_tokens_mistral': 4526, 'n_tokens_neox': 3905, 'n_words': 846}