51d3b8b7b18d2dfc1093a30ef925c97ce8f6b129 kent Tue Apr 20 15:52:05 2021 -0700 Commenting the extras structure a little and adding stretchToItem set from trackDb barChartStretchToItem to it. This puts the stretching control under this option, which is off by default for backwards compatibility. diff --git src/hg/hgTracks/barChartTrack.c src/hg/hgTracks/barChartTrack.c index aba8a21..9d4dd48 100644 --- src/hg/hgTracks/barChartTrack.c +++ src/hg/hgTracks/barChartTrack.c @@ -32,35 +32,38 @@ struct rgbColor *colors; /* Colors for all categories */ struct hash *categoryFilter; /* NULL out excluded factors */ int maxViewLimit; // dimensions for drawing char *maxGraphSize; /* optionally limit graph size (override semantic zoom) small, medium, or large (default) */ int winMaxGraph; /* Draw large graphs if window size smaller than this */ int winMedGraph; /* Draw medium graphs if window size greater than this and smaller than winMaxGraph */ int winSmallGraph; /* Draw small graphs if windowSize between this and * win medGraph, draw tiny if smaller */ int squishHeight; /* Height of item in squish mode (larger than typical) */ int boxModelHeight; /* Height of indicator box drawn under graph to show gene extent */ - int modelHeight; /* Height of box drawn under graph with padding */ + int modelHeight; /* Height of box drawn under graph with margin */ + int margin; /* Added to pixel height to help separate things */ + + // Individual bar dimensions double barWidth; /* Width of individual bar in pixels */ - int margin; - int padding; - int maxHeight; + int padding; /* Pixel width between bars */ + int maxHeight; /* Maximum bar height. */ + boolean stretchToItem; /* If item is wider than chart, stretch to fit? */ }; 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 */ }; /***********************************************/ /* Organize category info */ struct barChartCategory *getCategories(struct track *tg) /* Get and cache category extras */ @@ -373,33 +376,37 @@ totalIntersect += single; } } if (totalIntersect == 0) return 0; else { return totalPixelSize * (double)totalIntersect / totalGenoSize; } } static int chartWidth(struct track *tg, struct barChartItem *itemInfo) /* How wide is the chart? */ { struct bed *bed = itemInfo->bed; -int geneSize = windowsTotalIntersection(windows, bed->chrom, bed->chromStart, bed->chromEnd); +int itemSize = windowsTotalIntersection(windows, bed->chrom, bed->chromStart, bed->chromEnd); int standardSize = chartStandardWidth(tg, itemInfo); -return max(standardSize, geneSize); +struct barChartTrack *extras = tg->extraUiData; +if (extras->stretchToItem) + return max(standardSize, itemSize); +else + return standardSize; } static void barChartLoadItems(struct track *tg) /* Load method for track items */ { /* 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; if (!tg->extraUiData) { AllocVar(extras); @@ -528,30 +535,31 @@ if (extras->barWidth <= 1 && extras->padding == 1) { extras->barWidth = 2; extras->padding = 0; } if (extras->barWidth < 1) extras->padding = 0; else extras->barWidth = round(extras->barWidth); // uglyAbort("barCount %d, graphSize %s, extras->barWidth = %g, extras->padding = %d, scale = %g", barCount, extras->maxGraphSize, extras->barWidth, extras->padding, scale); extras->modelHeight = extras->boxModelHeight + 3; extras->margin = 1; extras->squishHeight = tl.fontHeight - tl.fontHeight/2; +extras->stretchToItem = trackDbSettingOn(tg->tdb, "barChartStretchToItem"); while (bed != NULL) { AllocVar(itemInfo); itemInfo->bed = bed; slAddHead(&list, itemInfo); bed = bed->next; itemInfo->bed->next = NULL; itemInfo->height = barChartItemHeight(tg, itemInfo); } slReverse(&list); tg->items = list; } /***********************************************/