29e8e81cd709a39de50583f01fdfa37d3e3e309b
galt
  Thu Apr 14 16:55:31 2016 -0700
Fixing clipping problem with pgSnp for multi-region. refs #16898

diff --git src/hg/hgTracks/simpleTracks.c src/hg/hgTracks/simpleTracks.c
index b7ce304..7d9d7cc 100644
--- src/hg/hgTracks/simpleTracks.c
+++ src/hg/hgTracks/simpleTracks.c
@@ -10849,69 +10849,61 @@
         reverseComplement(list[i], strlen(list[i]));
         dyStringPrintf(ds, "%s", list[i]);
         if (i != myItem->alleleCount - 1)
             dyStringPrintf(ds, "%s", "/");
         }
     name = cloneString(ds->string);
     freeDyString(&ds);
     }
 /* if no changes needed return bed name */
 if (name == NULL)
     name = cloneString(myItem->name);
 return name;
 }
 
 void pgSnpTextRight(char *display, struct hvGfx *hvg, int x1, int y, int width, int height, Color color, MgFont *font, char *allele, int itemY, int lineHeight)
-/* put text anchored on right upper corner, doing separate colors if needed */
+/* Put text anchored on right upper corner, doing separate colors if needed. */
 {
+struct hvGfx *hvgWhich = hvg;    // There may be a separate image for sideLabel!
 int textX = x1 - width - 2;
 boolean snapLeft = (textX < fullInsideX);
-int clipYBak = 0, clipHeightBak = 0;
-struct hvGfx *hvgWhich = hvg;    // There may be a separate image for sideLabel!
 if (snapLeft)        /* Snap label to the left. */
     {
     if (hvgSide != NULL)
         hvgWhich = hvgSide;
-    hvGfxGetClip(hvgWhich, NULL, &clipYBak, NULL, &clipHeightBak);
-    hvGfxUnclip(hvgWhich);
-    hvGfxSetClip(hvgWhich, leftLabelX, itemY, fullInsideX - leftLabelX, lineHeight); // width was insideWidth
     textX = leftLabelX;
     width = leftLabelWidth-1;
     }
-
+int clipX, clipY, clipWidth, clipHeight;
+hvGfxGetClip(hvgWhich, &clipX, &clipY, &clipWidth, &clipHeight);
+hvGfxUnclip(hvgWhich);
+hvGfxSetClip(hvgWhich, textX, y, width, height);
 if (sameString(display, "freq"))
     {
-    Color allC = MG_BLACK;
+    color = MG_BLACK;
     if (startsWith("A", allele))
-        allC = MG_RED;
+        color = MG_RED;
     else if (startsWith("C", allele))
-        allC = MG_BLUE;
+        color = MG_BLUE;
     else if (startsWith("G", allele))
-        allC = darkGreenColor;
+        color = darkGreenColor;
     else if (startsWith("T", allele))
-        allC = MG_MAGENTA;
-    hvGfxTextRight(hvgWhich, textX, y, width, height, allC, font, allele);
+        color = MG_MAGENTA;
     }
-else
-    {
 hvGfxTextRight(hvgWhich, textX, y, width, height, color, font, allele);
-    }
-if (snapLeft)
-    {
-    hvGfxUnclip(hvgWhich);  // TODO GALT shoulld this be fullInsideX and fullInsideWidth:?
-    hvGfxSetClip(hvgWhich, insideX, clipYBak, insideWidth, clipHeightBak);
-    }
+hvGfxUnclip(hvgWhich);
+hvGfxSetClip(hvgWhich, clipX, clipY, clipWidth, clipHeight);
 }
 
 void pgSnpDrawAt(struct track *tg, void *item, struct hvGfx *hvg, int xOff, int y, double scale, MgFont *font, Color color, enum trackVisibility vis)
 /* Draw the personal genome SNPs at a given position. */
 {
 struct pgSnp *myItem = item;
 boolean cmpl = cartUsualBooleanDb(cart, database, COMPLEMENT_BASES_VAR, FALSE);
 char *display = "freq"; //cartVar?
 if (revCmplDisp)
    cmpl = !cmpl;
 if (vis == tvSquish || vis == tvDense || myItem->alleleCount > 2)
     {
     withIndividualLabels = TRUE; //haven't done label for this one
     bedDrawSimpleAt(tg, myItem, hvg, xOff, y, scale, font, color, vis);
     return;
@@ -11110,31 +11102,31 @@
     dyStringPrintf(ds, "%s:%s ", all[i], freq[i]);
     }
 mapBoxHgcOrHgGene(hvg, start, end, x, y, width, height, tg->track,
                   mapItemName, ds->string, directUrl, withHgsid, NULL);
 freeDyString(&ds);
 }
 
 void pgSnpLeftLabels(struct track *tg, int seqStart, int seqEnd,
 		     struct hvGfx *hvg, int xOff, int yOff, int width, int height,
 		     boolean withCenterLabels, MgFont *font, Color color,
 		     enum trackVisibility vis)
 /* pgSnp draws its own left labels when it draws the item in pack or full mode.
  * We don't want the default left labels when in full mode because they can overlap
  * with the item-drawing labels, but we do still need dense mode left labels. */
 {
-if (tg->visibility == tvDense)
+if (vis == tvDense)
     {
     if (isCenterLabelIncluded(tg))
 	yOff += mgFontLineHeight(font);
     hvGfxTextRight(hvg, leftLabelX, yOff, leftLabelWidth-1, tg->lineHeight,
 		   color, font, tg->shortLabel);
     }
 }
 
 void pgSnpMethods (struct track *tg)
 /* Personal Genome SNPs: show two alleles with stacked color bars for base alleles and
  * (if available) allele counts in mouseover. */
 {
 bedMethods(tg);
 tg->loadItems = loadPgSnp;
 tg->freeItems = freePgSnp;