e506d31b6278bb1251d8b260f75c67fa38c99a27
jcasper
  Thu Jul 23 10:20:01 2026 -0700
Making it possible for multiWig containers to be children of composites, refs #36320

diff --git src/hg/hgTracks/simpleTracks.c src/hg/hgTracks/simpleTracks.c
index ab5191f33b5..343a7df28e0 100644
--- src/hg/hgTracks/simpleTracks.c
+++ src/hg/hgTracks/simpleTracks.c
@@ -15542,31 +15542,31 @@
     }
 }
 #endif
 
 void makeCompositeTrack(struct track *track, struct trackDb *tdb)
 /* Construct track subtrack list from trackDb entry.
  * Sets up color gradient in subtracks if requested */
 {
 buildMathWig(tdb);
 unsigned char finalR = track->color.r, finalG = track->color.g,
                             finalB = track->color.b, finalA = track->color.a;
 unsigned char altR = track->altColor.r, altG = track->altColor.g,
                             altB = track->altColor.b, altA = track->altColor.a;
 unsigned char deltaR = 0, deltaG = 0, deltaB = 0, deltaA = 0;
 
-struct slRef *tdbRef, *tdbRefList = trackDbListGetRefsToDescendantLeaves(tdb->subtracks);
+struct slRef *tdbRef, *tdbRefList = trackDbListGetRefsToDescendantLeavesOrContainers(tdb->subtracks);
 
 struct trackDb *subTdb;
 int subCount = slCount(tdbRefList);
 int altColors = subCount - 1;
 struct track *subtrack = NULL;
 TrackHandler handler;
 boolean smart = FALSE;
 
 /* ignore if no subtracks */
 if (!subCount)
     return;
 
 char *compositeTrack = trackDbLocalSetting(tdb, "compositeTrack");
 /* look out for tracks that manage their own subtracks */
 if (startsWith("wig", tdb->type) || startsWith("bedGraph", tdb->type) ||
@@ -15590,43 +15590,62 @@
                 from black, to the specified color */
     deltaR = (finalR - altR) / altColors;
     deltaG = (finalG - altG) / altColors;
     deltaB = (finalB - altB) / altColors;
     // speculative - no harm, but there's no current way for a track to set its alpha,
     // so both final and altA should be 255
     deltaA = (finalA - altA) / altColors;
     }
 
 /* fill in subtracks of composite track */
 for (tdbRef = tdbRefList; tdbRef != NULL; tdbRef = tdbRef->next)
     {
     subTdb = tdbRef->val;
 
     subtrack = trackFromTrackDb(subTdb);
+    boolean isNestedContainer = (trackDbLocalSetting(subTdb, "container") != NULL);
+    if (isNestedContainer)
+        {
+        /* A container (e.g. multiWig) nested inside the composite.  Build its children
+         * and install the container's aggregate methods (multiWigContainerMethods) so it
+         * draws as a single aggregated row rather than one row per child. */
+        makeContainerTrack(subtrack, subTdb);
+        }
+    else
+        {
         boolean avoidHandler = trackDbSettingOn(tdb, "avoidHandler");
         if (!avoidHandler && ( handler = lookupTrackHandlerClosestToHome(subTdb)) != NULL)
             handler(subtrack);
+        }
 
     /* Add subtrack settings (table, colors, labels, vis & pri).  This is only
      * needed in the "not noInherit" case that hopefully will go away soon. */
     subtrack->track = subTdb->track;
     subtrack->table = subTdb->table;
     subtrack->shortLabel = subTdb->shortLabel;
     subtrack->longLabel = subTdb->longLabel;
     subtrack->priority = subTdb->priority;
     subtrack->parent = track;
 
+    if (isNestedContainer)
+        {
+        /* The container's wig children carry their own colors; skip the composite
+         * color gradient for the container track itself. */
+        slAddHead(&track->subtracks, subtrack);
+        continue;
+        }
+
     /* Add color gradient. */
     if (finalR || finalG || finalB)
 	{
 	subtrack->color.r = altR;
 	subtrack->altColor.r = (255+altR)/2;
 	altR += deltaR;
 	subtrack->color.g = altG;
 	subtrack->altColor.g = (255+altG)/2;
 	altG += deltaG;
 	subtrack->color.b = altB;
 	subtrack->altColor.b = (255+altB)/2;
 	altB += deltaB;
 	subtrack->color.a = altA;
 	subtrack->altColor.a = altA;
 	altA += deltaA;