8b16df428363748e823cc2b5a646b33466524f65 kate Thu Aug 24 13:20:50 2017 -0700 Extending maxHeight UI for barChart. refs #19872 diff --git src/hg/hgTracks/barChartTrack.c src/hg/hgTracks/barChartTrack.c index 925bd27..edc3020 100644 --- src/hg/hgTracks/barChartTrack.c +++ src/hg/hgTracks/barChartTrack.c @@ -10,31 +10,34 @@ #include "spaceSaver.h" #include "hubConnect.h" #include "barChartBed.h" #include "barChartCategory.h" #include "barChartUi.h" // If a category contributes more than this percentage, its color is displayed in squish mode // Could be a trackDb setting #define SPECIFICITY_THRESHOLD 10 struct barChartTrack /* Track info */ { boolean noWhiteout; /* Suppress whiteout of graph background (allow highlight, blue lines) */ double maxMedian; /* Maximum median across all categories */ - int maxHeight; /* Maximum height in pixels for track */ + int limitChartHeight; /* Set maximum height of a chart in the window to maxHeight. Else + maxHeight is maximum height for highest chart in dataset, + based on maxLimit trackDb setting */ + int maxHeight; /* Maximum height in pixels for a chart */ boolean doLogTransform; /* Log10(x+1) */ boolean doAutoScale; /* Scale to maximum in window, alternative to log */ 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 */ @@ -145,38 +148,42 @@ #define MIN_BAR_CHART_MODEL_HEIGHT 1 if (winSize < WIN_MAX_GRAPH) return MAX_BAR_CHART_MODEL_HEIGHT; else if (winSize < WIN_MED_GRAPH) return MED_BAR_CHART_MODEL_HEIGHT; else return MIN_BAR_CHART_MODEL_HEIGHT; } static int barChartMaxHeight(int maxHeight) /* Set maximum graph height based on window size */ { // scale based on subjective aesthetic (previous hardcoded were 175/100) #define WIN_MED_GRAPH_SCALE .57 +#define WIN_SMALL_GRAPH_SCALE .3 long winSize = virtWinBaseCount; +int height; if (winSize < WIN_MAX_GRAPH) - return maxHeight; + height = maxHeight; else if (winSize < WIN_MED_GRAPH) - return maxHeight * WIN_MED_GRAPH_SCALE; + height = maxHeight * WIN_MED_GRAPH_SCALE; else - return tl.fontHeight * 4; + //height = tl.fontHeight * 4; + height = maxHeight * WIN_SMALL_GRAPH_SCALE; +return height; } static int barChartItemHeight(struct track *tg, void *item); static void filterCategories(struct track *tg) /* Check cart for category selection. NULL out unselected categorys in category list */ { struct barChartTrack *extras = (struct barChartTrack *)tg->extraUiData; struct barChartCategory *categ = NULL; extras->categories = getCategories(tg); extras->categoryFilter = hashNew(0); if (cartListVarExistsAnyLevel(cart, tg->tdb, FALSE, BAR_CHART_CATEGORY_SELECT)) { struct slName *selectedValues = cartOptionalSlNameListClosestToHome(cart, tg->tdb, FALSE, BAR_CHART_CATEGORY_SELECT); @@ -281,34 +288,41 @@ /* Get track UI info */ struct barChartTrack *extras; AllocVar(extras); tg->extraUiData = extras; struct trackDb *tdb = tg->tdb; extras->doLogTransform = cartUsualBooleanClosestToHome(cart, tdb, FALSE, BAR_CHART_LOG_TRANSFORM, BAR_CHART_LOG_TRANSFORM_DEFAULT); extras->doAutoScale = cartUsualBooleanClosestToHome(cart, tdb, FALSE, BAR_CHART_AUTOSCALE, BAR_CHART_AUTOSCALE_DEFAULT); extras->maxMedian = barChartUiMaxMedianScore(tdb); extras->noWhiteout = cartUsualBooleanClosestToHome(cart, tdb, FALSE, BAR_CHART_NO_WHITEOUT, BAR_CHART_NO_WHITEOUT_DEFAULT); extras->unit = trackDbSettingClosestToHomeOrDefault(tdb, BAR_CHART_UNIT, ""); - +extras->limitChartHeight = cartUsualBooleanClosestToHome(cart, tdb, FALSE, + BAR_CHART_LIMIT_HEIGHT, + BAR_CHART_LIMIT_HEIGHT_DEFAULT); +int maxHeight = BAR_CHART_MAX_HEIGHT; +if (extras->limitChartHeight) + { int min, max, deflt, current; barChartUiFetchMinMaxPixels(cart, tdb, &min, &max, &deflt, ¤t); -extras->maxHeight = barChartMaxHeight(current); + maxHeight = current; + } +extras->maxHeight = barChartMaxHeight(maxHeight); /* Get bed (names and all-sample category median scores) in range */ loadSimpleBedWithLoader(tg, (bedItemLoader)barChartSimpleBedLoad); /* Create itemInfo items with BED and geneModels */ struct barChartItem *itemInfo = NULL, *infoList = NULL; struct bed *bed = (struct bed *)tg->items; /* Load category colors */ extras->colors = getCategoryColors(tg); filterCategories(tg); /* create list of barChart items */ double maxScoreInWindow = 0; @@ -555,77 +569,65 @@ struct rgbColor fillColor = extras->colors[i]; int fillColorIx = hvGfxFindColorIx(hvg, fillColor.r, fillColor.g, fillColor.b); double expScore = bed->expScores[i]; int height = valToClippedHeight(expScore, maxMedian, viewMax, extras); if (graphPadding == 0 || sameString(colorScheme, BAR_CHART_COLORS_USER)) hvGfxBox(hvg, x1, yZero-height+1, barWidth, height, fillColorIx); else hvGfxOutlinedBox(hvg, x1, yZero-height+1, barWidth, height, fillColorIx, lineColorIx); // mark clipped bar with magenta tip if (barChartUseViewLimit(extras) && expScore > viewMax) hvGfxBox(hvg, x1, yZero-height+1, barWidth, 2, clipColor); x1 = x1 + barWidth + graphPadding; } } -static int barChartItemHeightOptionalMax(struct track *tg, void *item, boolean isMax) +static int barChartItemHeight(struct track *tg, void *item) { // It seems that this can be called early or late enum trackVisibility vis = tg->visibility; if (tg->limitedVisSet) vis = tg->limitedVis; int height; if (vis == tvSquish || vis == tvDense) { if (vis == tvSquish) { tg->lineHeight = barChartSquishItemHeight(); tg->heightPer = tg->lineHeight; } height = tgFixedItemHeight(tg, item); return height; } struct barChartTrack *extras = (struct barChartTrack *)tg->extraUiData; -if (isMax) - { - int extra = 0; - height = extras->maxHeight + barChartMargin() + barChartModelHeight(extras) + extra; - return height; - } if (item == NULL) return 0; struct barChartItem *itemInfo = (struct barChartItem *)item; if (itemInfo->height != 0) { return itemInfo->height; } int topGraphHeight = barChartHeight(tg, itemInfo); topGraphHeight = max(topGraphHeight, tl.fontHeight); int bottomGraphHeight = 0; height = topGraphHeight + bottomGraphHeight + barChartMargin() + barChartModelHeight(extras); return height; } -static int barChartItemHeight(struct track *tg, void *item) -{ - int height = barChartItemHeightOptionalMax(tg, item, FALSE); - return height; -} - static char *barChartMapText(struct track *tg, struct barChartCategory *categ, double expScore) /* Construct mouseover text for a chart bar */ { static char buf[128]; struct barChartTrack *extras = (struct barChartTrack *)tg->extraUiData; safef(buf, sizeof(buf), "%s (%.1f %s)", categ->label, expScore, extras->unit); return buf; } static int barChartItemStart(struct track *tg, void *item) /* Return end chromosome coordinate of item, including graph */ { struct barChartItem *itemInfo = (struct barChartItem *)item; struct bed *bed = (struct bed *)itemInfo->bed; return bed->chromStart;