Skip to content

Commit

Permalink
add unstyled slider to naively filter by popularity
Browse files Browse the repository at this point in the history
  • Loading branch information
atogle committed Mar 5, 2012
1 parent 8dfd2fe commit 356812b
Show file tree
Hide file tree
Showing 9 changed files with 495 additions and 20 deletions.
9 changes: 9 additions & 0 deletions app/assets/javascripts/main.js.erb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@ $(function() {
showPage(pages.filter('[data-welcome-page]').attr("href")); showPage(pages.filter('[data-welcome-page]').attr("href"));
} }


$('#map-container').hiderslider({
title: 'Filter by Popularity',
slider: {
slide: function(e, data) {
Map.shareabout('filterByPopularityPercentage', data.value/100);
}
}
});

// Start the ticker // Start the ticker
if ( !Map.shareabout("smallScreen") ) { if ( !Map.shareabout("smallScreen") ) {
$("#ticker").activityticker({ $("#ticker").activityticker({
Expand Down
50 changes: 46 additions & 4 deletions app/assets/javascripts/shareabouts.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ $.widget("ui.shareabout", (function() {
fsm, // state machine fsm, // state machine
layersOnMap, // object that stores map features (marker layers, specifically) by their ID layersOnMap, // object that stores map features (marker layers, specifically) by their ID
popup, // one popup on the map popup, // one popup on the map
featurePointsCache = []; // Cache of all of the feature points featurePointsCache = [], // Cache of all of the feature points
popularityStats, // popularity stats about the current features in the cache
popularityThreshold = 0; // The min popularity to show


return { return {
options : { options : {
Expand Down Expand Up @@ -193,22 +195,26 @@ $.widget("ui.shareabout", (function() {
feature, feature,
inBounds, inBounds,
onMap, onMap,
isPopular,
markerLayer; markerLayer;


for(i=0; i<len; i++) { for(i=0; i<len; i++) {
feature = featurePointsCache[i]; feature = featurePointsCache[i];


// Popular enough to show
isPopular = feature.pop >= popularityThreshold;
// In the current map bounds
inBounds = this._isFeatureInBounds(feature, bounds); inBounds = this._isFeatureInBounds(feature, bounds);
// Not not something truthy is true // Not not something truthy is true
onMap = !!layersOnMap[feature.id]; onMap = !!layersOnMap[feature.id];


// If inBounds and not onMap, add it // If inBounds and not onMap, add it
if (inBounds && !onMap) { if (inBounds && !onMap && isPopular) {
this.addMapFeature(feature); this.addMapFeature(feature);
} }


// If not inBounds and onMap, remove it // If not popular or not inBounds and onMap, remove it
if (!inBounds && onMap) { if ((!isPopular || !inBounds) && onMap) {
map.removeLayer(layersOnMap[feature.id]); map.removeLayer(layersOnMap[feature.id]);
delete layersOnMap[feature.id]; delete layersOnMap[feature.id];
} }
Expand All @@ -217,6 +223,20 @@ $.widget("ui.shareabout", (function() {
if (callback) {callback();} if (callback) {callback();}
}, },


// Will update the map and only show features that are more popular
// than the given value.
filterByPopularity: function(pop) {
popularityThreshold = pop;
this.refreshMapFeatures();
},

// Will update the map and only show features that are more popular
// than the given percentage.
filterByPopularityPercentage: function(percent) {
var pop = (popularityStats.max - popularityStats.min) * percent;
this.filterByPopularity(pop);
},

openPopup : function(content) { openPopup : function(content) {
// Unsfocus the icon if highlighted // Unsfocus the icon if highlighted
this._unsetFocusedIcon(); this._unsetFocusedIcon();
Expand Down Expand Up @@ -257,6 +277,7 @@ $.widget("ui.shareabout", (function() {
success: function(data){ success: function(data){
if($.isArray(data) && data.length) { if($.isArray(data) && data.length) {
featurePointsCache = featurePointsCache.concat(data); featurePointsCache = featurePointsCache.concat(data);
popularityStats = self._getPopularityStats();
} }
if (success) {success(data);} if (success) {success(data);}
}, },
Expand Down Expand Up @@ -287,6 +308,27 @@ $.widget("ui.shareabout", (function() {
return null; return null;
}, },


_getPopularityStats: function() {
var i,
len = featurePointsCache.length,
min = Number.MAX_VALUE,
max = Number.MIN_VALUE;

for (i=0; i<len; i++) {
if (featurePointsCache[i].pop <= min) {
min = featurePointsCache[i].pop;
}
if (featurePointsCache[i].pop > max) {
max = featurePointsCache[i].pop;
}
}

return {
min: min,
max: max
};
},

_refreshMapFeaturesWithDelay : function(ms) { _refreshMapFeaturesWithDelay : function(ms) {
if (this._waitingToLoad) return; if (this._waitingToLoad) return;


Expand Down
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.css
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*= require layout-fullscreen *= require layout-fullscreen
*= require chrome *= require chrome
*= require ../../../lib/assets/stylesheets/externals *= require ../../../lib/assets/stylesheets/externals
*= require ../../../vendor/assets/stylesheets/externals
*/ */


/* define custom Google Web Font */ /* define custom Google Web Font */
Expand Down
8 changes: 8 additions & 0 deletions app/assets/stylesheets/chrome.css
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -516,6 +516,14 @@ table.regions {
background : transparent url('ticker-comment.png') no-repeat scroll top left; background : transparent url('ticker-comment.png') no-repeat scroll top left;
} }


/* HiderSlider Widget */
.ui-sliderhider-container {
position: absolute;
right:0px;
bottom:20px;
}


/* /*
* *
* Media Queries for Layout & Style Overrides * Media Queries for Layout & Style Overrides
Expand Down
51 changes: 51 additions & 0 deletions lib/assets/javascripts/jquery.ui.hiderslider.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,51 @@
(function($) {
$.widget("ui.hiderslider", {
options: {
title: 'HiderSlider'
},

_create: function() {
var self = this,
o = self.options,
el = self.element,
$inner;

// Append markup
$(el).append('<div class="ui-sliderhider-container">' +
'<div class="ui-sliderhider-title">'+o.title+'</div>' +
'<div class="ui-sliderhider-content">' +
'<div class="ui-sliderhider-inner">' +
'<div class="ui-sliderhider-slider"></div>' +
'<div class="ui-sliderhider-close">X</div>' +
'</div>' +
'</div>' +
'</div>');

// Init slider
$('.ui-sliderhider-slider', el).slider(o.slider);

// Manually set the width on inner to keep floated elements from jumping
$inner = $('.ui-sliderhider-inner');
$inner.width($inner.outerWidth());

// Toggle visibility when you click the title
$('.ui-sliderhider-title').click(function(){
self.toggleVisiblity();
});

// Toggle visibility when you click the close link
$('.ui-sliderhider-close').click(function(){
self.toggleVisiblity();
});
},

// Toggle visiblity
toggleVisiblity: function() {
$('.ui-sliderhider-content', self.element).animate({width: 'toggle'});
},

destroy: function() {
this.element.empty();
}
});
})(jQuery);
29 changes: 29 additions & 0 deletions lib/assets/stylesheets/jquery-ui-sliderhider.css
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,29 @@
.ui-sliderhider-container {
overflow: auto;
}

.ui-sliderhider-container > div {
float:left;
}

.ui-sliderhider-title {
padding: 10px;
}

.ui-sliderhider-content {
padding: 10px 0;
overflow: hidden;
}

.ui-sliderhider-inner {}

.ui-sliderhider-inner > div {
float: left;
margin: 0 10px;
}

.ui-sliderhider-slider {
width:300px;
}

.ui-sliderhider-close {}
41 changes: 41 additions & 0 deletions vendor/assets/javascripts/jquery-ui-1.8.18.custom.min.js

Large diffs are not rendered by default.

16 changes: 0 additions & 16 deletions vendor/assets/javascripts/jquery.ui.widget.min.js

This file was deleted.

Loading

0 comments on commit 356812b

Please sign in to comment.