7c4f3c1acfd16636e8d812338fd612cd5f755f23 kate Tue Apr 11 10:16:31 2017 -0700 Add map boxes to graph background (JK request) and item label (for zero-expression items). refs #18736 diff --git src/hg/hgTracks/barChartTrack.c src/hg/hgTracks/barChartTrack.c index c87861c..d427625 100644 --- src/hg/hgTracks/barChartTrack.c +++ src/hg/hgTracks/barChartTrack.c @@ -26,30 +26,31 @@ char *unit; /* Units for category values (e.g. RPKM) */ struct barChartCategory *categories; /* Category names, colors, etc. */ int categCount; /* Count of categories - derived from above */ char **categNames; /* Category names - derived from above */ char **categLabels; /* Category labels - derived from above */ struct rgbColor *colors; /* Colors for all categories */ struct hash *categoryFilter; /* NULL out excluded factors */ }; struct barChartItem /* BED item plus computed values for display */ { struct barChartItem *next; /* Next in singly linked list */ struct bed *bed; /* Item coords, name, exp count and values */ int height; /* Item height in pixels */ + // TODO: add chartWidth so it's just computed once }; /***********************************************/ /* Organize category info */ struct barChartCategory *getCategories(struct track *tg) /* Get and cache category info */ { struct barChartTrack *info = (struct barChartTrack *)tg->extraUiData; if (info->categories == NULL) info->categories = barChartUiGetCategories(database, tg->tdb); return info->categories; } int getCategoryCount(struct track *tg) @@ -625,103 +626,94 @@ static void barChartMapItem(struct track *tg, struct hvGfx *hvg, void *item, char *itemName, char *mapItemName, int start, int end, int x, int y, int width, int height) /* Create a map box on item and label, and one for each category (bar in the graph) in * pack or full mode. Just single map for squish/dense modes */ { if (tg->limitedVis == tvDense) { genericMapItem(tg, hvg, item, itemName, itemName, start, end, x, y, width, height); return; } struct barChartTrack *extras = (struct barChartTrack *)tg->extraUiData; struct barChartItem *itemInfo = (struct barChartItem *)item; struct bed *bed = (struct bed *)itemInfo->bed; int itemStart = bed->chromStart; int itemEnd = bed->chromEnd; +int x1, x2; if (tg->limitedVis == tvSquish) { int categId = maxCategoryForItem(bed, SPECIFICITY_THRESHOLD); char *maxCateg = ""; if (categId > 1) maxCateg = getCategoryLabel(tg, categId); char buf[128]; safef(buf, sizeof buf, "%s %s", bed->name, maxCateg); - int x1, x2; getItemX(itemStart, itemEnd, &x1, &x2); int width = max(1, x2-x1); mapBoxHc(hvg, itemStart, itemEnd, x1, y, width, height, tg->track, mapItemName, buf); return; } int topGraphHeight = barChartHeight(tg, itemInfo); topGraphHeight = max(topGraphHeight, tl.fontHeight); // label int yZero = topGraphHeight + y - 1; // yZero is bottom of graph -int x1 = insideX; + +// add map box to item label + +int labelWidth = mgFontStringWidth(tl.font, itemName); +getItemX(start, end, &x1, &x2); +if (x1-labelWidth <= insideX) + labelWidth = 0; +// map over label +int itemHeight = itemInfo->height; +mapBoxHc(hvg, start, end, x1-labelWidth, y, labelWidth, itemHeight-3, + tg->track, mapItemName, itemName); +// map over background of chart +// TODO: more efficient +int graphWidth = barChartWidth(tg, itemInfo); +mapBoxHc(hvg, start, end, x1, y, graphWidth, itemHeight-3, + tg->track, mapItemName, itemName); // add maps to category bars struct barChartCategory *categs = getCategories(tg); struct barChartCategory *categ = NULL; int barWidth = barChartBarWidth(tg); int padding = barChartPadding(); double maxMedian = ((struct barChartTrack *)tg->extraUiData)->maxMedian; int graphX = barChartX(bed); if (graphX < 0) return; // x1 is at left of graph x1 = insideX + graphX; double viewMax = (double)cartUsualIntClosestToHome(cart, tg->tdb, FALSE, BAR_CHART_MAX_LIMIT, BAR_CHART_MAX_LIMIT_DEFAULT); int i = 0; for (categ = categs; categ != NULL; categ = categ->next, i++) { if (!filterCategory(tg, categ->name)) continue; double expScore = bed->expScores[i]; int height = valToClippedHeight(expScore, maxMedian, viewMax, barChartMaxHeight(), extras->doLogTransform); mapBoxHc(hvg, itemStart, itemEnd, x1, yZero-height, barWidth, height, tg->track, mapItemName, barChartMapText(tg, categ, expScore)); x1 = x1 + barWidth + padding; } -#ifdef ITEM_NAME_MAP -// Maybe later -// add map boxes with item name to item -if (itemInfo->geneModel && itemInfo->description) - { - // perhaps these are just start, end ? - int itemStart = itemInfo->geneModel->txStart; - int itemEnd = barChartItemEnd(tg, item); - int x1, x2; - getItemX(itemStart, itemEnd, &x1, &x2); - int w = x2-x1; - int labelWidth = mgFontStringWidth(tl.font, itemName); - if (x1-labelWidth <= insideX) - labelWidth = 0; - // map over label - int itemHeight = itemInfo->height; - mapBoxHc(hvg, geneStart, geneEnd, x1-labelWidth, y, labelWidth, itemHeight-3, - tg->track, mapItemName, itemInfo->description); - // map over gene model (extending to end of item) - int geneModelHeight = barChartModelHeight(extras); - mapBoxHc(hvg, geneStart, geneEnd, x1, y+itemHeight-geneModelHeight-3, w, geneModelHeight, - tg->track, mapItemName, itemInfo->description); - } -#endif } /* This is lifted nearly wholesale from gtexGene track. Could be shared */ static int getBarChartHeight(void *item) { struct barChartItem *itemInfo = (struct barChartItem *)item; assert(itemInfo->height != 0); return itemInfo->height; } /* This is lifted nearly wholesale from gtexGene track. Could be shared */ static int barChartTotalHeight(struct track *tg, enum trackVisibility vis) /* Figure out total height of track. Set in track and also return it */