5c16e9df442a6a66c91f8cbf52f7543cb9cb4517
braney
  Mon Dec 6 16:34:22 2021 -0800
add new function to the graphics library to put text in a box that is
used by the logo function of wiggle draws

diff --git src/hg/hgTracks/wigTrack.c src/hg/hgTracks/wigTrack.c
index 42afbfa..28e506a 100644
--- src/hg/hgTracks/wigTrack.c
+++ src/hg/hgTracks/wigTrack.c
@@ -1158,30 +1158,31 @@
 	    grayValue = min(grayValue,graphUpperLimit);
 	    grayIndex = ((grayValue-graphLowerLimit)/graphRange)*MAX_WIG_VALUE;
 
 	    drawColor =
 		tg->colorShades[grayInRange(grayIndex, 0, MAX_WIG_VALUE)];
 	    doLine(image, x, yOff, tg->lineHeight, drawColor);
             }   /*	vis == tvDense || vis == tvSquish	*/
 	}	/*	if (preDraw[].count)	*/
     }	/*	for (x1 = 0; x1 < width; ++x1)	*/
 
 if (dropMouseOverData)
     slFreeList(&mouseOverData);
 return(mouseOverData);
 }	/*	graphPreDraw()	*/
 
+#ifdef NOTNOW
 static void drawLogoChar( struct hvGfx *hvg, int xOff, int yOff, struct dnaMotif *motif, int width, int height, int count, boolean flip)
 {
 int orangeColor = hvGfxFindColorIx(hvg, 230, 130, 0);
 int blueColor = hvGfxFindColorIx(hvg, 0,114,198);
 int greenColor = hvGfxFindColorIx(hvg, 28,206,40);
 
 int ii;
 FILE *f;
 struct tempName pngTn;
 unsigned char *buf;
 
 buf = needMem(width + 1);
 makeTempName(&pngTn, "logo", ".pgm");
 dnaMotifToLogoPGM(motif, width / count, width  , (double)height - 2, NULL, "../trash", pngTn.forCgi);
 
@@ -1210,30 +1211,31 @@
 
     if (flip)
         {
         int pos = yOff + height - ii;
         hvGfxVerticalSmear(hvg,xOff,pos,width ,1, colors,TRUE);
             //        hvGfxBox(hvg, xOff, pos, width, 1, MG_BLACK);
         }
     else
         hvGfxVerticalSmear(hvg,xOff,yOff+ii,width ,1, colors,TRUE);
     }
 hvGfxUnclip(hvg);
 
 fclose(f);
 remove(pngTn.forCgi);
 }
+#endif
 
 struct dnaMotif *getMotif(int numBases)
 {
 struct dnaMotif *motif;
 AllocVar(motif);
 motif->name = NULL;
 motif->columnCount = numBases;
 motif->aProb = needMem(sizeof(float) * motif->columnCount);
 motif->cProb = needMem(sizeof(float) * motif->columnCount);
 motif->gProb = needMem(sizeof(float) * motif->columnCount);
 motif->tProb = needMem(sizeof(float) * motif->columnCount);
 
 return motif;
 }
 
@@ -1403,30 +1405,60 @@
                         }
                     }
 
                 int boxHeight = max(1,abs(y1 - y0));
                 int boxTop = min(y1,y0);
 
                 //	positive data value exactly equal to Bottom pixel
                 //  make sure it draws at least a pixel there
                 if (boxTop == h)
                     boxTop = h - 1;
 
                 // negative data value exactly equal to top pixel
                 // make sure it draws something
                 double prob = (double)(dataValue) / (graphUpperLimit - graphLowerLimit);
                     
+                char string[2];
+                string[0] = toupper(base);
+                string[1] = 0;
+                MgFont *font = tl.font;
+                int height = dataValue * scaleFactor;
+                unsigned color = MG_BLACK;
+                if (base == 'a')
+                    color = MG_RED;
+                else if (base == 't')
+                    color = MG_GREEN;
+                else if (base == 'c')
+                    color = MG_BROWN;
+                else if (base == 'g')
+                    color = MG_BLUE;
+                if (abs(dataValue) > 0.1)
+                    {
+                    if (dataValue < 0)
+                        {
+                        //hvGfxBox(image, x, yOff+graphUpperLimit * scaleFactor, width, -height, MG_RED);
+                        hvGfxTextInBox(hvg, x, yOff+graphUpperLimit * scaleFactor, width - 1, dataValue * scaleFactor,
+                            color, font, string);
+                        }
+                    else
+                        {
+                       // hvGfxBox(image, x, yOff-height+graphUpperLimit * scaleFactor, width, height, MG_RED);
+
+                        hvGfxTextInBox(hvg, x, yOff-height+graphUpperLimit * scaleFactor, width - 1, dataValue * scaleFactor,
+                            color, font, string);
+                        }
+                    }
                 if (((boxTop+boxHeight) == 0) && !isnan(dataValue))
                     boxHeight += 1;
                 struct dnaMotif *motif;
                 if (dataValue < 0)
                     {
                     motif = motifNeg;
                     prob = -prob;
                     }
                 else
                     motif = motifPos;
                 if (base == 'a')
                     motif->aProb[baseNum] = prob;
                 if (base == 't')
                     motif->tProb[baseNum] = prob;
                 if (base == 'c')
@@ -1439,33 +1471,30 @@
 	    if ((yOffsets != NULL) && (numTrack > 0))
 		stackValue += yOffsets[(numTrack-1) *  width + x1];
 	    if (stackValue > graphUpperLimit)
                 {
 		doLine(image, x, yOff, 2, clipColor);
                 }
 	    else if (stackValue < graphLowerLimit)
                 {
 		doLine(image, x, yOff + h - 1, 2, clipColor);
                 }
 #undef scaleHeightToPixels	/* No longer use this symbol */
             }   /*	vis == tvFull || vis == tvPack */
         }
     }	/*	for (x1 = 0; x1 < width; ++x1)	*/
 
-drawLogoChar( hvg, xOff, yOff + graphLowerLimit * scaleFactor, motifPos, width, tg->lineHeight, numBases, FALSE);
-drawLogoChar( hvg, xOff, yOff + graphUpperLimit * scaleFactor, motifNeg, width, tg->lineHeight, numBases, TRUE);
-
 if (dropMouseOverData)
     slFreeList(&mouseOverData);
 return(mouseOverData);
 }
 
 
 struct wigMouseOver *graphPreDrawContainer(struct preDrawContainer *preDrawContainer,
     int preDrawZero, int width, struct track *tg, struct hvGfx *hvg,
     int xOff, int yOff, double graphUpperLimit, double graphLowerLimit,
     double graphRange, enum trackVisibility vis, struct wigCartOptions *wigCart)
 /* Draw the graphs for all tracks in container. */
 {
 double epsilon = graphRange / tg->lineHeight;
 struct preDrawElement *preDraw = preDrawContainer->preDraw;
 Color *colorArray = makeColorArray(preDraw, width, preDrawZero, wigCart, tg, hvg);