Skip to content

Commit

Permalink
tweak track creation API to instantiate the store inside GenomeView, …
Browse files Browse the repository at this point in the history
…and make the track constructor just take an object for its args
  • Loading branch information
rbuels committed Jun 29, 2012
1 parent 6e53854 commit c3bf63e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 40 deletions.
35 changes: 28 additions & 7 deletions src/JBrowse/GenomeView.js
Expand Up @@ -1527,19 +1527,40 @@ GenomeView.prototype.renderTrack = function( /**Object*/ trackConfig ) {
});
trackDiv.trackName = trackName;

require( [trackClass], dojo.hitch(this,function(trackClass) {
// figure out what data store class to use with the track,
// applying some defaults if it is not explicit in the
// configuration
var storeClass =
trackConfig.storeClass ? trackConfig.storeClass :
/\/HTMLFeatures$/.test( trackClass ) ? 'JBrowse/Store/SeqFeature/NCList'+( trackConfig.backendVersion == 0 ? '_v0' : '' ) :
/\/FixedImage/.test( trackClass ) ? 'JBrowse/Store/TiledImage/Fixed' +( trackConfig.backendVersion == 0 ? '_v0' : '' ) :
/\/Sequence$/.test( trackClass ) ? 'JBrowse/Store/Sequence/StaticChunked' :
null;
if( ! storeClass ) {
console.error( "Unable to find an appropriate data store to use with a "
+ trackClass + " track, please explicitly specify a "
+ "storeClass in the configuration." );
return trackDiv;
}

var track = new trackClass(
trackConfig,
this.ref,
{
require( [ trackClass, storeClass ], dojo.hitch(this,function( trackClass, storeClass ) {

var store = new storeClass({
urlTemplate: trackConfig.urlTemplate,
baseUrl: trackConfig.baseUrl,
refSeq: this.ref
});

var track = new trackClass({
refSeq: this.ref,
config: trackConfig,
changeCallback: dojo.hitch( this, 'showVisibleBlocks', true ),
trackPadding: this.trackPadding,
charWidth: this.charWidth,
seqHeight: this.seqHeight
seqHeight: this.seqHeight,
store: store
});


// tell the track to get its data, since we're going to display it.
track.load();

Expand Down
53 changes: 20 additions & 33 deletions src/JBrowse/View/Track/HTMLFeatures.js
Expand Up @@ -12,51 +12,38 @@ var HTMLFeatures = declare( BlockBased,
* A track that draws discrete features using `div` elements.
* @constructs
* @extends JBrowse.View.Track.BlockBased
* @param args.config {Object} track configuration. Must include key, label
* @param args.refSeq {Object} reference sequence object with name, start,
* and end members.
* @param args.changeCallback {Function} optional callback for
* when the track's data is loaded and ready
* @param args.trackPadding {Number} distance in px between tracks
*/
constructor: function( config, refSeq, browserParams ) {
//config: object with:
// key: display text track name
// label: internal track name (no spaces, odd characters)
// baseUrl: base URL to use for resolving relative URLs
// contained in the track's configuration
// config: configuration info for this track
//refSeq: object with:
// name: refseq name
// start: refseq start
// end: refseq end
//browserParams: object with:
// changeCallback: function to call once JSON is loaded
// trackPadding: distance in px between tracks
// baseUrl: base URL for the URL in config

constructor: function( args ) {
var config = args.config;
BlockBased.call( this, config.label, config.key,
false, browserParams.changeCallback);
false, args.changeCallback);
this.fields = {};
this.refSeq = refSeq;

// TODO: this featureStore object should eventuallly be
//number of histogram bins per block
this.numBins = 25;
this.histLabel = false;
this.padding = 5;
this.trackPadding = args.trackPadding;

this.config = config;


// this featureStore object should eventually be
// instantiated by Browser and passed into this constructor, not
// constructed here.
var storeclass = config.backendVersion == 0 ? SeqFeatureStore.NCList_v0 : SeqFeatureStore.NCList;
this.featureStore = new storeclass({
urlTemplate: config.urlTemplate,
baseUrl: config.baseUrl,
refSeq: refSeq,
track: this
});
this.featureStore = args.store;

// connect the store and track loadSuccess and loadFailed events
// to eachother
dojo.connect( this.featureStore, 'loadSuccess', this, 'loadSuccess' );
dojo.connect( this.featureStore, 'loadFail', this, 'loadFail' );

//number of histogram bins per block
this.numBins = 25;
this.histLabel = false;
this.padding = 5;
this.trackPadding = browserParams.trackPadding;

this.config = config;
},

/**
Expand Down

0 comments on commit c3bf63e

Please sign in to comment.