7538532d26dbee720c6ee3426fab17680d242dd1 kent Tue Dec 22 11:02:24 2020 -0800 Estimating width of label based on helvetica font in memory. diff --git src/hg/hgc/barChartClick.c src/hg/hgc/barChartClick.c index ce2bac9..c189a9f 100644 --- src/hg/hgc/barChartClick.c +++ src/hg/hgc/barChartClick.c @@ -1,30 +1,31 @@ /* Details pages for barChart tracks */ /* Copyright (C) 2015 The Regents of the University of California * See README in this or parent directory for licensing information. */ #include "common.h" #include "hash.h" #include "hdb.h" #include "hvGfx.h" #include "trashDir.h" #include "hCommon.h" #include "hui.h" #include "asParse.h" #include "hgc.h" #include "trackHub.h" +#include "memgfx.h" #include "barChartBed.h" #include "barChartCategory.h" #include "barChartData.h" #include "barChartSample.h" #include "barChartUi.h" #define EXTRA_FIELDS_SIZE 256 struct barChartItemData /* Measured value for a sample and the sample category at a locus. * Used for barChart track details (boxplot) */ { struct barChartItemData *next; /* Next in singly linked list. */ char *sample; /* Sample identifier */ @@ -359,48 +360,66 @@ // to help with QAing the change, we add the "oldFonts" CGI parameter so QA can compare // old and new fonts to make sure that things are still readible on mirrors and servers // without the new fonts installed. This only needed during the QA phase bool useOldFonts = cgiBoolean("oldFonts"); /* Exec R in quiet mode, without reading/saving environment or workspace */ dyStringPrintf(cmd, "Rscript --vanilla --slave hgcData/barChartBoxplot.R %s '%s' %s %s %s %s %d", item, units, colorFile, df, pngTn.forHtml, isEmpty(name2) ? "n/a" : name2, useOldFonts); int ret = system(cmd->string); if (ret == 0) printf("<img src = \"%s\" border=1><br>\n", pngTn.forHtml); else warn("Error creating boxplot from sample data with command: %s", cmd->string); } +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.1; +} + + static void printBarChart(struct barChartBed *chart, struct trackDb *tdb, double maxVal) /* 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; } double heightPer=18.0; double innerHeight=heightPer-1; -double widthPer=1300.0; +double widthPer=1250.0; +double labelWidth = longestLabelSize(categs) + 2; +if (labelWidth > widthPer/2) labelWidth = widthPer/2; double labelOffset = 20.0; -double barOffset = 260.0; +double barOffset = labelOffset + labelWidth; double barMaxWidth = widthPer-barOffset - 45; double totalHeight = heightPer * categCount; printf("<svg width=\"%g\" height=\"%g\">\n", widthPer, totalHeight); double yPos = 0.0; int i; struct barChartCategory *categ; printf("<clipPath id=\"labelClip\"><rect x=\"%g\" y=\"0\" width=\"%g\" height=\"%g\"/></clipPath>", labelOffset, barOffset-labelOffset, totalHeight); for (i=0, categ=categs; i<categCount; ++i , categ=categ->next, yPos += heightPer) { double score = chart->expScores[i]; double barWidth = 0; if (maxVal > 0.0)