Skip to content

Commit

Permalink
fix clipped extents in #41
Browse files Browse the repository at this point in the history
  • Loading branch information
almccon committed Jan 27, 2017
1 parent cb2d2c3 commit c4f5299
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
17 changes: 14 additions & 3 deletions src/app/collections/city_buildings.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@ define([
if (!_.isNumber(_value)) {
return false;
}

return (_value >= range.min && _value <= range.max);
// Handle situations where there's only a min or only a max
if (range.min && range.max)
return (_value >= range.min && _value <= range.max);
if (range.min)
return (_value >= range.min);
if (range.max)
return (_value <= range.max);
}

function cityBuildingsFilterizer(buildings, categories, ranges) {
Expand Down Expand Up @@ -92,7 +97,13 @@ define([

CityBuildingQuery.prototype.toRangeSql = function() {
return _.map(this.ranges, function(range){
return range.field + " BETWEEN " + range.min + " AND " + range.max;
// Handle situations where there's only a min or only a max
if (range.min && range.max)
return range.field + " BETWEEN " + range.min + " AND " + range.max;
if (range.min)
return range.field + " >= " + range.min;
if (range.max)
return range.field + " <= " + range.max;
});
};

Expand Down
8 changes: 7 additions & 1 deletion src/app/views/map/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,13 @@ define([
filters = _.reject(filters, function(f){ return f.field == fieldName; });

if (rangeSlider.from !== rangeSlider.min || rangeSlider.to !== rangeSlider.max){
filters.push({field: fieldName, min: rangeSlider.from, max: rangeSlider.to});
var newFilter = {field: fieldName};
// Only include min or max in the filter if it is different from the rangeSlider extent.
// This is important to the rangeSlider can clip the extreme values off, but we don't
// want to use the rangeSlider extents to filter the data on the map.
if (rangeSlider.from !== rangeSlider.min) newFilter.min = rangeSlider.from;
if (rangeSlider.to !== rangeSlider.max) newFilter.max = rangeSlider.to;
filters.push(newFilter);
}

// fire event for other non Filter.js listeners
Expand Down

0 comments on commit c4f5299

Please sign in to comment.