<commit_before>/*==================================================
 *  Exhibit.NumericRangeFacet
 *==================================================
 */

Exhibit.NumericRangeFacet = function(collection, containerElmt, exhibit) {
    this._collection = collection;
    this._div = containerElmt;
    this._exhibit = exhibit;
    
    this._path = null;
    this._facetLabel = null;
    this._interval = 10;
    
    this._dom = null;
    this._ranges = [];
};

Exhibit.NumericRangeFacet.create = function(configuration, containerElmt, exhibit) {
    var collection = Exhibit.Collection.getCollection(configuration, exhibit);
    var facet = new Exhibit.NumericRangeFacet(
        collection, 
        containerElmt != null ? containerElmt : configElmt, 
        exhibit
    );
    
    Exhibit.NumericRangeFacet._configure(facet, configuration);
    
    facet._initializeUI();
    collection.addFacet(facet);
    
    return facet;
};

Exhibit.NumericRangeFacet.createFromDOM = function(configElmt, containerElmt, exhibit) {
    var configuration = Exhibit.getConfigurationFromDOM(configElmt);
    var collection = Exhibit.Collection.getCollectionFromDOM(configElmt, configuration, exhibit);
    var facet = new Exhibit.NumericRangeFacet(
        collection, 
        containerElmt != null ? containerElmt : configElmt, 
        exhibit
    );
    
    try {
        var expressionString = Exhibit.getAttribute(configElmt, "expression");
        if (expressionString != null && expressionString.length > 0) {
            var expression = Exhibit.Expression.parse(expressionString);
            if (expression.isPath()) {
                facet._path = expression.getPath();
            }
        }
        
        var facetLabel = Exhibit.getAttribute(configElmt, "facetLabel");
        if (facetLabel != null && facetLabel.length > 0) {
            facet._facetLabel = facetLabel;
        }
        
        var interval = Exhibit.getAttribute(configElmt, "interval");
        if (interval != null && interval.length > 0) {
            facet._interval = parseFloat(interval);
        }
    } catch (e) {
        SimileAjax.Debug.exception("NumericRangeFacet: Error processing configuration of numeric range facet", e);
    }
    
    facet._initializeUI();
    collection.addFacet(facet);
    
    return facet;
};

Exhibit.NumericRangeFacet._configure = function(facet, configuration) {
    if ("expression" in configuration) {
        var expression = Exhibit.Expression.parse(configuration.expression);
        if (expression.isPath()) {
            facet._path = expression.getPath();
        }
    }
    if ("facetLabel" in configuration) {
        facet._facetLabel = configuration.facetLabel;
    }
    if ("interval" in configuration) {
        facet._interval = configuration.interval;
    }
}

Exhibit.NumericRangeFacet.prototype.dispose = function() {
    this._dom.close();
    this._dom = null;
    
    this._collection = null;
    this._div = null;
    this._exhibit = null;
};

Exhibit.NumericRangeFacet.prototype.hasRestrictions = function() {
    return this._ranges.length > 0;
};

Exhibit.NumericRangeFacet.prototype.clearAllRestrictions = function() {
    var restrictions = [];
    if (this._ranges.length > 0) {
        restrictions = restrictions.concat(this._ranges);
        this._ranges = [];
        this._notifyCollection();
    }
    return restrictions;
};

Exhibit.NumericRangeFacet.prototype.applyRestrictions = function(restrictions) {
    this._ranges = restrictions;
    this._notifyCollection();
};

Exhibit.NumericRangeFacet.prototype.setRange = function(from, to, selected) {
    if (selected) {
        for (var i = 0; i < this._ranges.length; i++) {
            var range = this._ranges[i];
            if (range.from == from && range.to == to) {
                return;
            }
        }
        this._ranges.push({ from: from, to: to });
    } else {
        for (var i = 0; i < this._ranges.length; i++) {
            var range = this._ranges[i];
            if (range.from == from && range.to == to) {
                this._ranges.splice(i, 1);
                break;
            }
        }
    }
    this._notifyCollection();
}

Exhibit.NumericRangeFacet.prototype.restrict = function(items) {
    var path = this._path;
    var database = this._exhibit.getDatabase();
    
    var set = new Exhibit.Set();
    for (var i = 0; i < this._ranges.length; i++) {
        var range = this._ranges[i];
        set.addSet(path.rangeBackward(range.from, range.to, items, database).values);
    }
    return set;
};

Exhibit.NumericRangeFacet.prototype.update = function(items) {
    this._dom.valuesContainer.style.display = "none";
    this._dom.valuesContainer.innerHTML = "";
    
    this._reconstruct(items);
    this._dom.valuesContainer.style.display = "block";
};

Exhibit.NumericRangeFacet.prototype._reconstruct = function(items) {
    var database = this._exhibit.getDatabase();
    
    var propertyID = this._path.getLastSegment().property;<commit_msg>Fixed bug in which a numeric range facet incorrectly restricts items when it has no selection.<commit_after>/*==================================================
 *  Exhibit.NumericRangeFacet
 *==================================================
 */

Exhibit.NumericRangeFacet = function(collection, containerElmt, exhibit) {
    this._collection = collection;
    this._div = containerElmt;
    this._exhibit = exhibit;
    
    this._path = null;
    this._facetLabel = null;
    this._interval = 10;
    
    this._dom = null;
    this._ranges = [];
};

Exhibit.NumericRangeFacet.create = function(configuration, containerElmt, exhibit) {
    var collection = Exhibit.Collection.getCollection(configuration, exhibit);
    var facet = new Exhibit.NumericRangeFacet(
        collection, 
        containerElmt != null ? containerElmt : configElmt, 
        exhibit
    );
    
    Exhibit.NumericRangeFacet._configure(facet, configuration);
    
    facet._initializeUI();
    collection.addFacet(facet);
    
    return facet;
};

Exhibit.NumericRangeFacet.createFromDOM = function(configElmt, containerElmt, exhibit) {
    var configuration = Exhibit.getConfigurationFromDOM(configElmt);
    var collection = Exhibit.Collection.getCollectionFromDOM(configElmt, configuration, exhibit);
    var facet = new Exhibit.NumericRangeFacet(
        collection, 
        containerElmt != null ? containerElmt : configElmt, 
        exhibit
    );
    
    try {
        var expressionString = Exhibit.getAttribute(configElmt, "expression");
        if (expressionString != null && expressionString.length > 0) {
            var expression = Exhibit.Expression.parse(expressionString);
            if (expression.isPath()) {
                facet._path = expression.getPath();
            }
        }
        
        var facetLabel = Exhibit.getAttribute(configElmt, "facetLabel");
        if (facetLabel != null && facetLabel.length > 0) {
            facet._facetLabel = facetLabel;
        }
        
        var interval = Exhibit.getAttribute(configElmt, "interval");
        if (interval != null && interval.length > 0) {
            facet._interval = parseFloat(interval);
        }
    } catch (e) {
        SimileAjax.Debug.exception("NumericRangeFacet: Error processing configuration of numeric range facet", e);
    }
    
    facet._initializeUI();
    collection.addFacet(facet);
    
    return facet;
};

Exhibit.NumericRangeFacet._configure = function(facet, configuration) {
    if ("expression" in configuration) {
        var expression = Exhibit.Expression.parse(configuration.expression);
        if (expression.isPath()) {
            facet._path = expression.getPath();
        }
    }
    if ("facetLabel" in configuration) {
        facet._facetLabel = configuration.facetLabel;
    }
    if ("interval" in configuration) {
        facet._interval = configuration.interval;
    }
}

Exhibit.NumericRangeFacet.prototype.dispose = function() {
    this._dom.close();
    this._dom = null;
    
    this._collection = null;
    this._div = null;
    this._exhibit = null;
};

Exhibit.NumericRangeFacet.prototype.hasRestrictions = function() {
    return this._ranges.length > 0;
};

Exhibit.NumericRangeFacet.prototype.clearAllRestrictions = function() {
    var restrictions = [];
    if (this._ranges.length > 0) {
        restrictions = restrictions.concat(this._ranges);
        this._ranges = [];
        this._notifyCollection();
    }
    return restrictions;
};

Exhibit.NumericRangeFacet.prototype.applyRestrictions = function(restrictions) {
    this._ranges = restrictions;
    this._notifyCollection();
};

Exhibit.NumericRangeFacet.prototype.setRange = function(from, to, selected) {
    if (selected) {
        for (var i = 0; i < this._ranges.length; i++) {
            var range = this._ranges[i];
            if (range.from == from && range.to == to) {
                return;
            }
        }
        this._ranges.push({ from: from, to: to });
    } else {
        for (var i = 0; i < this._ranges.length; i++) {
            var range = this._ranges[i];
            if (range.from == from && range.to == to) {
                this._ranges.splice(i, 1);
                break;
            }
        }
    }
    this._notifyCollection();
}

Exhibit.NumericRangeFacet.prototype.restrict = function(items) {
    if (this._ranges.length == 0) {
        return items;
    } else {
        var path = this._path;
        var database = this._exhibit.getDatabase();
        
        var set = new Exhibit.Set();
        for (var i = 0; i < this._ranges.length; i++) {
            var range = this._ranges[i];
            set.addSet(path.rangeBackward(range.from, range.to, items, database).values);
        }
        return set;
    }
};

Exhibit.NumericRangeFacet.prototype.update = function(items) {
    this._dom.valuesContainer.style.display = "none";
    this._dom.valuesContainer.innerHTML = "";
    
    this._reconstruct(items);
    this._dom.valuesContainer.style.display = "block";
};

Exhibit.NumericRangeFacet.prototype._reconstruct = function(items) {
    var database = this._exhibit.getDatabase();
    
    var propertyID = this._path.getLastSegment().property;
{'fraction_non_alphanumeric': 0.13385518590998044, 'fraction_numerical': 0.0022504892367906067, 'mean_word_length': 2.658196134574087, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '3396747', 'n_tokens_mistral': 3004, 'n_tokens_neox': 2893, 'n_words': 564}