<commit_before>/**
 * @fileOverview Provide an easy way to attach classifications to a
 *     view with a legend widget.
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */

/**
 * @constructor
 * @class
 * @param {Object} configuration
 * @param {Element} containerElmt
 * @param {Exhibit.UIContext} uiContext
 */
Exhibit.LegendWidget = function(configuration, containerElmt, uiContext) {
    this._configuration = configuration;
    this._div = containerElmt;
    this._uiContext = uiContext;
    
    this._colorMarkerGenerator = typeof configuration.colorMarkerGenerator !== "undefined" ?
        configuration.colorMarkerGenerator :
        Exhibit.LegendWidget._defaultColorMarkerGenerator;	 
	this._sizeMarkerGenerator = typeof configuration.sizeMarkerGenerator !== "undefined" ?
		configuration.sizeMarkerGenerator :
		Exhibit.LegendWidget._defaultSizeMarkerGenerator;
	this._iconMarkerGenerator = typeof configuration.iconMarkerGenerator !== "undefined" ?
		configuration.iconMarkerGenerator :
		Exhibit.LegendWidget._defaultIconMarkerGenerator;

    this._labelStyler = typeof configuration.labelStyler !== "undefined" ?
        configuration.labelStyler :
        Exhibit.LegendWidget._defaultColorLabelStyler;
    
    this._initializeUI();
};

/**
 * @static
 * @param {Object} configuration
 * @param {Element} containerElmt
 * @param {Exhibit.UIContext} uiContext
 * @returns {Exhibit.LegendWidget}
 */
Exhibit.LegendWidget.create = function(configuration, containerElmt, uiContext) {
    return new Exhibit.LegendWidget(configuration, containerElmt, uiContext);
};

/**
 *
 */
Exhibit.LegendWidget.prototype.dispose = function() {
    Exhibit.jQuery(this._div).empty();
    
    this._div = null;
    this._uiContext = null;
};

/**
 *
 */
Exhibit.LegendWidget.prototype._initializeUI = function() {
    Exhibit.jQuery(this._div).attr("class", "exhibit-legendWidget");
    this.clear();
};

/**
 *
 */
Exhibit.LegendWidget.prototype.clear = function() {
    Exhibit.jQuery(this._div).html('<div id="exhibit-color-legend"></div><div id="exhibit-size-legend"></div><div id="exhibit-icon-legend"></div>');
};

/**
 * @param {String} label
 * @param {String} type
 */
Exhibit.LegendWidget.prototype.addLegendLabel = function(label, type) {
    var dom;
	dom = Exhibit.jQuery.simileDOM("string",
			"div",
			'<div id="legend-label">' +
				'<span id="label" class="exhibit-legendWidget-entry-title">' + 
					label.replace(/\s+/g, "&nbsp;") + 
				"</span>" +
			"&nbsp;&nbsp; </div>",
			{ }
		);
	Exhibit.jQuery(dom.elmt).attr("class","exhibit-legendWidget-label");
	Exhibit.jQuery('#exhibit-' + type + '-legend').append(dom.elmt);
}

/**
 * @param {} value
 * @param {String} label
 * @param {String} type
 */
Exhibit.LegendWidget.prototype.addEntry = function(value, label, type) {
    var dom, legendDiv;

	type = type || "color";
    label = (typeof label === "object") ? label.toString() : label;

    if (type === "color") {
		dom = Exhibit.jQuery.simileDOM("string",
			"span",
			'<span id="marker"></span>&nbsp;' +
				'<span id="label" class="exhibit-legendWidget-entry-title">' + 
					label.replace(/\s+/g, "&nbsp;") + 
				"</span>" +
				"&nbsp;&nbsp; ",
			{ marker: this._colorMarkerGenerator(value) }
		);
		legendDiv = Exhibit.jQuery("#exhibit-color-legend");
	}

	if (type === "size") {
		dom = Exhibit.jQuery.simileDOM("string",<commit_msg>fixing bug with more correct comparison; all other types like numbers will need toString<commit_after>/**
 * @fileOverview Provide an easy way to attach classifications to a
 *     view with a legend widget.
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */

/**
 * @constructor
 * @class
 * @param {Object} configuration
 * @param {Element} containerElmt
 * @param {Exhibit.UIContext} uiContext
 */
Exhibit.LegendWidget = function(configuration, containerElmt, uiContext) {
    this._configuration = configuration;
    this._div = containerElmt;
    this._uiContext = uiContext;
    
    this._colorMarkerGenerator = typeof configuration.colorMarkerGenerator !== "undefined" ?
        configuration.colorMarkerGenerator :
        Exhibit.LegendWidget._defaultColorMarkerGenerator;	 
	this._sizeMarkerGenerator = typeof configuration.sizeMarkerGenerator !== "undefined" ?
		configuration.sizeMarkerGenerator :
		Exhibit.LegendWidget._defaultSizeMarkerGenerator;
	this._iconMarkerGenerator = typeof configuration.iconMarkerGenerator !== "undefined" ?
		configuration.iconMarkerGenerator :
		Exhibit.LegendWidget._defaultIconMarkerGenerator;

    this._labelStyler = typeof configuration.labelStyler !== "undefined" ?
        configuration.labelStyler :
        Exhibit.LegendWidget._defaultColorLabelStyler;
    
    this._initializeUI();
};

/**
 * @static
 * @param {Object} configuration
 * @param {Element} containerElmt
 * @param {Exhibit.UIContext} uiContext
 * @returns {Exhibit.LegendWidget}
 */
Exhibit.LegendWidget.create = function(configuration, containerElmt, uiContext) {
    return new Exhibit.LegendWidget(configuration, containerElmt, uiContext);
};

/**
 *
 */
Exhibit.LegendWidget.prototype.dispose = function() {
    Exhibit.jQuery(this._div).empty();
    
    this._div = null;
    this._uiContext = null;
};

/**
 *
 */
Exhibit.LegendWidget.prototype._initializeUI = function() {
    Exhibit.jQuery(this._div).attr("class", "exhibit-legendWidget");
    this.clear();
};

/**
 *
 */
Exhibit.LegendWidget.prototype.clear = function() {
    Exhibit.jQuery(this._div).html('<div id="exhibit-color-legend"></div><div id="exhibit-size-legend"></div><div id="exhibit-icon-legend"></div>');
};

/**
 * @param {String} label
 * @param {String} type
 */
Exhibit.LegendWidget.prototype.addLegendLabel = function(label, type) {
    var dom;
	dom = Exhibit.jQuery.simileDOM("string",
			"div",
			'<div id="legend-label">' +
				'<span id="label" class="exhibit-legendWidget-entry-title">' + 
					label.replace(/\s+/g, "&nbsp;") + 
				"</span>" +
			"&nbsp;&nbsp; </div>",
			{ }
		);
	Exhibit.jQuery(dom.elmt).attr("class","exhibit-legendWidget-label");
	Exhibit.jQuery('#exhibit-' + type + '-legend').append(dom.elmt);
}

/**
 * @param {} value
 * @param {String} label
 * @param {String} type
 */
Exhibit.LegendWidget.prototype.addEntry = function(value, label, type) {
    var dom, legendDiv;

	type = type || "color";
    label = (typeof label !== "string") ? label.toString() : label;

    if (type === "color") {
		dom = Exhibit.jQuery.simileDOM("string",
			"span",
			'<span id="marker"></span>&nbsp;' +
				'<span id="label" class="exhibit-legendWidget-entry-title">' + 
					label.replace(/\s+/g, "&nbsp;") + 
				"</span>" +
				"&nbsp;&nbsp; ",
			{ marker: this._colorMarkerGenerator(value) }
		);
		legendDiv = Exhibit.jQuery("#exhibit-color-legend");
	}

	if (type === "size") {
		dom = Exhibit.jQuery.simileDOM("string",
{'fraction_non_alphanumeric': 0.16495886852359648, 'fraction_numerical': 0.0, 'mean_word_length': 4.125739644970414, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, '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': '3393984', 'n_tokens_mistral': 2352, 'n_tokens_neox': 2150, 'n_words': 384}