70694f5a2017b74955371ca3ff5e9883cc874083 kent Mon Dec 6 09:23:30 2021 -0800 Increasing max displayed width of label for a big sloppy data set. diff --git src/hg/hgc/facetedBar.c src/hg/hgc/facetedBar.c index 86e2dc6..bb62cc4 100644 --- src/hg/hgc/facetedBar.c +++ src/hg/hgc/facetedBar.c @@ -1,137 +1,137 @@ #include "common.h" #include "hash.h" #include "hdb.h" #include "web.h" #include "hvGfx.h" #include "trashDir.h" #include "hCommon.h" #include "hui.h" #include "asParse.h" #include "hgc.h" #include "trackHub.h" #include "hgColors.h" #include "fieldedTable.h" #include "tablesTables.h" #include "facetField.h" #include "barChartBed.h" #include "hgConfig.h" #include "facetedTable.h" #include "facetedBar.h" struct wrapContext /* Context used by various wrappers. */ { int colorIx; /* Index of color in row */ int valIx; /* Where value lives */ double maxVal;/* Maximum of any total value */ }; void wrapVal(struct fieldedTable *table, struct fieldedRow *row, char *field, char *val, char *shortVal, void *context) /* Write out wrapper draws a SVG bar*/ { struct wrapContext *wc = context; char *color = "#000000"; int colorIx = wc->colorIx; if (colorIx >= 0) color = row->row[colorIx]; double x = sqlDouble(val); int width = 500, height = 13; // These are units of ~2010 pixels or something double barWidth = (double)width*x/wc->maxVal; printf("", barWidth, height); printf("", barWidth, height, color); printf(""); printf(" %6.2f", x); } struct fieldedTable *addChartVals(struct fieldedTable *table, struct barChartBed *chart) /* All a new column with chart values */ { if (chart->expCount != table->rowCount) errAbort("Mismatch in field counts between %s (%d) and barChartBed (%d)", table->name, table->rowCount, chart->expCount); int oldFieldCount = table->fieldCount; int newFieldCount = oldFieldCount+1; char *newRow[newFieldCount]; int i; for (i=0; ifields[i]; newRow[oldFieldCount] = "val"; struct fieldedTable *newTable = fieldedTableNew(table->name, newRow, newFieldCount); struct fieldedRow *fr; int rowIx = 0; for (fr = table->rowList; fr != NULL; fr = fr->next, ++rowIx) { for (i=0; irow[i]; char buf[16]; safef(buf, sizeof(buf), "%g", chart->expScores[rowIx]); newRow[oldFieldCount] = lmCloneString(newTable->lm, buf); fieldedTableAdd(newTable, newRow, newFieldCount, fr->id); } return newTable; } void facetedBarChart(char *item, struct barChartBed *chart, struct trackDb *tdb, double maxVal, char *statsFile, char *facets, char *metric) { char *trackName = tdb->track; struct sqlConnection *conn = sqlConnect(database); struct hash *wrapperHash = hashNew(0); /* Write html to make white background */ hInsideStyleToWhite(); /* Set up url that has enough context to get back to us. */ struct dyString *returnUrl = dyStringNew(0); dyStringPrintf(returnUrl, "../cgi-bin/hgc?g=%s", trackName); if (item != NULL) dyStringPrintf(returnUrl, "&i=%s", item); dyStringPrintf(returnUrl, "&%s", cartSidUrlString(cart)); /* Working within a form we save context. It'd be nice to work outside of form someday. */ printf("
\n"); printf("
"); cartSaveSession(cart); cgiContinueHiddenVar("g"); cgiContinueHiddenVar("i"); /* Load up table from tsv file */ char *requiredStatsFields[] = {"count",}; struct fieldedTable *statsTable = fieldedTableFromTabFile(statsFile, statsFile, requiredStatsFields, ArraySize(requiredStatsFields)); struct fieldedTable *table = addChartVals(statsTable, chart); /* Update facet selections from users input if any and get selected part of table */ struct facetedTable *facTab = facetedTableFromTable(table, trackName, facets); facetedTableUpdateOnClick(facTab, cart); struct fieldedTable *selected = facetedTableSelect(facTab, cart); /* Set up context for functions that wrap output fields */ struct wrapContext context = { .valIx = fieldedTableFindFieldIx(table, "val"), .colorIx = fieldedTableFindFieldIx(table, "color"), }; context.maxVal = fieldedTableMaxInCol(table, context.valIx); /* Add wrapper function(s) */ hashAdd(wrapperHash, "val", wrapVal); /* Pick which fields to display. We'll take the first field whatever it is * named, and also count, and the "val" field we added and wrapped. */ char displayList[256]; safef(displayList, sizeof(displayList), "%s,count,val", table->fields[0]); facetedTableWriteHtml(facTab, cart, selected, displayList, - returnUrl->string, 40, wrapperHash, &context, 5); + returnUrl->string, 45, wrapperHash, &context, 5); /* Clean up and go home. */ printf("
\n"); facetedTableFree(&facTab); sqlDisconnect(&conn); }