<commit_before>/**
 * Creates a new textblock in the specified element.
 * @param element The element/group where the text block should be appended.
 * @constructor New text block where additional <tspan>'s can be applied to.
 */
webvowl.util.textElement = function (element) {

	var textElement = {},
		LINE_DISTANCE = 1,
		SUBTEXT_CSS_CLASS = "subtext",
		textBlock = element.append("text")
			.classed("text", true)
			.attr("text-anchor", "middle");

	/**
	 * Repositions the textblock according to its own offsetHeight.
	 */
	function repositionTextBlock() {
		// Nothing to do if no child elements exist
		var textBlockChildCount = textBlock.property("childElementCount");
		if (textBlockChildCount < 1) {
			return;
		}

		var textBlockHeight = getTextBlockHeight(textBlock);
		textBlock.attr("y", -textBlockHeight * 0.6 + "px");
	}

	/**
	 * Adds a new line of text to the element.
	 * @param text
	 */
	textElement.addTextline = function (text) {
		addTextline(text);
	};

	/**
	 * Adds a line of text in subproperty style.
	 * @param text
	 */
	textElement.addSubTextNode = function (text) {
		addTextline(text, SUBTEXT_CSS_CLASS, "(", ")");
	};

	/**
	 * Adds a line of text in equivalent node listing style.
	 * @param text
	 */
	textElement.addEquivalentSpan = function (text) {
		addTextline(text, SUBTEXT_CSS_CLASS, "[", "]");
	};

	function addTextline(text, subtextCssClass, prefix, postfix) {
		if (!text) {
			return;
		}

		var truncatedText, tspan;

		subtextCssClass = subtextCssClass || "text";
		truncatedText = text.truncate(element.datum().textWidth());

		tspan = textBlock.append("tspan")
			.classed("text", true)
			.classed(subtextCssClass, true)
			.text(applyPreAndPostFix(truncatedText, prefix, postfix), subtextCssClass)
			.attr("x", 0)
			.attr("dy", function () {
				var heightInPixels = getPixelHeightOfTextLine(d3.select(this)),
					siblingCount = textBlock.property("childElementCount") - 1,
					lineDistance = siblingCount > 0 ? LINE_DISTANCE : 0;
				return heightInPixels + lineDistance + "px";
			});


		repositionTextBlock();
	}

	function applyPreAndPostFix(text, prefix, postfix) {
		if (prefix) {
			text = prefix + text;
		}
		if (postfix) {
			text += postfix;
		}
		return text;
	}

	function getPixelHeightOfTextLine(textElement) {
		/* Due to browser incompatibilities this has to be hardcoded. This is because Firefox has no
		 * "offsetHeight" attribute like Chrome to retrieve the absolute pixel height. */
		if (textElement.classed("subtext")) {
			return 10;
		} else {
			return 14;
		}
	}

	function getTextBlockHeight(textBlock) {
		/* Hardcoded due to the same reasons like in the getPixelHeightOfTextLine function. */

		var children = textBlock.selectAll("*"),
			childCount = children.size();
		if (childCount === 0) {
			return 0;
		}

		// Values retrieved by testing
		var pixelHeight = childCount * LINE_DISTANCE;
		children.each(function () {
			pixelHeight += getPixelHeightOfTextLine(d3.select(this));
		});

		return pixelHeight;
	}

	textElement.setTranslation = function (x, y) {
		textBlock.attr("transform", "translate(" + x + ", " + y + ")");
	};

	return textElement;
};
<commit_msg>Pass subtext class on subtext truncation<commit_after>/**
 * Creates a new textblock in the specified element.
 * @param element The element/group where the text block should be appended.
 * @constructor New text block where additional <tspan>'s can be applied to.
 */
webvowl.util.textElement = function (element) {

	var textElement = {},
		LINE_DISTANCE = 1,
		SUBTEXT_CSS_CLASS = "subtext",
		textBlock = element.append("text")
			.classed("text", true)
			.attr("text-anchor", "middle");

	/**
	 * Repositions the textblock according to its own offsetHeight.
	 */
	function repositionTextBlock() {
		// Nothing to do if no child elements exist
		var textBlockChildCount = textBlock.property("childElementCount");
		if (textBlockChildCount < 1) {
			return;
		}

		var textBlockHeight = getTextBlockHeight(textBlock);
		textBlock.attr("y", -textBlockHeight * 0.6 + "px");
	}

	/**
	 * Adds a new line of text to the element.
	 * @param text
	 */
	textElement.addTextline = function (text) {
		addTextline(text);
	};

	/**
	 * Adds a line of text in subproperty style.
	 * @param text
	 */
	textElement.addSubTextNode = function (text) {
		addTextline(text, SUBTEXT_CSS_CLASS, "(", ")");
	};

	/**
	 * Adds a line of text in equivalent node listing style.
	 * @param text
	 */
	textElement.addEquivalentSpan = function (text) {
		addTextline(text, SUBTEXT_CSS_CLASS, "[", "]");
	};

	function addTextline(text, subtextCssClass, prefix, postfix) {
		if (!text) {
			return;
		}

		var truncatedText, tspan;

		subtextCssClass = subtextCssClass || "text";
		truncatedText = text.truncate(element.datum().textWidth(), subtextCssClass);

		tspan = textBlock.append("tspan")
			.classed("text", true)
			.classed(subtextCssClass, true)
			.text(applyPreAndPostFix(truncatedText, prefix, postfix))
			.attr("x", 0)
			.attr("dy", function () {
				var heightInPixels = getPixelHeightOfTextLine(d3.select(this)),
					siblingCount = textBlock.property("childElementCount") - 1,
					lineDistance = siblingCount > 0 ? LINE_DISTANCE : 0;
				return heightInPixels + lineDistance + "px";
			});


		repositionTextBlock();
	}

	function applyPreAndPostFix(text, prefix, postfix) {
		if (prefix) {
			text = prefix + text;
		}
		if (postfix) {
			text += postfix;
		}
		return text;
	}

	function getPixelHeightOfTextLine(textElement) {
		/* Due to browser incompatibilities this has to be hardcoded. This is because Firefox has no
		 * "offsetHeight" attribute like Chrome to retrieve the absolute pixel height. */
		if (textElement.classed("subtext")) {
			return 10;
		} else {
			return 14;
		}
	}

	function getTextBlockHeight(textBlock) {
		/* Hardcoded due to the same reasons like in the getPixelHeightOfTextLine function. */

		var children = textBlock.selectAll("*"),
			childCount = children.size();
		if (childCount === 0) {
			return 0;
		}

		// Values retrieved by testing
		var pixelHeight = childCount * LINE_DISTANCE;
		children.each(function () {
			pixelHeight += getPixelHeightOfTextLine(d3.select(this));
		});

		return pixelHeight;
	}

	textElement.setTranslation = function (x, y) {
		textBlock.attr("transform", "translate(" + x + ", " + y + ")");
	};

	return textElement;
};

{'fraction_non_alphanumeric': 0.12796730073887755, 'fraction_numerical': 0.005030655557302311, 'mean_word_length': 3.805135951661631, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3201103', 'n_tokens_mistral': 2307, 'n_tokens_neox': 2017, 'n_words': 537}