86fdc2ac12ccfc5210455d4af0f499ffac0f2dbb kate Wed Aug 23 12:14:03 2017 -0700 Fix graph height bug find by ChrisL, note 14. refs #19872 diff --git src/hg/hgTracks/barChartTrack.c src/hg/hgTracks/barChartTrack.c index 82df923..925bd27 100644 --- src/hg/hgTracks/barChartTrack.c +++ src/hg/hgTracks/barChartTrack.c @@ -27,31 +27,31 @@ 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 */ struct bed *bed; /* Item coords, name, exp count and values */ - int maxScore; /* Maximum expScore in bed */ + double maxScore; /* Maximum expScore in bed */ int height; /* Item height in pixels */ }; /***********************************************/ /* 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; } @@ -277,73 +277,71 @@ /* Initialize colors for visibilities that don't display actual barchart */ if (tg->visibility == tvSquish || tg->limitedVis == tvSquish) tg->itemColor = barChartItemColor; tg->colorShades = shadesOfGray; /* 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, ""); int min, max, deflt, current; barChartUiFetchMinMaxPixels(cart, tdb, &min, &max, &deflt, ¤t); extras->maxHeight = barChartMaxHeight(current); /* 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; while (bed != NULL) { AllocVar(itemInfo); itemInfo->bed = bed; slAddHead(&infoList, itemInfo); bed = bed->next; itemInfo->bed->next = NULL; itemInfo->maxScore = barChartMaxExpScore(tg, itemInfo); - // for autoscale, determine maximum median score in window - if (itemInfo->maxScore > extras->maxMedian) - extras->maxMedian = itemInfo->maxScore; + maxScoreInWindow = max(maxScoreInWindow, itemInfo->maxScore); } +if (extras->doAutoScale) + extras->maxMedian = maxScoreInWindow; +else + extras->maxMedian = max(maxScoreInWindow, extras->maxMedian); + /* determine graph heights */ for (itemInfo = infoList; itemInfo != NULL; itemInfo = itemInfo->next) - { itemInfo->height = barChartItemHeight(tg, itemInfo); - } -double maxScore = barChartUiMaxMedianScore(tdb); -if (!extras->doAutoScale && maxScore > extras->maxMedian) - // maximum median score in entire dataset. - // If not set, using default, but might be too small for this dataset. - extras->maxMedian = maxScore; /* replace item list with wrapped beds */ slReverse(&infoList); tg->items = infoList; } /***********************************************/ /* Draw */ /* Bargraph layouts for three window sizes */ #define WIN_MAX_GRAPH 50000 #define MAX_BAR_WIDTH 5 #define MAX_GRAPH_PADDING 2 #define WIN_MED_GRAPH 500000