1ec6923b8825dc073e01796be7e818e1e08c34ac
braney
  Wed Mar 15 15:01:38 2017 -0700
fix some problem with converage graphs

diff --git src/hg/hgTracks/simpleTracks.c src/hg/hgTracks/simpleTracks.c
index a1ca32a..0d48afb 100644
--- src/hg/hgTracks/simpleTracks.c
+++ src/hg/hgTracks/simpleTracks.c
@@ -4464,31 +4464,31 @@
     // add in all the counts that are totally in this pixel
     for(; startUns < endUns; startUns++)
 	{
 	realCount += 1.0;
 	realSum += counts[startUns];
 	realSumSquares += counts[startUns] * counts[startUns];
 	if (max < counts[startUns])
 	    max = counts[startUns];
 	if (min > counts[startUns])
 	    min = counts[startUns];
 	}
 
     // add any fraction of the count that's only partially in this pixel
     double lastFrac = endReal - endUns;
     double lastSum = lastFrac * counts[endUns];
-    if (lastFrac > 0.0)
+    if ((lastFrac > 0.0) && (endUns < size))
 	{
 	if (max < counts[endUns])
 	    max = counts[endUns];
 	if (min > counts[endUns])
 	    min = counts[endUns];
 	realCount += lastFrac;
 	realSum += lastSum;
 	realSumSquares += lastSum * lastSum;
 	}
 
     pe->count = normalizeCount(pe, realCount, min, max, realSum, realSumSquares);
     }
 }
 
 static void countsToPixels(unsigned *counts, struct preDrawContainer *pre)
@@ -4496,31 +4496,37 @@
 {
 unsigned size = winEnd - winStart;
 double countsPerPixel = size / (double) insideWidth;
 
 if (countsPerPixel <= 1.0)
     countsToPixelsUp(counts, pre);
 else
     countsToPixelsDown(counts, pre);
 }
 
 static void genericDrawItemsWiggle(struct track *tg, int seqStart, int seqEnd,
                                        struct hvGfx *hvg, int xOff, int yOff, int width,
                                        MgFont *font, Color color, enum trackVisibility vis)
 /* Draw a list of linked features into a wiggle. */
 {
+struct wigCartOptions *wigCart = tg->wigCartData;
 struct preDrawContainer *pre = tg->preDrawContainer = initPreDrawContainer(insideWidth);
+struct trackDb *tdb = tg->tdb;
+if (hashFindVal(tdb->settingsHash, AUTOSCALE) == NULL)
+    wigCart->autoScale =  wiggleScaleAuto;
+if (hashFindVal(tdb->settingsHash, WINDOWINGFUNCTION) == NULL)
+    wigCart->windowingFunction = wiggleWindowingMax;
 unsigned *counts = countOverlaps(tg);
 
 countsToPixels(counts, pre);
 freez(&counts);
 
 tg->colorShades = shadesOfGray;
 hvGfxSetClip(hvg, insideX, yOff, insideWidth, tg->height);
 tg->mapsSelf = FALSE; // some magic to turn off the link out
 wigPreDrawPredraw(tg, seqStart, seqEnd, hvg, xOff, yOff, width, font, color, vis,
 	       tg->preDrawContainer, tg->preDrawContainer->preDrawZero, tg->preDrawContainer->preDrawSize, &tg->graphUpperLimit, &tg->graphLowerLimit);
 wigDrawPredraw(tg, seqStart, seqEnd, hvg, xOff, yOff, width, font, color, vis,
 	       tg->preDrawContainer, tg->preDrawContainer->preDrawZero, tg->preDrawContainer->preDrawSize, tg->graphUpperLimit, tg->graphLowerLimit);
 tg->mapsSelf = TRUE;
 hvGfxUnclip(hvg);
 }