432d18c69970f3fcaed4388399b9e3e2b14ca07d
tdreszer
  Sun Mar 27 17:56:25 2011 -0700
redmine 1876.  Hopefully fixed. Subtracks were going through limitVisibility() before their items were loaded.
diff --git src/hg/hgTracks/simpleTracks.c src/hg/hgTracks/simpleTracks.c
index 65d67e1..3459857 100644
--- src/hg/hgTracks/simpleTracks.c
+++ src/hg/hgTracks/simpleTracks.c
@@ -9363,81 +9363,102 @@
 struct track *subtrack;
 int ct = 0;
 for (subtrack = trackList; subtrack; subtrack = subtrack->next)
     if (isSubtrackVisible(subtrack))
         ct++;
 return ct;
 }
 
 enum trackVisibility limitVisibility(struct track *tg)
 /* Return default visibility limited by number of items and
  * by parent visibility if part of a coposite track.
  * This also sets tg->height. */
 {
 if (!tg->limitedVisSet)
     {
-    tg->limitedVisSet = TRUE;
+    tg->limitedVisSet = TRUE;  // Prevents recursive loop!
     if (trackShouldUseAjaxRetrieval(tg))
         {
         tg->limitedVis = tg->visibility;
         tg->height = REMOTE_TRACK_HEIGHT;
         }
     else
         {
         enum trackVisibility vis = tg->visibility;
         int h;
         int maxHeight = maximumTrackHeight(tg);
 
         if (vis == tvHide)
             {
             tg->height = 0;
             tg->limitedVis = tvHide;
             return tvHide;
             }
         if (tg->subtracks != NULL)
             {
             struct track *subtrack;
             int subCnt = subtrackCount(tg->subtracks);
-            maxHeight = maxHeight * max(subCnt,1);
+            maxHeight = maxHeight * max(subCnt,1);  // Without further restruction does this ever accomplish anything?
+            //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);
 		}
             }
         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;
+            //if (tg->visibility != vis)
+            //    warn("DEMOTION: %s -> %s %s  maxHeight:%d  totHeight:%d",
+            //         hStringFromTv(tg->visibility),hStringFromTv(vis),tg->track,maxHeight,tg->height);
             }
         tg->height = h;
+        if (tg->limitedVis == tvHide)
         tg->limitedVis = vis;
+        else
+            tg->limitedVis = tvMin(vis,tg->limitedVis);
         }
+
     if (tg->syncChildVisToSelf)
         {
 	struct track *subtrack;
 	for (subtrack = tg->subtracks;  subtrack != NULL; subtrack = subtrack->next)
 	    {
 	    subtrack->visibility = tg->visibility;
 	    subtrack->limitedVis = tg->limitedVis;
 	    subtrack->limitedVisSet = tg->limitedVisSet;
 	    }
 	}
+    else if (tdbIsComposite(tg->tdb)) // If a composite is restricted, it's children should be atleast as restricted.
+        {
+        struct track *subtrack;
+        for (subtrack = tg->subtracks;  subtrack != NULL; subtrack = subtrack->next)
+            {
+            subtrack->limitedVis = tvMin(subtrack->limitedVis, tg->limitedVis);
+            //subtrack->limitedVisSet = tg->limitedVisSet; // But don't prevent subtracks from being further restricted!
+            }
+        }
+
+    if (tg->height == 0 && tg->limitedVis != tvHide)
+        tg->limitedVisSet = FALSE;  // Items may not be loaded yet, so going to need to check again
     }
 return tg->limitedVis;
 }
 
 void compositeTrackVis(struct track *track)
 /* set visibilities of subtracks */
 {
 struct track *subtrack;
 
 if (track->visibility == tvHide)
     return;
 
 /* Count visible subtracks. */
 for (subtrack = track->subtracks; subtrack != NULL; subtrack = subtrack->next)
     if (!subtrack->limitedVisSet)