22ee4e58588dbf633ee93b9c661e08349ff8e908 kent Mon Jan 18 20:28:29 2021 -0800 Fixing it so underbar and space should be equivalent in the bar chart labels in the stats file. diff --git src/hg/hgc/barChartClick.c src/hg/hgc/barChartClick.c index 230f54e..aa85492 100644 --- src/hg/hgc/barChartClick.c +++ src/hg/hgc/barChartClick.c @@ -378,53 +378,63 @@ static double longestLabelSize(struct barChartCategory *categList) /* Get estimate of longest label in pixels */ { MgFont *font = mgHelvetica14Font(); int longest = 0; struct barChartCategory *categ; for (categ = categList; categ != NULL; categ = categ->next) { int size = mgFontStringWidth(font, categ->label); if (size > longest) longest = size; } return longest * 1.09; } +void deunderbarColumn(struct fieldedTable *ft, char *field) +/* Ununderbar all of a column inside table because space/underbar gets + * so confusing */ +{ +int fieldIx = fieldedTableFindFieldIx(ft, field); +struct fieldedRow *row; +for (row = ft->rowList; row != NULL; row = row->next) + replaceChar(row->row[fieldIx], '_', ' '); +} static void printBarChart(struct barChartBed *chart, struct trackDb *tdb, double maxVal, char *metric) /* Plot bar chart without quartiles or anything fancy just using SVG */ { /* Load up input labels, color, and data */ struct barChartCategory *categs = barChartUiGetCategories(database, tdb); int categCount = slCount(categs); if (categCount != chart->expCount) { warn("Problem in %s barchart track. There are %d categories in trackDb and %d in data", tdb->track, categCount, chart->expCount); return; } char *statsFile = trackDbSetting(tdb, "barChartStatsUrl"); struct hash *statsHash = NULL; int countStatIx = 0; double statsSize = 0.0; if (statsFile != NULL) { char *required[] = {"cluster", "count", "total"}; struct fieldedTable *ft = fieldedTableFromTabFile( statsFile, statsFile, required, ArraySize(required)); + deunderbarColumn(ft, "cluster"); statsHash = fieldedTableIndex(ft, "cluster"); countStatIx = fieldedTableFindFieldIx(ft, "count"); statsSize = 8*(fieldedTableMaxColChars(ft, countStatIx)+1); } /* Some constants that control layout */ double heightPer=18.0; double totalWidth=1250.0; double borderSize = 1.0; double headerHeight = heightPer + 2*borderSize; double innerHeight=heightPer-borderSize; double labelWidth = longestLabelSize(categs) + 9; // Add some because size is just estimate if (labelWidth > totalWidth/2) labelWidth = totalWidth/2; // Don't let labels take up more than half double patchWidth = heightPer; @@ -461,43 +471,41 @@ if (maxVal > 0.0) barWidth = barMaxWidth * score/maxVal; char *deunder = cloneString(categ->label); replaceChar(deunder, '_', ' '); printf("\n", yPos, innerHeight, categ->color); printf("\n", barOffset, yPos, barWidth, innerHeight, categ->color); if (i&1) // every other time printf("\n", labelOffset, yPos, labelWidth+statsSize, innerHeight, 0xFFFFFF); printf("%s\n", labelOffset, yPos+innerHeight-1, innerHeight-1, deunder); if (statsSize > 0.0) { - struct fieldedRow *fr = hashFindVal(statsHash, categ->label); - if (fr == NULL) - fr = hashFindVal(statsHash, deunder); + struct fieldedRow *fr = hashFindVal(statsHash, deunder); if (fr != NULL) { printf("%s\n", statsRightOffset, yPos+innerHeight-1, innerHeight-1, fr->row[countStatIx]); } } printf("%5.3f\n", barOffset+barWidth+2, yPos+innerHeight-1, innerHeight-1, score); } -printf(""); +printf(""); } struct asColumn *asFindColByIx(struct asObject *as, int ix) /* Find AS column by index */ { struct asColumn *asCol; int i; for (i=0, asCol = as->columnList; asCol != NULL && inext, i++); return asCol; } void doBarChartDetails(struct trackDb *tdb, char *item) /* Details of barChart item */ {