45122968acaa5d7d794247535f27deb94c08e25f
braney
  Sat Jan 10 08:56:23 2015 -0800
fixed scaling problem when zoomed way into very long features (#14505note 33)

diff --git src/hg/hgTracks/simpleTracks.c src/hg/hgTracks/simpleTracks.c
index 5566118..9cb31ff 100644
--- src/hg/hgTracks/simpleTracks.c
+++ src/hg/hgTracks/simpleTracks.c
@@ -1236,32 +1236,38 @@
     {
     if (charsInBox < strlen(label))
         strcpy(shortLabel+charsInBox-3, "...");
     Color labelColor = hvGfxContrastingColor(hvg, color);
     hvGfxTextCentered(hvg, x1, y, w, height, labelColor, font, shortLabel);
     }
 }
 
 void drawScaledBoxSample(struct hvGfx *hvg,
                          int chromStart, int chromEnd, double scale,
                          int xOff, int y, int height, Color color, int score)
 /* Draw a box scaled from chromosome to window coordinates. */
 {
 //int i;
 int x1, x2, w;
-x1 = round((double)(chromStart-winStart)*scale) + xOff;
-x2 = round((double)(chromEnd-winStart)*scale) + xOff;
+int ourStart = chromStart;
+if (ourStart < winStart) 
+    ourStart = winStart;
+int ourEnd = chromEnd;
+if (ourEnd > winEnd) 
+    ourEnd = winEnd;
+x1 = round((double)(ourStart-winStart)*scale) + xOff;
+x2 = round((double)(ourEnd-winStart)*scale) + xOff;
 
 if (x2 >= MAXPIXELS)
     x2 = MAXPIXELS - 1;
 w = x2-x1;
 if (w < 1)
     w = 1;
 hvGfxBox(hvg, x1, y, w, height, color);
 }
 
 
 void filterItems(struct track *tg, boolean (*filter)(struct track *tg, void *item), 
                 char *filterType)
 /* Filter out items from track->itemList. */
 {
 struct slList *newList = NULL, *oldList = NULL, *el, *next;
@@ -2701,32 +2707,38 @@
 	gp = (struct genePred *)(lf->original);
     if (gp && gp->cdsStart != gp->cdsEnd)
         lf->codons = baseColorCodonsFromGenePred(lf, gp, (drawOpt != baseColorDrawDiffCodons), cartUsualBooleanClosestToHome(cart, tg->tdb, FALSE, CODON_NUMBERING_SUFFIX, FALSE));
     }
 if (psl && drawOpt == baseColorDrawCds && !zoomedToCdsColorLevel)
     baseColorSetCdsBounds(lf, psl, tg);
 
 tallStart = lf->tallStart;
 tallEnd = lf->tallEnd;
 if ((tallStart == 0 && tallEnd == 0) && lf->start != 0 && !sameWord(tg->table, "jaxQTL3"))
     {
     // sometimes a bed <8 will get passed off as a bed 8, tsk tsk
     tallStart = lf->start;
     tallEnd   = lf->end;
     }
-x1 = round((double)((int)lf->start-winStart)*scale) + xOff;
-x2 = round((double)((int)lf->end-winStart)*scale) + xOff;
+int ourStart = lf->start;
+if (ourStart < winStart) 
+    ourStart = winStart;
+int ourEnd = lf->end;
+if (ourEnd > winEnd) 
+    ourEnd = winEnd;
+x1 = round((double)((int)ourStart-winStart)*scale) + xOff;
+x2 = round((double)((int)ourEnd-winStart)*scale) + xOff;
 w = x2-x1;
 if (lf->start==lf->end && w==0) // like a SNP insertion point of size=0
     {
     w = 1;
     hvGfxBox(hvg, x1, y, w, heightPer, color);
     return;
     }
 
 // are we highlighting this feature with background highlighting
 if (lf->highlightColor && (lf->highlightMode == highlightBackground))
     {
     // draw the background
     hvGfxBox(hvg, x1, y, w, heightPer, lf->highlightColor);
 
     // draw the item slightly smaller