Skip to content

Commit

Permalink
make Faceted track selector facet selector filtering smarter and more…
Browse files Browse the repository at this point in the history
… customizable: can now take a selectableFacets constructor arg that discriminates which facets should have facet selectors rendered for them. also, rename TrackMetaData getFacets() to getFacetNames()
  • Loading branch information
rbuels committed May 11, 2012
1 parent 7b02505 commit 6512329
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
2 changes: 1 addition & 1 deletion js/Model/TrackMetaData.js
Expand Up @@ -238,7 +238,7 @@ dojo.declare( 'JBrowse.Model.TrackMetaData', null,
* in this track metadata.
* @param callback {Function} called as callback( [facet,facet,...] )
*/
getFacets: function( callback ) {
getFacetNames: function( callback ) {
return this.facets;
},

Expand Down
51 changes: 45 additions & 6 deletions js/View/TrackList/Faceted.js
Expand Up @@ -17,6 +17,38 @@ dojo.declare( 'JBrowse.View.TrackList.Faceted', null,
this.browser = args.browser;
this.tracksActive = {};

// construct the discriminator for whether we will display a
// facet selector for this facet
this._isSelectableFacet = function() {
// just a function returning true if not specified
var filter = args.selectableFacets ||
// default facet filtering function
function( store, facetName ){
return (
// has an avg bucket size > 1
store.getFacetStats( facetName ).avgBucketSize > 1
&&
// and not an ident or label attribute
! dojo.some( store.getLabelAttributes()
.concat( store.getIdentityAttributes() ),
function(l) {return l == facetName;}
)
);
};
// if we have a non-function filter, coerce to an array,
// then convert that array to a function
if( typeof filter == 'string' )
filter = [filter];
if( Array.isArray( filter ) ) {
filter = function( store, facetName) {
return dojo.some( filter, function(fn) {
return facetName == fn;
});
};
}
return filter;
}.call(this);

// data store that fetches and filters our track metadata
this.trackDataStore = args.trackMetaData;

Expand Down Expand Up @@ -198,7 +230,7 @@ dojo.declare( 'JBrowse.View.TrackList.Faceted', null,

renderGrid: function() {
// make a data grid that will hold the search results
var facets = this.trackDataStore.getFacets();
var facets = this.trackDataStore.getFacetNames();
var rename = { key: 'name' }; // rename some columns in the grid
var grid = new dojox.grid.EnhancedGrid({
id: 'trackSelectGrid',
Expand Down Expand Up @@ -323,10 +355,17 @@ dojo.declare( 'JBrowse.View.TrackList.Faceted', null,

var store = this.trackDataStore;
this.facetSelectors = {};
var renderFacets = dojo.filter( store.getFacets(), function(facet) {
return ! dojo.some( store.getLabelAttributes().concat( store.getIdentityAttributes() ), function(l) {return l == facet;} );
});
dojo.forEach( renderFacets, function(facetName) {


// for the facets from the store, only render facet selectors
// for ones that are not identity attributes, and have an
// average bucket size greater than 1
var storeFacets =
dojo.filter( store.getFacetNames(),
dojo.hitch( this, '_isSelectableFacet', store )
);

dojo.forEach( storeFacets, function(facetName) {
// get the values of this facet
var values = store.getFacetValues(facetName).sort();
if( !values || !values.length )
Expand Down Expand Up @@ -435,7 +474,7 @@ dojo.declare( 'JBrowse.View.TrackList.Faceted', null,
}

// update from the facet selectors
dojo.forEach( this.trackDataStore.getFacets(), function(facetName) {
dojo.forEach( this.trackDataStore.getFacetNames(), function(facetName) {
var options = this.facetSelectors[facetName];
if( !options ) return;

Expand Down

0 comments on commit 6512329

Please sign in to comment.