Skip to content

Commit

Permalink
Fixed bug where if switch to different sequence, SequenceTrack did no…
Browse files Browse the repository at this point in the history
…t display residues when fully zoomed in. SequenceTrack and AnnotTrack both now always refer to GenomeView.getSequenceCharacterSize() for seq residues width and height.
  • Loading branch information
GreggHelt2 committed Dec 20, 2012
1 parent 871c5c0 commit 2648e13
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 50 deletions.
6 changes: 4 additions & 2 deletions plugins/WebApollo/js/View/Track/AnnotTrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,8 @@ var AnnotTrack = declare( DraggableFeatureTrack,

// if zoomed int to showing sequence residues, then make edge-dragging snap to interbase pixels
var gridvals;
if (scale === track.gview.charWidth) { gridvals = [track.gview.charWidth, 1]; }
var charSize = track.gview.getSequenceCharacterSize();
if (scale === charSize.width) { gridvals = [track.gview.charWidth, 1]; }
else { gridvals = false; }

$(featdiv).resizable( {
Expand Down Expand Up @@ -2573,7 +2574,8 @@ makeTrackMenu: function() {
var strand = topfeat.get('strand');
var selectionYPosition = $(featdiv).position().top;
var scale = track.gview.bpToPx(1);
if (scale === track.gview.charWidth && track.useResiduesOverlay) {
var charSize = track.gview.getSequenceCharacterSize();
if (scale === charSize.width && track.useResiduesOverlay) {
var seqTrack = this.getSequenceTrack();
for (var bindex = this.firstAttached; bindex <= this.lastAttached; bindex++) {
var block = this.blocks[bindex];
Expand Down
68 changes: 20 additions & 48 deletions plugins/WebApollo/js/View/Track/SequenceTrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ function( declare, StaticChunked, DraggableFeatureTrack, JSONUtils, Permission,
};

this.charSize = this.gview.getSequenceCharacterSize();
this.charWidth = this.charSize.charWidth;
this.seqHeight = this.charSize.seqHeight;
// this.charWidth = this.charSize.charWidth;
// this.seqHeight = this.charSize.seqHeight;

// splitting seqHeight into residuesHeight and translationHeight, so future iteration may be possible
// for DNA residues and protein translation to be different styles
this.dnaHeight = this.seqHeight;
this.proteinHeight = this.seqHeight;
// this.dnaHeight = this.seqHeight;
// this.proteinHeight = this.seqHeight;

// this.refSeq = refSeq; already assigned in BlockBased superclass

Expand Down Expand Up @@ -151,9 +151,10 @@ function( declare, StaticChunked, DraggableFeatureTrack, JSONUtils, Permission,
},

endZoom: function(destScale, destBlockBases) {
var charSize = this.getCharacterMeasurements();
// var charSize = this.getCharacterMeasurements();
var charSize = this.gview.getSequenceCharacterSize();

if( ( destScale == charSize.w ) ||
if( ( destScale == charSize.width ) ||
(this.SHOW_IF_FEATURES && this.featureCount > 0) ) {
this.show();
}
Expand All @@ -180,9 +181,9 @@ function( declare, StaticChunked, DraggableFeatureTrack, JSONUtils, Permission,

this.inherited( arguments );

var charSize = this.getCharacterMeasurements();

if ( (scale == charSize.w ) ||
// var charSize = this.getCharacterMeasurements();
var charSize = this.gview.getSequenceCharacterSize();
if ( (scale == charSize.width ) ||
(this.SHOW_IF_FEATURES && this.featureCount > 0) ) {
this.show();
} else {
Expand All @@ -192,36 +193,6 @@ function( declare, StaticChunked, DraggableFeatureTrack, JSONUtils, Permission,
this.setLabel( this.key );
},

/**
* @returns {Object} containing <code>h</code> and <code>w</code>,
* in pixels, of the characters being used for sequences
*/
getCharacterMeasurements: function() {
if( !this._measurements )
this._measurements = this._measureSequenceCharacterSize( this.div );
return this._measurements;
},

/**
* Conducts a test with DOM elements to measure sequence text width
* and height.
*/
_measureSequenceCharacterSize: function( containerElement ) {
var widthTest = document.createElement("div");
widthTest.className = "wa-sequence";
widthTest.style.visibility = "hidden";
var widthText = "12345678901234567890123456789012345678901234567890";
widthTest.appendChild(document.createTextNode(widthText));
containerElement.appendChild(widthTest);
var result = {
w: widthTest.clientWidth / widthText.length,
h: widthTest.clientHeight
};
containerElement.removeChild(widthTest);
return result;
},


/**
* GAH
* not entirely sure, but I think this strategy of calling getRange() only works as long as
Expand All @@ -244,8 +215,9 @@ function( declare, StaticChunked, DraggableFeatureTrack, JSONUtils, Permission,

var fillArgs = arguments;
var track = this;
var charSize = this.getCharacterMeasurements();
if ((scale == charSize.w) ||
// var charSize = this.getCharacterMeasurements();
var charSize = this.gview.getSequenceCharacterSize();
if ((scale == charSize.width) ||
(this.SHOW_IF_FEATURES && this.featureCount > 0) ) {
this.show();
} else {
Expand All @@ -271,10 +243,10 @@ function( declare, StaticChunked, DraggableFeatureTrack, JSONUtils, Permission,
var leftExtended = leftBase - 2;
var rightExtended = rightBase + 2;

var dnaHeight = charSize.h;
var proteinHeight = charSize.h;
var dnaHeight = charSize.height;
var proteinHeight = charSize.height;

if ( scale == charSize.w ) {
if ( scale == charSize.width ) {
// this.sequenceStore.getRange( this.refSeq, leftBase, rightBase,
// this.sequenceStore.getRange( this.refSeq, leftBase, endBase,
// this.store.getFeatures(
Expand Down Expand Up @@ -478,8 +450,8 @@ function( declare, StaticChunked, DraggableFeatureTrack, JSONUtils, Permission,
var featDiv =
this.renderFeature(feature, uniqueId, block, scale, labelScale, descriptionScale, containerStart, containerEnd);
$(featDiv).addClass("sequence-alteration");

var charSize = this.getCharacterMeasurements();
// var charSize = this.getCharacterMeasurements();
var charSize = this.gview.getSequenceCharacterSize();

var seqNode = $("div.wa-sequence", block).get(0);
// var seqNode = $("div.dna-container", block).get(0);
Expand All @@ -490,7 +462,7 @@ function( declare, StaticChunked, DraggableFeatureTrack, JSONUtils, Permission,

}
else if (ftype == "insertion") {
if ( scale == charSize.w ) {
if ( scale == charSize.width ) {
var container = document.createElement("div");
var residues = feature.get("residues");
$(container).addClass("dna-residues");
Expand All @@ -506,7 +478,7 @@ function( declare, StaticChunked, DraggableFeatureTrack, JSONUtils, Permission,
}
}
else if ((ftype == "substitution")) {
if ( scale == charSize.w ) {
if ( scale == charSize.width ) {
var container = document.createElement("div");
var residues = feature.get("residues");
$(container).addClass("dna-residues");
Expand Down

0 comments on commit 2648e13

Please sign in to comment.