c15c2bb4fb6c8f010db048072e7d41c6e3965453 giardine Wed Mar 16 07:48:43 2011 -0700 pgSnp track: move labels over if run out of room on left, fix bug that lost labels on following tracks. Redmine 3225, 3207 diff --git src/hg/hgTracks/simpleTracks.c src/hg/hgTracks/simpleTracks.c index 4effd0f..8af6786 100644 --- src/hg/hgTracks/simpleTracks.c +++ src/hg/hgTracks/simpleTracks.c @@ -3037,30 +3037,31 @@ { int w = x2-textX; /* Arrows? */ if (w > 0) { if (nextItemCompatible(tg)) genericDrawNextItemStuff(tg, hvg, vis, item, x2, textX, y, tg->heightPer, FALSE, color); else { tg->mapItem(tg, hvg, item, tg->itemName(tg, item), tg->mapItemName(tg, item), s, e, textX, y, w, tg->heightPer); } } } + withIndividualLabels = TRUE; /* reset in case done with pgSnp */ } static void genericDrawItemsPackSquish(struct track *tg, int seqStart, int seqEnd, struct hvGfx *hvg, int xOff, int yOff, int width, MgFont *font, Color color, enum trackVisibility vis) /* genericDrawItems logic for pack and squish modes */ { double scale = scaleForWindow(width, seqStart, seqEnd); int lineHeight = tg->lineHeight; struct spaceNode *sn; int maxHeight = maximumTrackHeight(tg); int overflowRow = (maxHeight - tl.fontHeight +1) / lineHeight; boolean firstOverflow = TRUE; @@ -9535,50 +9536,66 @@ { reverseComplement(list[i], strlen(list[i])); dyStringPrintf(ds, "%s", list[i]); if (i != myItem->alleleCount - 1) dyStringPrintf(ds, "%s", "/"); } name = cloneString(ds->string); freeDyString(&ds); } /* if no changes needed return bed name */ if (name == NULL) name = cloneString(myItem->name); return name; } -void pgSnpTextRight(char *display, struct hvGfx *hvg, int x1, int y, int width, int height, Color color, MgFont *font, char *allele) -/* put text on right, doing separate colors if needed */ +void pgSnpTextRight(char *display, struct hvGfx *hvg, int x1, int y, int width, int height, Color color, MgFont *font, char *allele, int trackY, int trackHeight) +/* put text anchored on right upper corner, doing separate colors if needed */ { +boolean snapLeft = FALSE; +int textX = x1 - width; +snapLeft = (textX < insideX); +if (snapLeft) /* Snap label to the left. */ + { + hvGfxUnclip(hvg); + hvGfxSetClip(hvg, leftLabelX, trackY, insideWidth, trackHeight); + x1 = leftLabelX; + width = leftLabelWidth-1; + } + if (sameString(display, "freq")) { Color allC = MG_BLACK; if (startsWith("A", allele)) allC = MG_RED; else if (startsWith("C", allele)) allC = MG_BLUE; else if (startsWith("G", allele)) allC = darkGreenColor; else if (startsWith("T", allele)) allC = MG_MAGENTA; hvGfxTextRight(hvg, x1, y, width, height, allC, font, allele); } else { hvGfxTextRight(hvg, x1, y, width, height, color, font, allele); } +if (snapLeft) + { + hvGfxUnclip(hvg); + hvGfxSetClip(hvg, insideX, trackY, insideWidth, trackHeight); + } } void pgSnpDrawAt(struct track *tg, void *item, struct hvGfx *hvg, int xOff, int y, double scale, MgFont *font, Color color, enum trackVisibility vis) /* Draw the personal genome SNPs at a given position. */ { struct pgSnp *myItem = item; boolean cmpl = cartUsualBooleanDb(cart, database, COMPLEMENT_BASES_VAR, FALSE); char *display = "freq"; //cartVar? if (revCmplDisp) cmpl = !cmpl; if (vis == tvSquish || vis == tvDense || myItem->alleleCount > 2) { withIndividualLabels = TRUE; //haven't done label for this one bedDrawSimpleAt(tg, myItem, hvg, xOff, y, scale, font, color, vis); return; @@ -9641,71 +9658,75 @@ } } } else { pgSnpDrawScaledBox(hvg, myItem->chromStart, myItem->chromEnd, scale, xOff, y, tg->heightPer, color); } /* determine graphics attributes for vgTextCentered */ int allHeight = trunc(tg->heightPer / 2); int allWidth = mgFontStringWidth(font, allele[0]); int all2Width = 0; if (cnt > 1) + { all2Width = mgFontStringWidth(font, allele[1]); + if (all2Width > allWidth) + allWidth = all2Width; /* use max */ + } int yCopy = y + 1; /* allele 1, should be insertion if doesn't fit */ -if (allWidth >= w || all2Width >= w || sameString(display, "freq")) +if (sameString(display, "freq")) { if (cmpl) complement(allele[0], strlen(allele[0])); if (revCmplDisp) reverseComplement(allele[0], strlen(allele[0])); - pgSnpTextRight(display, hvg, x1-allWidth-2, yCopy, allWidth, allHeight, color, font, allele[0]); + pgSnpTextRight(display, hvg, x1-allWidth-2, yCopy, allWidth, allHeight, color, font, allele[0], y, tg->height); } else { if (cartUsualBooleanDb(cart, database, COMPLEMENT_BASES_VAR, FALSE)) complement(allele[0], strlen(allele[0])); /* sequence in box automatically reversed with browser */ spreadBasesString(hvg, x1, yCopy, w, allHeight, MG_WHITE, font, allele[0], strlen(allele[0]), FALSE); } if (cnt > 1) { /* allele 2 */ yCopy += allHeight; - if (allWidth >= w || all2Width >= w || sameString(display, "freq")) + if (sameString(display, "freq")) { if (cmpl) complement(allele[1], strlen(allele[1])); if (revCmplDisp) reverseComplement(allele[1], strlen(allele[1])); - pgSnpTextRight(display, hvg, x1-all2Width-2, yCopy, all2Width, allHeight, color, font, allele[1]); + pgSnpTextRight(display, hvg, x1-allWidth-2, yCopy, allWidth, allHeight, color, font, allele[1], y, tg->height); } else { if (cartUsualBooleanDb(cart, database, COMPLEMENT_BASES_VAR, FALSE)) complement(allele[1], strlen(allele[1])); spreadBasesString(hvg, x1, yCopy, w, allHeight, MG_WHITE, font, allele[1], strlen(allele[1]), FALSE); } } /* map box for link, when text outside box */ -if (allWidth >= w || all2Width >= w || sameString(display, "freq")) +if (allWidth >= w || sameString(display, "freq")) { tg->mapItem(tg, hvg, item, tg->itemName(tg, item), tg->mapItemName(tg, item), myItem->chromStart, myItem->chromEnd, x1-allWidth-2, yCopy, allWidth+w, tg->heightPer); } withIndividualLabels = FALSE; //turn labels off, done already } int pgSnpHeight (struct track *tg, enum trackVisibility vis) { int f = tl.fontHeight; int t = f + 1; if (vis != tvDense) { f = f*2;