a33f1b928200549e10005e79e6db16a9d79b801e
braney
  Thu Jan 25 13:37:37 2024 -0800
use summary information in bigBeds when filters are off and there are
too many items in the region

diff --git src/hg/hgTracks/simpleTracks.c src/hg/hgTracks/simpleTracks.c
index 8fd1bd3..5ea5a04 100644
--- src/hg/hgTracks/simpleTracks.c
+++ src/hg/hgTracks/simpleTracks.c
@@ -844,30 +844,31 @@
 /* Most fixed height track groups will use this to figure out the height
  * they use. */
 {
 
 boolean doWiggle = checkIfWiggling(cart, tg);
 if (doWiggle)
     {
     struct wigCartOptions *wigCart = tg->wigCartData;
     if (tg->wigCartData == NULL)
 	{
         // fake the trackDb range for this auto-wiggle
         int wordCount = 3;
         char *words[3];
         words[0] = "bedGraph";
 	wigCart = wigCartOptionsNew(cart, tg->tdb, wordCount, words );
+        wigCart->windowingFunction = wiggleWindowingMean;
 	tg->wigCartData = (void *) wigCart;
 	}
     return wigTotalHeight(tg, vis);
     }
 
 int rows;
 double maxHeight = maximumTrackHeight(tg);
 int itemCount = slCount(tg->items);
 int maxItemsToUseOverflow = maxItemsToOverflow(tg);
 tg->heightPer = heightPer;
 tg->lineHeight = lineHeight;
 
 /* Note that the maxCount variable passed to packCountRowsOverflow()
    is tied to the maximum height allowed for a track and influences
    decisions about when to squish, dense, or overflow a track.
@@ -4943,50 +4944,71 @@
     }
 }
 
 static void countsToPixels(unsigned *counts, struct preDrawContainer *pre)
 /* Sample counts into pixels. */
 {
 unsigned size = winEnd - winStart;
 double countsPerPixel = size / (double) insideWidth;
 
 if (countsPerPixel <= 1.0)
     countsToPixelsUp(counts, pre);
 else
     countsToPixelsDown(counts, pre);
 }
 
+static void summaryToPixels(struct bbiSummaryElement *summary, struct preDrawContainer *pre)
+/* Convert bbiSummaryElement array into a preDrawElement array */
+{
+struct preDrawElement *pe = &pre->preDraw[pre->preDrawZero];
+struct preDrawElement *lastPe = &pe[insideWidth];
+
+for (; pe < lastPe; pe++, summary++)
+    {
+    pe->count = summary->validCount;
+    pe->min = summary->minVal;
+    pe->max = summary->maxVal;
+    pe->sumData = summary->sumData;
+    pe->sumSquares = summary->sumSquares;
+    }
+}
+
 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;
 boolean parentLevel = isNameAtParentLevel(tdb,tdb->track);
 
 char *autoScale = cartOptionalStringClosestToHome(cart, tdb, parentLevel, AUTOSCALE);
 if (autoScale == NULL)
     wigCart->autoScale =  wiggleScaleAuto;
 char *windowingFunction = cartOptionalStringClosestToHome(cart, tdb, parentLevel, WINDOWINGFUNCTION);
 if (windowingFunction == NULL)
     wigCart->windowingFunction = wiggleWindowingMean;
-unsigned *counts = countOverlaps(tg);
 
+if (tg->summary)
+    summaryToPixels(tg->summary, pre);
+else
+    {
+    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);
 }
 
 static void genericDrawItemsPackSquish(struct track *tg, int seqStart, int seqEnd,
                                        struct hvGfx *hvg, int xOff, int yOff, int width,
                                        MgFont *font, Color color, enum trackVisibility vis)
@@ -11398,31 +11420,36 @@
         //if (subCnt > 4)
         //    maxHeight *= 2; // NOTE: Large composites should suffer an additional restriction.
         if (!tg->syncChildVisToSelf)
             {
             for (subtrack = tg->subtracks;  subtrack != NULL; subtrack = subtrack->next)
                 limitVisibility(subtrack);
             }
         }
     if (canWiggle(tg))   // if this is a track type that can wiggle, we want to go straight to that rather than reduce visibility
         {
         while  ((h = tg->totalHeight(tg, vis)) > maxHeight && vis != tvDense)
             {
             tg->limitWiggle = TRUE;
             }
         if ( tg->limitWiggle)   // auto-density coverage is alway tvFull
+            {
+            if (tg->visibility == tvDense)
+                tg->visibility = tg->limitedVis = tvDense;
+            else
                 tg->visibility = tg->limitedVis = tvFull;
+            }
         else
             tg->limitedVis = vis;
         }
     else
         {
         while ((h = tg->totalHeight(tg, vis)) > maxHeight && vis != tvDense)
             {
             if (vis == tvFull && tg->canPack)
                 vis = tvPack;
             else if (vis == tvPack)
                 vis = tvSquish;
             else
                 vis = tvDense;
             }