Skip to content

Commit

Permalink
standardize signatures for config callbacks that operate feature-by-f…
Browse files Browse the repository at this point in the history
…eature
  • Loading branch information
rbuels committed Feb 22, 2013
1 parent ca5dbeb commit 51353be
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
9 changes: 9 additions & 0 deletions src/JBrowse/View/Track/BlockBased.js
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,15 @@ return declare( null,
return args ? func.apply( this, args ) : func;
},

/**
* Like getConf, but get a conf value that explicitly can vary
* feature by feature. Provides a uniform function signature for
* user-defined callbacks.
*/
getConfForFeature: function( path, feature ) {
return this.getConf( path, [feature, path, null, null, this ] );
},

_openDialog: function( spec, evt, context ) {
context = context || {};
var type = spec.action;
Expand Down
3 changes: 1 addition & 2 deletions src/JBrowse/View/Track/CanvasFeatures.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ return declare( [CanvasTrack,FeatureDetailMixin], {
},

getStyle: function( feature, name ) {
var args = [feature, name, null, null, this ];
return this.getConf( 'style.'+name, args );
return this.getConfForFeature( 'style.'+name, feature );
},

fillBlock: function( args ) {
Expand Down
2 changes: 1 addition & 1 deletion src/JBrowse/View/Track/FeatureDetailMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ return declare(null,{
container = container || dojo.create('div', { className: 'detail feature-detail feature-detail-'+track.name, innerHTML: '' } );
var coreDetails = dojo.create('div', { className: 'core' }, container );
coreDetails.innerHTML += '<h2 class="sectiontitle">Primary Data</h2>';
coreDetails.innerHTML += fmt( 'Name', this.getConf( 'style.label', [f] ) );
coreDetails.innerHTML += fmt( 'Name', this.getConfForFeature( 'style.label', f ) );
coreDetails.innerHTML += fmt( 'Type', f.get('type') );
coreDetails.innerHTML += fmt( 'Description', this._getDescription ? this._getDescription( f ) : (f.get('note') || f.get('description') ));
coreDetails.innerHTML += fmt(
Expand Down
2 changes: 1 addition & 1 deletion src/JBrowse/View/Track/HTMLFeatures.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ var HTMLFeatures = declare( [ BlockBased, YScaleMixin, ExportMixin, FeatureDetai

// if the label extends beyond the feature, use the
// label end position as the end position for layout
var name = this.getConf( 'style.label', [feature] );
var name = this.getConfForFeature( 'style.label', feature );
var description = scale > descriptionScale && this._getDescription(feature);
if( description && description.length > this.config.style.maxDescriptionLength )
description = description.substr(0, this.config.style.maxDescriptionLength+1 ).replace(/(\s+\S+|\s*)$/,'')+String.fromCharCode(8230);
Expand Down
7 changes: 3 additions & 4 deletions src/JBrowse/View/Track/Wiggle/Density.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,15 @@ return declare( WiggleBase,
var disableClipMarkers = thisB.config.disable_clip_markers;
var normOrigin = normalize( dataScale.origin );
return function( feature ) {
var confArgs = [ feature, thisB ];
var score = feature.get('score');
var n = normalize( score );
return ( disableClipMarkers || n <= 1 && n >= 0 )
? Color.blendColors(
new Color( thisB.getConf('style.bg_color', confArgs ) ),
new Color( thisB.getConf( n >= normOrigin ? 'style.pos_color' : 'style.neg_color', confArgs ) ),
new Color( thisB.getConfForFeature('style.bg_color', feature ) ),
new Color( thisB.getConfForFeature( n >= normOrigin ? 'style.pos_color' : 'style.neg_color', feature ) ),
Math.abs(n-normOrigin)
)
: new Color( thisB.getConf('style.clip_marker_color', confArgs ) ) || ( n > 1 ? white : black );
: new Color( thisB.getConfForFeature('style.clip_marker_color', feature ) ) || ( n > 1 ? white : black );
};
})();

Expand Down
12 changes: 5 additions & 7 deletions src/JBrowse/View/Track/Wiggle/XYPlot.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,9 @@ var XYPlot = declare( [WiggleBase, YScaleMixin],
fRect.t = toY( score );
//console.log( score, fRect.t );

var confArgs = [f, this]; //< args passed to getConf calls

// draw the background color if we are configured to do so
if( fRect.t >= 0 ) {
var bgColor = this.getConf('style.bg_color', confArgs);
var bgColor = this.getConfForFeature('style.bg_color', f );
if( bgColor ) {
context.fillStyle = bgColor;
context.fillRect( fRect.l, 0, fRect.w, canvasHeight );
Expand All @@ -107,19 +105,19 @@ var XYPlot = declare( [WiggleBase, YScaleMixin],
if( fRect.t <= canvasHeight ) { // if the rectangle is visible at all
if( fRect.t <= originY ) {
// bar goes upward
context.fillStyle = this.getConf('style.pos_color',confArgs);
context.fillStyle = this.getConfForFeature('style.pos_color',f);
context.fillRect( fRect.l, fRect.t, fRect.w, originY-fRect.t+1);
if( !disableClipMarkers && fRect.t < 0 ) { // draw clip marker if necessary
context.fillStyle = this.getConf('style.clip_marker_color',confArgs) || this.getConf('style.neg_color',confArgs);
context.fillStyle = this.getConfForFeature('style.clip_marker_color',f) || this.getConfForFeature('style.neg_color',f);
context.fillRect( fRect.l, 0, fRect.w, 2 );
}
}
else {
// bar goes downward
context.fillStyle = this.getConf('style.neg_color',confArgs);
context.fillStyle = this.getConfForFeature('style.neg_color',f);
context.fillRect( fRect.l, originY, fRect.w, fRect.t-originY+1 );
if( !disableClipMarkers && fRect.t >= canvasHeight ) { // draw clip marker if necessary
context.fillStyle = this.getConf('style.clip_marker_color',confArgs) || this.getConf('style.pos_color',confArgs);
context.fillStyle = this.getConfForFeature('style.clip_marker_color',f) || this.getConfForFeature('style.pos_color',f);
context.fillRect( fRect.l, canvasHeight-3, fRect.w, 2 );
}
}
Expand Down

0 comments on commit 51353be

Please sign in to comment.