Skip to content

Commit

Permalink
added support for boolean operations (track adding and masking)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsmirob committed Mar 1, 2013
1 parent 54673f0 commit 86a7b82
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions src/JBrowse/View/Track/Wiggle/Density.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ return declare( WiggleBase,
return { maxExportSpan: 500000, style: { height: 32 } };
},

_drawFeatures: function( scale, leftBase, rightBase, block, canvas, features, featureRects, dataScale ) {
_drawFeatures: function( scale, leftBase, rightBase, block, canvas, pixels, dataScale ) {

var context = canvas.getContext('2d');
var canvasHeight = canvas.height;
Expand All @@ -38,19 +38,41 @@ return declare( WiggleBase,
var clipColor = new Color( this.config.style.clip_marker_color );
var disableClipMarkers = this.config.disable_clip_markers;
var normOrigin = normalize( dataScale.origin );
return function( feature ) {
var score = feature.get('score');
var n = normalize( score );
return function( pixelHeight ) {
var n = normalize( pixelHeight );
return ( disableClipMarkers || n <= 1 && n >= 0 )
? Color.blendColors( backgroundColor, n >= normOrigin ? posColor : negColor, Math.abs(n-normOrigin) )
: clipColor || ( n > 1 ? white : black );
};
}.call(this);

dojo.forEach( features, function(f,i) {
var fRect = featureRects[i];
context.fillStyle = ''+featureColor( f );
context.fillRect( fRect.l, 0, fRect.w, canvasHeight );
dojo.forEach( pixels, function(p,i) {
if (p) {
context.fillStyle = ''+featureColor( p );
context.fillRect( i, 0, 1, canvasHeight );
}
});
},

/* If boolean track, mask accordingly */
_maskBySpans: function( scale, leftBase, rightBase, block, canvas, pixels, dataScale, spans ) {
var context = canvas.getContext('2d');
var canvasHeight = canvas.height;
context.fillStyle = this.config.style.mask_color || 'rgba(128,128,128,0.6)';

for ( var index in spans ) {
if (spans.hasOwnProperty(index)) {
var w = Math.ceil(( spans[index].end - spans[index].start ) * scale );
var l = Math.round(( spans[index].start - leftBase ) * scale );
context.fillRect( l, 0, w-1, canvasHeight );
context.clearRect( l, 0, w-1, canvasHeight/3);
context.clearRect( l, (2/3)*canvasHeight, w-1, canvasHeight/3);
}}
dojo.forEach( pixels, function(p,i) {
if (!p) {
// if there is no data at a point, erase the mask.
context.clearRect( i, 0, 1, canvasHeight );
}
});
},

Expand Down

0 comments on commit 86a7b82

Please sign in to comment.