2ad7640d9646a8968d002801cb68e102cb2f69a4
kate
  Sun Nov 15 12:55:10 2015 -0800
Mostly working with variable heigt item layout in full mode.

diff --git src/hg/hgTracks/gtexTracks.c src/hg/hgTracks/gtexTracks.c
index e64e887..63b921b 100644
--- src/hg/hgTracks/gtexTracks.c
+++ src/hg/hgTracks/gtexTracks.c
@@ -260,30 +260,33 @@
     extras->colors = getGtexTissueColors();
     }
 else
     {
     int expCount = geneBed->expCount;
     extras->colors = getRainbow(&saturatedRainbowAtPos, expCount);
     }
 while (geneBed != NULL)
     {
     AllocVar(geneInfo);
     geneInfo->geneBed = geneBed;
     geneInfo->geneModel = hashFindVal(modelHash, geneBed->geneId);
     slAddHead(&list, geneInfo);
     geneBed = geneBed->next;
     geneInfo->geneBed->next = NULL;
+    if (extras->isComparison && (tg->visibility == tvFull || tg->visibility == tvPack))
+        // compute medians based on configuration (comparisons, and later, filters)
+        loadComputedMedians(geneInfo, extras);
     }
 slReverse(&list);
 tg->items = list;
 }
 
 /***********************************************/
 /* Draw */
 
 /* Bargraph layouts for three window sizes */
 #define WIN_MAX_GRAPH 20000
 #define MAX_GRAPH_HEIGHT 100
 #define MAX_BAR_WIDTH 5
 #define MAX_GRAPH_PADDING 2
 
 #define WIN_MED_GRAPH 500000
@@ -439,42 +442,39 @@
                 double scale, MgFont *font, Color color, enum trackVisibility vis)
 /* Draw tissue expression bar graph over gene model. 
    Optionally, draw a second graph under gene, to compare sample sets */
 {
 struct gtexGeneInfo *geneInfo = (struct gtexGeneInfo *)item;
 struct gtexGeneBed *geneBed = geneInfo->geneBed;
 boolean doLogTransform = cartUsualBooleanClosestToHome(cart, tg->tdb, FALSE, GTEX_LOG_TRANSFORM, 
                                                 GTEX_LOG_TRANSFORM_DEFAULT);
 // Color in dense mode using transcriptClass
 Color statusColor = getTranscriptStatusColor(hvg, geneBed);
 if (vis != tvFull && vis != tvPack)
     {
     bedDrawSimpleAt(tg, geneBed, hvg, xOff, y, scale, font, statusColor, vis);
     return;
     }
-struct gtexGeneExtras *extras = (struct gtexGeneExtras *)tg->extraUiData;
-if (extras->isComparison && (tg->visibility == tvFull || tg->visibility == tvPack))
-        //&& gtexGraphHeight() != MIN_GRAPH_HEIGHT)
-    // compute medians based on configuration (comparisons, and later, filters)
-    loadComputedMedians(geneInfo, extras);
 
 int heightPer = tg->heightPer;
 int graphX = gtexGraphX(geneBed);
 if (graphX < 0)
     return;
 
 int topGraphHeight = gtexGeneGraphHeight(tg, geneInfo, doLogTransform, TRUE);
+if (geneInfo->medians2)
+    topGraphHeight = max(topGraphHeight, tl.fontHeight);
 int yZero = topGraphHeight + y - 1;  // yZero is bottom of graph
 
 #ifndef MULTI_REGION
 int x1 = xOff + graphX;         // x1 is at left of graph
 int keepX = x1;                 // FIXME:  Too many X's!
 drawGraphBase(hvg, keepX, yZero+1, geneInfo);
 
 int startX = x1;
 struct rgbColor lineColor = {.r=0};
 int lineColorIx = hvGfxFindColorIx(hvg, lineColor.r, lineColor.g, lineColor.b);
 int barWidth = gtexBarWidth();
 int graphPadding = gtexGraphPadding();
 char *colorScheme = cartUsualStringClosestToHome(cart, tg->tdb, FALSE, GTEX_COLORS, 
                         GTEX_COLORS_DEFAULT);
 Color labelColor = MG_GRAY;
@@ -485,30 +485,31 @@
 if (geneInfo->medians2)
     {
     hvGfxText(hvg, x1, yZero - tl.fontHeight, labelColor, font, "F");
     hvGfxText(hvg, x1, yZero + gtexGeneHeight() + gtexGeneMargin(), labelColor, font, "M");
     startX = startX + tl.mWidth+2;
     x1 = startX;
     }
 
 // draw bar graph
 // TODO: share this code with other graph
 double viewMax = (double)cartUsualIntClosestToHome(cart, tg->tdb, FALSE, 
                                 GTEX_MAX_LIMIT, GTEX_MAX_LIMIT_DEFAULT);
 double maxMedian = ((struct gtexGeneExtras *)tg->extraUiData)->maxMedian;
 int i;
 int expCount = geneBed->expCount;
+struct gtexGeneExtras *extras = (struct gtexGeneExtras *)tg->extraUiData;
 for (i=0; i<expCount; i++)
     {
     struct rgbColor fillColor = extras->colors[i];
     if (barWidth == 1 && sameString(colorScheme, GTEX_COLORS_GTEX))
         {
         // brighten colors a bit so they'll be more visible at this scale
         fillColor = gtexTissueBrightenColor(fillColor);
         }
     int fillColorIx = hvGfxFindColorIx(hvg, fillColor.r, fillColor.g, fillColor.b);
     double expScore = (geneInfo->medians1 ? geneInfo->medians1[i] : geneBed->expScores[i]);
     int height = valToClippedHeight(expScore, maxMedian, viewMax, 
                                         gtexMaxGraphHeight(), doLogTransform);
     if (graphPadding == 0 || sameString(colorScheme, GTEX_COLORS_GTEX))
         hvGfxBox(hvg, x1, yZero-height+1, barWidth, height, fillColorIx);
     else
@@ -574,35 +575,30 @@
 
 #ifdef MULTI_REGION
 static void gtexGeneNonPropDrawAt(struct track *tg, void *item, struct hvGfx *hvg, int xOff, int y,
                 double scale, MgFont *font, Color color, enum trackVisibility vis)
 {
 struct gtexGeneInfo *geneInfo = (struct gtexGeneInfo *)item;
 struct gtexGeneBed *geneBed = geneInfo->geneBed;
 
 // Color in dense mode using transcriptClass
 // GALT REMOVE Color statusColor = getTranscriptStatusColor(hvg, geneBed);
 if (vis != tvFull && vis != tvPack)
     {
     //GALT bedDrawSimpleAt(tg, geneBed, hvg, xOff, y, scale, font, statusColor, vis);
     return;
     }
-struct gtexGeneExtras *extras = (struct gtexGeneExtras *)tg->extraUiData;
-if (extras->isComparison && (tg->visibility == tvFull || tg->visibility == tvPack))
-        //&& gtexGraphHeight() != MIN_GRAPH_HEIGHT)
-    // compute medians based on configuration (comparisons, and later, filters)
-    loadComputedMedians(geneInfo, extras);
 int i;
 int expCount = geneBed->expCount;
 double maxMedian = ((struct gtexGeneExtras *)tg->extraUiData)->maxMedian;
 struct rgbColor lineColor = {.r=0};
 int lineColorIx = hvGfxFindColorIx(hvg, lineColor.r, lineColor.g, lineColor.b);
 // GALT REMOVE int heightPer = tg->heightPer;
 
 int graphX = gtexGraphX(geneBed);
 if (graphX < 0)
     return;
 int x1 = xOff + graphX; // x1 is at left of graph
 int startX = x1;
 int yZero = gtexMaxGraphHeight() + y - 1; // yZero is at bottom of graph
 
 // draw faint line under graph to delineate extent when bars are missing (tissue w/ 0 expression)
@@ -683,31 +679,35 @@
     }
 }
 #endif
 
 static int gtexGeneItemHeight(struct track *tg, void *item)
 {
 if ((item == NULL) || (tg->visibility == tvSquish) || (tg->visibility == tvDense))
     return 0;
 boolean doLogTransform = cartUsualBooleanClosestToHome(cart, tg->tdb, FALSE, GTEX_LOG_TRANSFORM, 
                                                 GTEX_LOG_TRANSFORM_DEFAULT);
 struct gtexGeneInfo *geneInfo = (struct gtexGeneInfo *)item;
 int topGraphHeight = gtexGeneGraphHeight(tg, geneInfo, doLogTransform, TRUE);
 int bottomGraphHeight = 0;
 boolean isComparison = ((struct gtexGeneExtras *)tg->extraUiData)->isComparison;
 if (isComparison)
-    bottomGraphHeight = gtexGeneGraphHeight(tg, geneInfo, doLogTransform, FALSE);
+    {
+    topGraphHeight = max(topGraphHeight, tl.fontHeight);
+    bottomGraphHeight = max(gtexGeneGraphHeight(tg, geneInfo, doLogTransform, FALSE),
+                                tl.fontHeight) + gtexGeneMargin();
+    }
 int height = topGraphHeight + bottomGraphHeight + gtexGeneMargin() + gtexGeneHeight();
 return height;
 }
 
 static void gtexGeneDrawItemsFull(struct track *tg, int seqStart, int seqEnd,
                                       struct hvGfx *hvg, int xOff, int yOff, int width,
                                       MgFont *font, Color color, enum trackVisibility vis)
 /* Draw GTEx gene graphs in full mode.  Special handling as they are variable height */
 {
 double scale = scaleForWindow(width, seqStart, seqEnd);
 struct slList *item;
 int y = yOff + 1;
 for (item = tg->items; item != NULL; item = item->next)
     {
     tg->drawItemAt(tg, item, hvg, xOff, y, scale, font, color, vis);
@@ -752,46 +752,52 @@
 if (graphX < 0)
     return;
 // x1 is at left of graph
 int x1 = insideX + graphX;
 
 if (geneInfo->medians2)
     {
     // skip over labels in comparison graphs
     x1 = x1 + tl.mWidth+ 2;
     }
 int i = 0;
 
 boolean doLogTransform = cartUsualBooleanClosestToHome(cart, tg->tdb, FALSE, GTEX_LOG_TRANSFORM, 
                                                 GTEX_LOG_TRANSFORM_DEFAULT);
 int topGraphHeight = gtexGeneGraphHeight(tg, geneInfo, doLogTransform, TRUE);
-int yZero = topGraphHeight + y - 1;  // yZero is bottom of graph
+if (geneInfo->medians2)
+    topGraphHeight = max(topGraphHeight, tl.fontHeight);        // label
+int yZero = topGraphHeight + y - 1;  // yZero is bottom of (top) graph
 
 double viewMax = (double)cartUsualIntClosestToHome(cart, tg->tdb, FALSE, 
                                 GTEX_MAX_LIMIT, GTEX_MAX_LIMIT_DEFAULT);
 for (tissue = tissues; tissue != NULL; tissue = tissue->next, i++)
     {
-    int height = valToClippedHeight(geneBed->expScores[i], maxMedian, viewMax, 
+    double expScore =  (geneInfo->medians1 ? geneInfo->medians1[i] : geneBed->expScores[i]);
+    int height = valToClippedHeight(expScore, maxMedian, viewMax, 
                                         gtexMaxGraphHeight(), doLogTransform);
-    mapBoxHc(hvg, start, end, x1, yZero-height, barWidth, height, tg->track, mapItemName, tissue->description);
+    mapBoxHc(hvg, start, end, x1, yZero-height, barWidth, height, tg->track, mapItemName, 
+                tissue->description);
     // add map box to comparison graph
     if (geneInfo->medians2)
         {
         double expScore = geneInfo->medians2[i];
-        int height = valToClippedHeight(expScore, maxMedian, viewMax, gtexMaxGraphHeight(), doLogTransform);
-        int y = yZero + gtexGeneHeight() + gtexGeneMargin();
-        mapBoxHc(hvg, start, end, x1, y, barWidth, height, tg->track, mapItemName, tissue->description);
+        int height = valToClippedHeight(expScore, maxMedian, viewMax, 
+                                        gtexMaxGraphHeight(), doLogTransform);
+        int y = yZero + gtexGeneHeight() + gtexGeneMargin();  // y is top of bottom graph
+        mapBoxHc(hvg, start, end, x1, y, barWidth, height, tg->track, mapItemName, 
+                        tissue->description);
         }
     x1 = x1 + barWidth + padding;
     }
 }
 
 static char *gtexGeneItemName(struct track *tg, void *item)
 /* Return gene name */
 {
 struct gtexGeneInfo *geneInfo = (struct gtexGeneInfo *)item;
 struct gtexGeneBed *geneBed = geneInfo->geneBed;
 return geneBed->name;
 }
 
 static int gtexGeneTotalHeight(struct track *tg, enum trackVisibility vis)
 /* Figure out total height of track. Set in track and also return it */