04f62f226b0167adf59cc4b55980423164992934 angie Thu Apr 2 14:37:49 2020 -0700 Fix bug that David H noticed in 'hapClusterMethod fileOrder' mode: depending on what tracks are viewed, sometimes sample labels were clipped instead of displayed. refs #25197 diff --git src/hg/hgTracks/vcfTrack.c src/hg/hgTracks/vcfTrack.c index 21be9fc..76913db 100644 --- src/hg/hgTracks/vcfTrack.c +++ src/hg/hgTracks/vcfTrack.c @@ -1097,63 +1097,73 @@ colorMode); // Draw as much of the tree as can fit in the left label area: int extraPixel = (colorMode == altOnlyMode) ? 1 : 0; int hapHeight = tg->height- CLIP_PAD - 2*extraPixel; struct yFromNodeHelper yHelper = {0, NULL, NULL}; initYFromNodeHelper(&yHelper, yOff+extraPixel, hapHeight, gtHapCount, gtHapOrder, vcff->genotypeCount); struct titleHelper titleHelper = { NULL, 0, 0, 0, 0, NULL, NULL }; initTitleHelper(&titleHelper, tg->track, startIx, centerIx, endIx, nRecords, vcff); char *treeAngle = cartOrTdbString(cart, tg->tdb, VCF_HAP_TREEANGLE_VAR, VCF_DEFAULT_HAP_TREEANGLE); boolean drawRectangle = sameString(treeAngle, VCF_HAP_TREEANGLE_RECTANGLE); drawTreeInLabelArea(ht, hvg, yOff+extraPixel, hapHeight+CLIP_PAD, &yHelper, &titleHelper, drawRectangle); } -static void drawSampleLabels(struct vcfFile *vcff, boolean isAllDiploid, int yStart, int height, +static void drawSampleLabels(struct vcfFile *vcff, struct hvGfx *hvg, + boolean isAllDiploid, int yStart, int height, unsigned short *gtHapOrder, int gtHapCount, MgFont *font, Color color, char *track) /* Draw sample names as left labels. */ { +// Figure out which hvg to use, save current clipping, and clip to left label coords: +struct hvGfx *hvgLL = (hvgSide != NULL) ? hvgSide : hvg; +int clipXBak, clipYBak, clipWidthBak, clipHeightBak; +hvGfxGetClip(hvgLL, &clipXBak, &clipYBak, &clipWidthBak, &clipHeightBak); +hvGfxUnclip(hvgLL); +hvGfxSetClip(hvgLL, leftLabelX, yStart, leftLabelWidth, height); if (isAllDiploid) { double pxPerGt = (double)height / vcff->genotypeCount; if (pxPerGt < tl.fontHeight + 1) warn("track %s: drawSampleLabels called with insufficient height", track); int gtIx; for (gtIx = 0; gtIx < vcff->genotypeCount; gtIx++) { int y = gtIx * pxPerGt; - hvGfxTextRight(hvgSide, leftLabelX, y+yStart, leftLabelWidth-1, (int)pxPerGt, + hvGfxTextRight(hvgLL, leftLabelX, y+yStart, leftLabelWidth-1, (int)pxPerGt, color, font, vcff->genotypeIds[gtIx]); } } else { double pxPerHt = (double)height / gtHapCount; if (pxPerHt < tl.fontHeight + 1) warn("track %s: drawSampleLabels called with insufficient height", track); int orderIx; for (orderIx = 0; orderIx < gtHapCount; orderIx++) { int gtHapIx = gtHapOrder[orderIx]; int gtIx = (gtHapIx >> 1); int y = gtIx * pxPerHt; - hvGfxTextRight(hvgSide, leftLabelX, y+yStart, leftLabelWidth-1, (int)pxPerHt, + hvGfxTextRight(hvgLL, leftLabelX, y+yStart, leftLabelWidth-1, (int)pxPerHt, color, font, vcff->genotypeIds[gtIx]); } } +// Restore the prior clipping: +hvGfxUnclip(hvgLL); +hvGfxSetClip(hvgLL, clipXBak, clipYBak, clipWidthBak, clipHeightBak); } static void drawSampleTitles(struct vcfFile *vcff, int yStart, int height, unsigned short *gtHapOrder, int gtHapCount, char *track) /* Draw mouseover labels / titles with the samples that are drawn at each pixel y offset */ { double hapPerPx = (double)gtHapCount / height; int labelEnd = leftLabelX + leftLabelWidth; struct dyString *dy = dyStringNew(0); int y; for (y = 0; y < height; y++) { dyStringClear(dy); int gtHapStart = y * hapPerPx; int gtHapEnd = (y + 1) * hapPerPx; @@ -1229,31 +1239,31 @@ unsigned short *gtHapOrder = gtHapOrderFromGtOrder(vcff, &isAllDiploid, >HapCount); struct vcfRecord *rec; for (rec = vcff->records; rec != NULL; rec = rec->next) drawOneRec(rec, gtHapOrder, gtHapCount, tg, hvg, xOff, yOff, width, FALSE, FALSE, colorMode); // If height is sufficient, draw sample names as left labels; otherwise make mouseover titles // with sample names for each pixel y offset. int extraPixel = (colorMode == altOnlyMode) ? 1 : 0; int hapHeight = tg->height - CLIP_PAD - 2*extraPixel; int minHeightForLabels; if (isAllDiploid) minHeightForLabels = vcff->genotypeCount * (tl.fontHeight + 1); else minHeightForLabels = gtHapCount * (tl.fontHeight + 1); if (hapHeight >= minHeightForLabels) - drawSampleLabels(vcff, isAllDiploid, yOff+extraPixel, hapHeight, gtHapOrder, gtHapCount, + drawSampleLabels(vcff, hvg, isAllDiploid, yOff+extraPixel, hapHeight, gtHapOrder, gtHapCount, font, color, tg->track); else drawSampleTitles(vcff, yOff+extraPixel, hapHeight, gtHapOrder, gtHapCount, tg->track); } static struct phyloTree *getTreeFromFile(struct trackDb *tdb) /* Get the filename that follows trackDb setting 'hapClusterMethod treeFile ' and read it in * as a phyloTree. */ { char *hapMethod = cloneString(trackDbSetting(tdb, VCF_HAP_METHOD_VAR)); if (! startsWithWord(VCF_HAP_METHOD_TREE_FILE, nextWord(&hapMethod))) errAbort("getTreeFromFile: expected trackDb setting " VCF_HAP_METHOD_VAR "to start with '" VCF_HAP_METHOD_TREE_FILE "' followed by a file name, but got '%s'", hapMethod); char *fileName = nextWord(&hapMethod); return phyloOpenTree(fileName);