8e2da4f21d261f3e5481305016a45ed040fc61b0 kate Tue Oct 9 12:24:08 2018 -0700 Partial (interrupted) work to implement right label in pack mode. refs #21917 diff --git src/hg/hgTracks/interactTrack.c src/hg/hgTracks/interactTrack.c index 72652bb..beed63d 100644 --- src/hg/hgTracks/interactTrack.c +++ src/hg/hgTracks/interactTrack.c @@ -234,30 +234,52 @@ int labelEnd = labelStart + labelWidth - 1; if (labelStart <= prevLabelEnd && !(labelStart == prevLabelStart && labelEnd == prevLabelEnd && sameString(otherChrom, prevLabel))) tInfo->doOtherLabels = FALSE; prevLabelStart = labelStart; prevLabelEnd = labelEnd; prevLabel = otherChrom; } } tInfo->fontHeight = vgGetFontPixelHeight(hvg->vg, font); tInfo->otherHeight = (tInfo->otherCount) ? 3 * tInfo->fontHeight : 0; tInfo->sameHeight = (tInfo->sameCount) ? tg->height - tInfo->otherHeight : 0; } +static int interactRightPixels(struct track *tg, void *item) +/* Return number of pixels we need to the right. */ +{ +struct interact *inter = item; +struct interactTrackInfo *tInfo = tg->customPt; +if ((tg->visibility == tvPack || tg->visibility == tvFull) && !tInfo->clusterMode) + { + char *rightLabel = ""; + if (tInfo->isDirectional) + { + if (inter->targetStart == inter->chromStart) + rightLabel = inter->sourceName; + if (inter->targetEnd == inter->chromEnd) + rightLabel = inter->targetName; + } + else + rightLabel = inter->targetName; + return mgFontStringWidth(tl.font, rightLabel); + } +return 0; +} + void interactLoadItems(struct track *tg) /* Load interact items in interact format */ { loadAndFilterItems(tg); struct interactTrackInfo *tInfo = NULL; AllocVar(tInfo); tg->customPt = tInfo; tInfo->isDirectional = interactUiDirectional(tg->tdb); tInfo->offset = interactUiOffset(tg->tdb); tInfo->drawUp = trackDbSettingClosestToHomeOn(tg->tdb, INTERACT_UP); tInfo->clusterMode = interactUiClusterMode(cart, tg->track, tg->tdb); if (tInfo->clusterMode || isLinkedFeaturesMode(tg)) { @@ -714,72 +736,82 @@ } } void interactLinkedFeaturesDrawAt(struct track *tg, void *item, struct hvGfx *hvg, int xOff, int y, double scale, MgFont *font, Color color, enum trackVisibility vis) /* Draw a item with target in contrasting color */ { struct linkedFeatures *lf = item; if (tg->visibility == tvDense) { lf->filterColor = slightlyDarkerColor(hvg, MG_GRAY); // can't distinguish overlapping colors, so force to gray } linkedFeaturesDrawAt(tg, item, hvg, xOff, y, scale, font, color, vis); -struct interactTrackInfo *tInfo = tg->customPt; -// draw overlapping items in white +// draw overlapping items in white and add right label +struct interactTrackInfo *tInfo = tg->customPt; if (tInfo->clusterMode) { struct simpleFeature *sf; int shortHeight = tg->heightPer/2; for (sf = lf->components; sf; sf = sf->next) { if (sf->start > lf->tallStart && sf->end < lf->tallEnd) { drawScaledBox(hvg, sf->start, sf->end, scale, xOff, y + shortHeight/2, shortHeight, MG_WHITE); } } } else { struct simpleFeature *sf1 = lf->components, *sf2 = sf1->next; if (sf2 && sf2->start < sf1->end) { drawScaledBox(hvg, sf2->start, sf2->end, scale, xOff, y, tg->heightPer, MG_WHITE); } + else + { + // right label + int x2 = round((double)((int)lf->end - winStart) * scale) + xOff; + int x = x2 + tl.mWidth/2; + char *label = "foo"; + int w = mgFontStringWidth(font, label); + hvGfxTextCentered(hvg, x, y, w, tg->heightPer, lf->filterColor, font, label); + } } } void interactDrawItems(struct track *tg, int seqStart, int seqEnd, struct hvGfx *hvg, int xOff, int yOff, int width, MgFont *font, Color color, enum trackVisibility vis) /* Draw a list of interact structures. */ { struct interactTrackInfo *tInfo = (struct interactTrackInfo *)tg->customPt; if (tInfo->clusterMode || isLinkedFeaturesMode(tg)) { tg->drawItemAt = interactLinkedFeaturesDrawAt; linkedFeaturesDraw(tg, seqStart, seqEnd, hvg, xOff, yOff, width, font, color, vis); } else // curve, etc. connector display drawInteractItems(tg, seqStart, seqEnd, hvg, xOff, yOff, width, font, color, vis); } void interactMethods(struct track *tg) /* Interact track type methods */ { tg->bedSize = 12; linkedFeaturesMethods(tg); // for most vis and mode settings tg->loadItems = interactLoadItems; +tg->itemRightPixels = interactRightPixels; tg->drawItems = interactDrawItems; } void interactCtMethods(struct track *tg) /* Interact track methods for custom track */ { interactMethods(tg); }