ddb85ced5e8b6127a233b5cda5fcb1fbe2260578
max
  Wed Mar 25 04:22:06 2026 -0700
Add detailsScript trackDb mechanism for JS visualizations on bigBed details pages

Changing based on feedback from Jonathan, Chris and Brian after group
discussion. Refactored existing Claude-generated code, moving functions
into libraries.

This is the first use of ES6 modules in the kent js code. In 2026, this
should be acceptable?

New trackDb syntax: detailsScript.<plotType>.<fieldName> <jsonConfig>
The C code (bigBedClick.c) collects these settings, exports field values as JSON
(bedDetails object), and dynamically imports hgc.<plotType>.js as an ES6 module.
Fields used by detailsScript are shown in the HTML table with empty values,
filled by JavaScript.

Includes hgc.histogram.js module for drawing SVG bar chart histograms from
logfmt-encoded data (space-separated key=value pairs). Applied to both the
trexplorer and webstr tracks in the strVar supertrack.

Also adds jsonWriteJsonElement() helper to jsonWrite.c for writing parsed
jsonElement trees into a jsonWrite stream.

max, refs #36652
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

diff --git src/hg/hgc/hgc.h src/hg/hgc/hgc.h
index 9231d4f6d24..89c4449b279 100644
--- src/hg/hgc/hgc.h
+++ src/hg/hgc/hgc.h
@@ -531,30 +531,35 @@
 /* Show details for bigDbSnp item. */
 
 void printAddWbr(char *text, int distance);
 /* a crazy hack for firefox/mozilla that is unable to break long words in tables
  * We need to add a <wbr> tag every x characters in the text to make text breakable.
  */
 
 void printIframe(struct trackDb *tdb, char *itemName);
 /* print an iframe with the URL specified in trackDb (iframeUrl), can have
  * the standard codes in it (like $$ for itemName, etc) */
 
 char *getIdInUrl(struct trackDb *tdb, char *itemName);
 /* If we have an idInUrlSql tag, look up itemName in that, else just
  * return itemName. */
 
+// trackDb setting prefix for JS visualization scripts on details pages.
+// Format: detailsScript.<plotType>.<fieldName> <jsonConfig>
+// Parsed in both bigBedClick.c (to build JSON + load JS) and hgc.c (to skip fields from table).
+#define DETAILS_SCRIPT_PREFIX "detailsScript.*"
+
 void printFieldLabel(char *entry);
 /* print the field label, the first column in the table, as a <td>. Allow a
  * longer description after a |-char, as some fields are not easy to
  * understand. */
 
 void printFieldLabelWithId(char *entry, char *fieldName);
 /* Like printFieldLabel but adds id="bfld_<fieldName>" to the <tr> element,
  * so JavaScript can find the row by field name. */
 
 struct slPair* getExtraFields(struct trackDb *tdb, char **fields, int fieldCount);
 /* return the extra field names and their values as a list of slPairs */
 
 struct slPair *getFields(struct trackDb *tdb, char **fields);
 /* return field names and their values as a list of slPairs.  */