fef68995ad2ebf461ac6147fe67cd34de4e0c6a3 jcasper Fri Sep 20 16:29:54 2019 -0700 Changes in response to code review, refs #24153 diff --git src/hg/lib/hicUi.c src/hg/lib/hicUi.c index 3fa6c96..f76a422 100644 --- src/hg/lib/hicUi.c +++ src/hg/lib/hicUi.c @@ -114,33 +114,30 @@ long long value = atoll(meta->resolutions[i-1]); sprintWithMetricBaseUnit(buffer, sizeof(buffer), value); menu[i] = cloneString(buffer); values[i] = cloneString(meta->resolutions[i-1]); } char *selected = hicUiFetchResolution(cart, tdb, meta); cgiMakeDropListWithVals(cartVar, menu, values, meta->nRes+1, selected); free(menu); } char *hicUiFetchDrawMode(struct cart *cart, struct trackDb *tdb) /* Return the current draw mode selection, or the default if none * has been selected. */ { -//char cartVar[1024]; -//safef(cartVar, sizeof(cartVar), "%s.%s", track, HIC_DRAW_MODE); -//char* selected = cartNonemptyString(cart, cartVar); char *selected = cartOptionalStringClosestToHome(cart, tdb, FALSE, HIC_DRAW_MODE); if ( !sameOk(selected, HIC_DRAW_MODE_SQUARE) && !sameOk(selected, HIC_DRAW_MODE_ARC) && !sameOk(selected, HIC_DRAW_MODE_TRIANGLE) ) { selected = HIC_DRAW_MODE_DEFAULT; } return selected; } void hicUiDrawMenu(struct cart *cart, struct trackDb *tdb) /* Draw the list of draw mode options for Hi-C tracks. Square is the * standard square-shaped heatmap with the chromosome position axis on * a diagonal from top left to bottom right. Triangle is the top half @@ -149,97 +146,85 @@ * but skips over self-relations. */ { char cartVar[1024]; printf("<b>Draw mode:</b> "); safef(cartVar, sizeof(cartVar), "%s.%s", tdb->track, HIC_DRAW_MODE); char *menu[] = {HIC_DRAW_MODE_SQUARE, HIC_DRAW_MODE_TRIANGLE, HIC_DRAW_MODE_ARC}; char* selected = hicUiFetchDrawMode(cart, tdb); cgiMakeDropList(cartVar, menu, 3, selected); } char *hicUiFetchDrawColor(struct cart *cart, struct trackDb *tdb) /* Retrieve the HTML hex code for the color to draw the * track values in (e.g., #00ffa1) */ { -//char cartVar[1024]; -//safef(cartVar, sizeof(cartVar), "%s.%s", tdb->track, HIC_DRAW_COLOR); -//char* selected = cartNonemptyString(cart, cartVar); char* selected = cartOptionalStringClosestToHome(cart, tdb, FALSE, HIC_DRAW_COLOR); if (selected == NULL) selected = HIC_DRAW_COLOR_DEFAULT; const char *colorExpr ="^#[0-9a-fA-F]{6}$"; if (!regexMatch(selected, colorExpr)) { selected = HIC_DRAW_COLOR_DEFAULT; } return selected; } char *hicUiFetchBgColor(struct cart *cart, struct trackDb *tdb) /* Retrieve the HTML hex code of the background color for the * track. This is the color associated with scores at or close to 0. */ { -//char cartVar[1024]; -//safef(cartVar, sizeof(cartVar), "%s.%s", track, HIC_DRAW_BG_COLOR); -//char* selected = cartNonemptyString(cart, cartVar); char* selected = cartOptionalStringClosestToHome(cart, tdb, FALSE, HIC_DRAW_BG_COLOR); if (selected == NULL) selected = HIC_DRAW_BG_COLOR_DEFAULT; const char *colorExpr ="^#[0-9a-fA-F]{6}$"; if (!regexMatch(selected, colorExpr)) { selected = HIC_DRAW_BG_COLOR_DEFAULT; } return selected; } double hicUiFetchMaxValue(struct cart *cart, struct trackDb *tdb) /* Retrieve the score value at which the draw color reaches its * its maximum intensity. Any scores above this value will * share that same draw color. */ { -//char cartVar[1024]; -//safef(cartVar, sizeof(cartVar), "%s.%s", track, HIC_DRAW_MAX_VALUE); -//return cartUsualDouble(cart, cartVar, HIC_DRAW_MAX_VALUE_DEFAULT); return cartUsualDoubleClosestToHome(cart, tdb, FALSE, HIC_DRAW_MAX_VALUE, HIC_DRAW_MAX_VALUE_DEFAULT); } void hicUiAddAutoScaleJS(struct cart *cart, char *track) /* Write out a bit of javascript to associate checking/unchecking the autoscale * checkbox with deactivating/activating (respectively) the maximum score * input. */ { struct dyString *new = dyStringNew(0); dyStringPrintf(new, "$('input[name=\"%s.%s\"]')[0].onclick = function() {", track, HIC_DRAW_AUTOSCALE); dyStringPrintf(new, "if (this.checked) {$('input[name=\"%s.%s\"]')[0].disabled = true; $('span#hicMaxText').css('color', 'gray');}", track, HIC_DRAW_MAX_VALUE); dyStringPrintf(new, "else {$('input[name=\"%s.%s\"]')[0].disabled = false; $('span#hicMaxText').css('color', '');} };\n", track, HIC_DRAW_MAX_VALUE); dyStringPrintf(new, "if ($('input[name=\"%s.%s\"]')[0].checked) {$('input[name=\"%s.%s\"]')[0].disabled = true; $('span#hicMaxText').css('color', 'gray');}\n", track, HIC_DRAW_AUTOSCALE, track, HIC_DRAW_MAX_VALUE); jsInline(dyStringContents(new)); dyStringFree(&new); } boolean hicUiFetchAutoScale(struct cart *cart, struct trackDb *tdb) /* Returns whether the track is configured to automatically scale its color range * depending on the scores present in the window, or if it should stick to a * gradient based on the user's selected maximum value. */ { -//char cartVar[1024]; -//safef(cartVar, sizeof(cartVar), "%s.%s", track, HIC_DRAW_AUTOSCALE); -//return cartUsualBoolean(cart, cartVar, TRUE); return cartUsualBooleanClosestToHome(cart, tdb, FALSE, HIC_DRAW_AUTOSCALE, TRUE); } void hicUiColorMenu(struct cart *cart, struct trackDb *tdb) /* Draw the menu inputs associated with selecting draw colors for the track. */ { char cartVar[1024]; printf("<b>Color:</b> "); safef(cartVar, sizeof(cartVar), "%s.%s", tdb->track, HIC_DRAW_COLOR); char* selected = hicUiFetchDrawColor(cart, tdb); printf("<input type='color' name='%s' value='%s' />\n", cartVar, selected); // Leaving out background color options for now. We'll see if this option is requested. /* @@ -265,50 +250,34 @@ safef(cartVar, sizeof(cartVar), "%s.%s", tdb->track, HIC_DRAW_AUTOSCALE); boolean autoscaleChecked = hicUiFetchAutoScale(cart, tdb); cgiMakeCheckBox(cartVar, autoscaleChecked); hicUiAddAutoScaleJS(cart, tdb->track); } void hicUiFileDetails(struct hicMeta *trackMeta) { int i;//, first = 1; printf("</p><hr>\nMetadata from file header:<br>\n"); printf("<div style='margin-left: 2em'>\n"); printf("<label class='trackUiHicLabel'>Genome: %s\n<br></label>", trackMeta->fileAssembly); -/* -printf("<label class='trackUiHicLabel trackUiHicAttrToggle'>Attribute dictionary: <img height=10 src='../images/ab_down.gif'></label>"); -printf("<div class='trackUiHicHiddenAttributes'>\n"); -for (i=0; i<trackMeta->nAttributes-1; i+=2) - { - char *encodedKey = htmlEncode(trackMeta->attributes[i]); - char *encodedValue = htmlEncode(trackMeta->attributes[i+1]); - printf("%s%s = <pre>%s</pre>\n", first?"":"<br>", encodedKey, encodedValue); - first = 0; - } -printf("</div>\n"); -jsInline("$('label.trackUiHicAttrToggle').click(function() {$('div.trackUiHicHiddenAttributes').toggle();});"); -*/ char scriptline[2048]; for (i=0; i<trackMeta->nAttributes-1; i+=2) { -// printf("<label class='trackUiHicLabelExpand trackUiHicAttrToggle%d'>%s</label><br>",// <img height=10 src='../images/ab_right.gif'></label>", -// i, htmlEncode(trackMeta->attributes[i])); - printf("<label class='trackUiHicLabelExpand trackUiHicAttrToggle%d'>%s <img src='%s' class='trackUiHicLabelArrow'></label><br>",// <img height=10 src='../images/ab_right.gif'></label>", - i, htmlEncode(trackMeta->attributes[i]), "../images/ab_right.gif"); + printf("<label class='trackUiHicLabelExpand trackUiHicAttrToggle%d'>%s <img src='%s' class='trackUiHicLabelArrow'></label><br>", i, htmlEncode(trackMeta->attributes[i]), "../images/ab_right.gif"); printf("<div class='trackUiHicHiddenAttributes hicAttr%d'>\n", i); printf("<pre>%s</pre>", htmlEncode(trackMeta->attributes[i+1])); printf("</div>\n"); safef(scriptline, sizeof(scriptline), "$('label.trackUiHicAttrToggle%d').click(function() {$(this).children('img').toggleClass('open'); $('div.hicAttr%d').toggle();});", i, i); jsInline(scriptline); } printf("</div>\n"); printf("<p>For questions concerning the content of a file's metadata header, please contact the file creator.</p>\n"); } void hicCfgUi(char *database, struct cart *cart, struct trackDb *tdb, char *track, char *title, boolean boxed) /* Draw the list of track configuration options for Hi-C tracks */ {