b8180d9f6d41dc708a2f249ba892cbca311e7a06 jcasper Mon Feb 27 11:38:55 2023 -0800 Adding transparency support for colors refs #30569 diff --git src/hg/hgTracks/vcfTrack.c src/hg/hgTracks/vcfTrack.c index 883d7e0..b779bc9 100644 --- src/hg/hgTracks/vcfTrack.c +++ src/hg/hgTracks/vcfTrack.c @@ -1542,32 +1542,32 @@ if (retHapColorMode) *retHapColorMode = getColorMode(tg->tdb); pushWarnHandler(ignoreEm); struct vcfRecord *rec; for (rec = vcff->records; rec != NULL; rec = rec->next) { vcfParseGenotypesGtOnly(rec); } popWarnHandler(); if (*retHapColorMode == functionMode) { if (!exprBedColorsMade) { makeRedGreenShades(hvg); // Make darkerShadesOfGreenOnWhite for local use - static struct rgbColor white = {255, 255, 255}; - static struct rgbColor darkerGreen = {0, 210, 0}; + static struct rgbColor white = {255, 255, 255, 255}; + static struct rgbColor darkerGreen = {0, 210, 0, 255}; hvGfxMakeColorGradient(hvg, &white, &darkerGreen, EXPR_DATA_SHADES, darkerShadesOfGreenOnWhite); } int gStart = winStart - GENE_SIZE_FUDGE; if (gStart < 0) gStart = 0; int gEnd = winEnd + GENE_SIZE_FUDGE; int chromSize = hChromSize(database, chromName); if (gEnd > chromSize) gEnd = chromSize; *retGSeqWin = chromSeqWindowNew(database, chromName, gStart, gEnd); *retTxiList = txInfoLoad(*retGSeqWin, tg->tdb); } else { @@ -1987,31 +1987,31 @@ } static Color rDrawPhyloTreeInLabelArea(struct phyloTree *node, struct hvGfx *hvg, int x, int yOff, double pxPerHap, MgFont *font, struct hash *highlightSamples, struct hash *sampleColors) /* Recursively draw the tree in the left label area. */ { const int branchW = 8; int labelEnd = leftLabelX + leftLabelWidth; Color color = MG_BLACK; if (!sampleColors) { // Misuse the branch length value as RGB color (if it's the typical small number, will still // draw as approximately black): unsigned int rgb = node->ident->length; - color = MAKECOLOR_32( ((rgb>>16)&0xff), ((rgb>>8)&0xff), (rgb&0xff) ); + color = hvGfxFindColorIx(hvg, ((rgb>>16)&0xff), ((rgb>>8)&0xff), (rgb&0xff) ); } if (node->numEdges > 0) { // Draw each child and a horizontal line to child int minY = -1, maxY = 0; Color childColors[node->numEdges]; int ix; for (ix = 0; ix < node->numEdges; ix++) { struct phyloTree *child = node->edges[ix]; childColors[ix] = rDrawPhyloTreeInLabelArea(child, hvg, x+branchW, yOff, pxPerHap, font, highlightSamples, sampleColors); struct nodeCoords *childCoords = child->priv; int childY = yOff + ((0.5 + childCoords->rank) * pxPerHap); hvGfxLine(hvg, x, childY, x+branchW, childY, childColors[ix]); @@ -2026,31 +2026,31 @@ hvGfxLine(hvg, x, minY, x, maxY, color); } else { // Leaf node -- draw a horizontal line, and label if there is space to right of tree struct nodeCoords *coords = node->priv; int yLine = yOff + ((0.5 + coords->rank) * pxPerHap); int yBox = yLine - pxPerHap / 2; int yText = yLine - tl.fontHeight / 2; // Dunno why but the default font seems to draw with the baseline at y while the other fonts // draw with the mid line at y. if (sameOk(tl.textSize, "8")) yText += 2; if (highlightSamples && node->ident->name && hashLookup(highlightSamples, node->ident->name)) hvGfxBox(hvg, leftLabelX, yBox, leftLabelWidth, pxPerHap, - MAKECOLOR_32_A(170, 255, 255, 128)); + hvGfxFindAlphaColorIx(hvg, 170, 255, 255, 128)); if (sampleColors != NULL) color = (Color)hashIntValDefault(sampleColors, node->ident->name, MG_BLACK); hvGfxLine(hvg, x, yLine, x+branchW, yLine, color); int textX = x + branchW + 3; if (pxPerHap >= tl.fontHeight+1 && textX < labelEnd) hvGfxText(hvg, textX, yText, MG_BLACK, font, node->ident->name); } return color; } static void drawPhyloTreeInLabelArea(struct phyloTree *tree, struct hvGfx *hvg, int yOff, int clipHeight, int gtHapCount, MgFont *font, struct hash *highlightSamples, struct hash *sampleColors) { @@ -2076,31 +2076,31 @@ { int ix; for (ix = 0; ix < node->numEdges; ix++) { struct phyloTree *child = node->edges[ix]; rHighlightSampleRows(child, hvg, yOff, pxPerHap, highlightSamples); } } else { // leaf node; highlight if it's in highlightSamples if (node->ident->name && hashLookup(highlightSamples, node->ident->name)) { struct nodeCoords *coords = node->priv; int y = yOff + (coords->rank * pxPerHap); - hvGfxBox(hvg, insideX, y, insideWidth, pxPerHap, MAKECOLOR_32_A(170, 255, 255, 128)); + hvGfxBox(hvg, insideX, y, insideWidth, pxPerHap, hvGfxFindAlphaColorIx(hvg, 170, 255, 255, 128)); } } } static struct hash *getSampleColors(struct trackDb *tdb) /* Return a hash of sample names to colors if specified in tdb, or NULL if none specified. */ { struct hash *sampleColors = NULL; char *setting = cartOrTdbString(cart, tdb, VCF_SAMPLE_COLOR_FILE, NULL); if (isNotEmpty(setting)) { // If the setting has not been set in the cart then we're getting the trackDb setting which // may specify a list of files and possibly labels like "Thing_one=file1 Thing_two=file2". // In that case, pick out the first file. if (strchr(setting, '=') || strchr(setting, ' ')) @@ -2111,32 +2111,32 @@ setting = eq+1; } char *fileName = hReplaceGbdb(setting); struct lineFile *lf = netLineFileMayOpen(fileName); if (lf) { sampleColors = hashNew(0); char *line; while (lineFileNextReal(lf, &line)) { char *words[3]; int wordCount = chopTabs(line, words); lineFileExpectWords(lf, 2, wordCount); char *sample = words[0]; char *colorStr = words[1]; - int rgb = bedParseColor(colorStr); - Color color = MAKECOLOR_32( ((rgb>>16)&0xff), ((rgb>>8)&0xff), (rgb&0xff) ); + unsigned int rgb = bedParseColor(colorStr); + Color color = bedColorToGfxColor(rgb); hashAddInt(sampleColors, sample, color); } lineFileClose(&lf); } else warn("Can't open sampleColorFile '%s'", fileName); } return sampleColors; } static struct hash *getHighlightSamples(struct trackDb *tdb) /* Return a hash of node IDs to highlight in the phylo tree display, or NULL if none specified. */ { struct hash *highlightSamples = NULL; char *setting = cartOrTdbString(cart, tdb, "highlightIds", NULL); @@ -2854,48 +2854,48 @@ hvGfxSetClip(hvgLL, clipXBak, clipYBak, clipWidthBak, clipHeightBak); } static void vcfPhasedSetupHaplotypesLines(struct track *track, struct hvGfx *hvg, int xOff, int yOff, int width, int *retYOffsets, struct slPair *sampleNames, char *childSample, MgFont *font) /* Setup the background for drawing the ticks, the two haplotype lines for each sample, and the * transparent gray box to help distinguish between consecutive samples */ { int sampleHeight = round(track->height / track->customInt); double yHap1 = track->lineHeight; // relative offset of first haplotype line double yHap2 = sampleHeight - track->lineHeight; // relative offset of second line struct slPair *name; int i, y1, y2; struct rgbColor yellow = lightRainbowAtPos(0.2); -int transYellow = MAKECOLOR_32_A(yellow.r, yellow.g, yellow.b, 100); +int transYellow = hvGfxFindAlphaColorIx(hvg, yellow.r, yellow.g, yellow.b, 100); boolean useDefaultLabel = FALSE; if (cartVarExistsAnyLevel(cart, track->tdb, FALSE, VCF_PHASED_DEFAULT_LABEL_VAR)) useDefaultLabel = cartUsualBooleanClosestToHome(cart, track->tdb, FALSE, VCF_PHASED_DEFAULT_LABEL_VAR, FALSE); boolean useAliasLabel = trackDbSettingOn(track->tdb, VCF_PHASED_TDB_USE_ALT_NAMES); if (cartVarExistsAnyLevel(cart, track->tdb, FALSE, VCF_PHASED_ALIAS_LABEL_VAR)) useAliasLabel = cartUsualBooleanClosestToHome(cart, track->tdb, FALSE, VCF_PHASED_ALIAS_LABEL_VAR, FALSE); for (name = sampleNames, i = 0; name != NULL; name = name->next, i++) { y1 = yOff + yHap1 + (i * sampleHeight); y2 = yOff + yHap2 + (i * sampleHeight); retYOffsets[2*i] = y1; retYOffsets[(2*i) + 1] = y2; - // make the background of every other lane light yellow, but only when NOT doing PDF/EPS output - if (hvg->pixelBased && sameString(childSample, name->name)) + // make the background of every other lane light yellow + if (sameString(childSample, name->name)) { hvGfxBox(hvg, xOff, y1-(track->lineHeight), width, (y2 + track->lineHeight) - (y1-track->lineHeight), transYellow); } hvGfxLine(hvg, xOff, y1, xOff+width, y1, MG_BLACK); hvGfxLine(hvg, xOff, y2, xOff+width, y2, MG_BLACK); struct dyString *label = dyStringNew(0); boolean hasAlias = isNotEmpty((char *)name->val); dyStringPrintf(label, "%s%s%s", useDefaultLabel ? name->name : "", useDefaultLabel && useAliasLabel && hasAlias ? "/" : "", useAliasLabel && hasAlias ? (char *)name->val : ""); vcfPhasedAddLabel(track, hvg, label->string, yOff, round(((y1 + y2) / 2) - (track->lineHeight / 2)), font, MG_BLACK); } }