<commit_before>function CodeDisplayManager(language, algorithmOrDataStructure) {

    this.codeRoot;
    this.currentClass;
    this.currentFunction;
	this.currentLine;
	this.variables;
	this.variableMap;

    var self = this;

    $.ajax({
        url: "./js/codedisplay/code.json",
        dataType: "json",
        async: false,
        success: function (data) {
            self.codeRoot = data;
			self.currentClass = data[language][algorithmOrDataStructure];
			self.variables = data[language][algorithmOrDataStructure]["variables"];
        },
        error: function (xhr, ajaxOptions, thrownError) {
            alert(xhr.status);
            alert(thrownError);
        }
    });
}

CodeDisplayManager.prototype.loadFunctions = function () {
    $("#code-text").empty();
    for (var i = 0; i < arguments.length; i++) {
        $("#code-text").append("<span id='" + arguments[i] + "'>" + this.currentClass[arguments[i]].header + "\n");
        for(var j = 0; j < this.currentClass[arguments[i]].lines.length; j++)
            $("#" + arguments[i]).append(this.makeHighlightSpan(this.currentClass[arguments[i]].lines[j]));

        $("#code-text").append("\n\n");
    }

    hljs.initHighlighting.called = false;
    hljs.initHighlighting();
    this.addVariableTooltips();
};

CodeDisplayManager.prototype.makeHighlightSpan = function (line) {
    var textStartIndex = line.search(/\S|$/);
	return line.slice(0, textStartIndex) + "<span class='highlighted-code' style='background-color: rgba(255,255,0,0);'>" + line.slice(textStartIndex) + "</span>\n";
};

CodeDisplayManager.prototype.addVariableTooltips = function () {
	// Make a map containing variable name and corresponding value if it is not already done.
	if (this.variableMap === undefined) {
		this.variableMap = this.variables.reduce(function (map, obj) {
			map[obj.name] = "Var";
			return map;
		}, {});
	}<commit_msg>Prevented error when variables are not defined for visualization<commit_after>function CodeDisplayManager(language, algorithmOrDataStructure) {

    this.codeRoot;
    this.currentClass;
    this.currentFunction;
	this.currentLine;
	this.variables;
	this.variableMap;

    var self = this;

    $.ajax({
        url: "./js/codedisplay/code.json",
        dataType: "json",
        async: false,
        success: function (data) {
            self.codeRoot = data;
			self.currentClass = data[language][algorithmOrDataStructure];
			self.variables = data[language][algorithmOrDataStructure]["variables"];
        },
        error: function (xhr, ajaxOptions, thrownError) {
            alert(xhr.status);
            alert(thrownError);
        }
    });
}

CodeDisplayManager.prototype.loadFunctions = function () {
    $("#code-text").empty();
    for (var i = 0; i < arguments.length; i++) {
        $("#code-text").append("<span id='" + arguments[i] + "'>" + this.currentClass[arguments[i]].header + "\n");
        for(var j = 0; j < this.currentClass[arguments[i]].lines.length; j++)
            $("#" + arguments[i]).append(this.makeHighlightSpan(this.currentClass[arguments[i]].lines[j]));

        $("#code-text").append("\n\n");
    }

    hljs.initHighlighting.called = false;
    hljs.initHighlighting();
    this.addVariableTooltips();
};

CodeDisplayManager.prototype.makeHighlightSpan = function (line) {
    var textStartIndex = line.search(/\S|$/);
	return line.slice(0, textStartIndex) + "<span class='highlighted-code' style='background-color: rgba(255,255,0,0);'>" + line.slice(textStartIndex) + "</span>\n";
};

CodeDisplayManager.prototype.addVariableTooltips = function () {
	if (this.variables == null)
		return

	// Make a map containing variable name and corresponding value if it is not already done.
	if (this.variableMap === undefined) {
		this.variableMap = this.variables.reduce(function (map, obj) {
			map[obj.name] = "Var";
			return map;
		}, {});
	}
{'fraction_non_alphanumeric': 0.16124871001031993, 'fraction_numerical': 0.005675954592363261, 'mean_word_length': 3.4512055109070032, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, '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': '2747286', 'n_tokens_mistral': 1231, 'n_tokens_neox': 1166, 'n_words': 222}