6a6d27d0f45a9cb2a4f783f4641f0b2a0ecdca69
kent
Fri Jan 22 04:16:19 2021 -0800
Making right label of how big bar is use same calculations for string width as the left labels, and in process preventing them from getting clipped as often.
diff --git src/hg/hgc/barChartClick.c src/hg/hgc/barChartClick.c
index aa85492..f0b5e10 100644
--- src/hg/hgc/barChartClick.c
+++ src/hg/hgc/barChartClick.c
@@ -363,39 +363,48 @@
// 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(" \n", pngTn.forHtml);
else
warn("Error creating boxplot from sample data with command: %s", cmd->string);
}
+static double estimateStringWidth(char *s)
+/* Get estimate of string width based on a memory font that is about the
+ * same size as svg will be using. After much research I don't think we
+ * can get the size from the server, would have to be in Javascript to get
+ * more precise */
+{
+MgFont *font = mgHelvetica14Font();
+return mgFontStringWidth(font, s);
+}
+
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);
+ int size = estimateStringWidth(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], '_', ' ');
}
@@ -430,31 +439,32 @@
/* 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;
double labelOffset = patchWidth + 2*borderSize;
double statsOffset = labelOffset + labelWidth;
double barOffset = statsOffset + statsSize;
double statsRightOffset = barOffset - 9;
-double barMaxWidth = totalWidth-barOffset - 45; // The 45 is to leave room for ~6 digit number at end.
+double barNumLabelWidth = estimateStringWidth(" 1234.000");
+double barMaxWidth = totalWidth-barOffset -barNumLabelWidth ;
double totalHeight = headerHeight + heightPer * categCount + borderSize;
printf("