444b1eb7e7ec2938a4a9a6d3ed214179073ab6f7
max
  Wed Sep 9 05:41:23 2026 -0700
Faceted composite: manual row reordering, group-by, saved UI state, and per-facet "only" links

The Fiber-seq compendium put 41 samples times six data types into one
faceted composite, which pushed on the parts of the page that were built
for a flat list of tracks.  Changes here, all in the shared faceted
composite code rather than anything Fiber-seq specific:

Row order.  Track order in the image follows the table, so the table now
lets you set that order by hand.  Vendored DataTables RowReorder 1.5.1
adds a drag handle as the first column after the checkbox, enabled on
the "shown in the browser" tab where reordering means something.  The
dragged order is remembered by sample name rather than by row number, so
it survives a metadata file whose contents have changed.

Group by.  A container of six data types can be read two ways, so the
page offers both: group the image by sample, keeping a sample's six
tracks together, or by data type, putting all the accessibility tracks
next to each other.  cartDump assigns the priorities and just swaps the
nesting of its two loops.  trackDb sets the starting choice with
defaultGroupBy.

Saved state.  Facets, per-column searches, sort column, page length,
which tab was open and the hand-dragged order go to localStorage keyed
by metadata id, so coming back to the page does not mean setting it all
up again.

Facet "only" links.  A small "only" appears on hover behind each facet
value and narrows to just that one, instead of unticking the others by
hand.

Column descriptions.  A metadata column heading can now carry a longer
explanation after a "|", shown behind an info icon on both the column
header and the facet heading.

Also: parseDataTypes() was returning its list reversed, since slPairAdd
prepends and nothing put it back, so the data type checkboxes and the
resulting subtrack order were backwards; the composite lifts itself out
of hide when the user touches anything on the page, which is what they
meant by touching it; the facet sidebar collapses when a table has no
facetable columns; and the label wording throughout says "samples" and
"in the browser" rather than "tracks" and "active".

The Methbase hg38 track gets labels for its three data types, which were
showing as the bare pipeline names hmr, levels and reads.

refs #36210

diff --git src/hg/cartDump/cartDump.c src/hg/cartDump/cartDump.c
index af5b1e9ddc3..cbc7de35776 100644
--- src/hg/cartDump/cartDump.c
+++ src/hg/cartDump/cartDump.c
@@ -63,30 +63,44 @@
 
 char subtrackSetting[1024];
 char prioritySetting[1024];
 
 // Remember how the faceted table was sorted, so that the next visit to the track
 // UI page comes back in the same order.  The value is a list of metadata field
 // names with directions ("field=+ field2=-"), mirroring the classic composite
 // "<track>.sortOrder" cart variable.  It's opaque here - only the javascript can
 // turn field names into an ordering, since only it reads the metadata file.
 char *facetSortOrder = cgiOptionalString(mdid_sort);
 if (isNotEmpty(facetSortOrder))
     cartSetString(cart, mdid_sort, facetSortOrder);
 else
     cartRemove(cart, mdid_sort);
 
+// Which of the two dimensions is kept together in the image: "sample" puts a
+// sample's data types side by side, "dataType" puts the same data type for
+// every sample side by side.  Remembered so the next visit to the track UI page
+// comes back with the same button selected.  Only two values are accepted, so a
+// junk value falls back to grouping by sample rather than being stored.
+char mdid_groupBy[1024];
+safef(mdid_groupBy, sizeof(mdid_groupBy), "%s.groupBy", mdid);
+char *groupBy = cgiOptionalString(mdid_groupBy);
+boolean groupByDataType = (isNotEmpty(groupBy) && sameString(groupBy, "dataType"));
+if (isNotEmpty(groupBy) && (groupByDataType || sameString(groupBy, "sample")))
+    cartSetString(cart, mdid_groupBy, groupBy);
+else
+    cartRemove(cart, mdid_groupBy);
+
 // Any ".priority" values left over from an earlier submission are stale, since the
 // loops below assign a fresh, dense 1..N to exactly the subtracks that are on now.
 // Clearing them first means the subtracks the user just turned off don't keep a
 // priority that would place them oddly if they're ever turned on again elsewhere.
 // Note that "<mdid>_*" can't match the composite's own "<mdid>.priority" - the
 // subtrack names are joined with an underscore rather than a dot.
 char priorityWild[1024];
 safef(priorityWild, sizeof(priorityWild), "%s_*.priority", mdid);
 cartRemoveLike(cart, priorityWild);
 
 // A subtrack the user has dragged up or down in the hgTracks image carries an
 // "_imgOrd" value, and flatTracksCmp() in hgTracks/imageV2.c sorts on that before
 // it ever looks at priority - so without this the dragged position would win and
 // the sort established here would appear to be ignored.  cartJustify() in cart.c
 // normally clears these whenever a ".priority" arrives as a CGI variable, but ours
@@ -124,36 +138,51 @@
         {
         boolean de_is_off = (hashLookup(de_now_hash, de->name) == NULL);
         for (struct slName *dt = dt_was_list; dt != NULL; dt = dt->next)
             {
             boolean dt_is_off = (hashLookup(dt_now_hash, dt->name) == NULL);
             if (de_is_off || dt_is_off)
                 {
                 safef(subtrackSetting, sizeof(subtrackSetting),
                       "%s_%s_%s_sel", mdid, de->name, dt->name);
                 cartSetString(cart, subtrackSetting, "0");
                 }
             }
         }
 
     // Set each shown subtrack's priority to match the order the data elements
-    // are currently sorted in the faceted table (de_now arrives in that order).
-    // Data elements are the outer loop so a sample's data-type subtracks stay
-    // contiguous, in the sample's sorted position.
+    // are currently sorted in the faceted table (de_now arrives in that order,
+    // and dt_now in the order the data types are declared in trackDb).
+    // Whichever list is the outer loop is the dimension that stays contiguous
+    // in the image: by default that is the data element, so a sample's data
+    // types sit together in the sample's sorted position.  Grouping by data
+    // type swaps the nesting, putting the same data type for every sample
+    // together instead.
     int priority = 0;
+    if (groupByDataType)
+        {
+        for (struct slName *dt = dt_now_list; dt != NULL; dt = dt->next)
             for (struct slName *de = de_now_list; de != NULL; de = de->next)
                 {
+                safef(prioritySetting, sizeof(prioritySetting),
+                      "%s_%s_%s.priority", mdid, de->name, dt->name);
+                cartSetInt(cart, prioritySetting, ++priority);
+                }
+        }
+    else
+        {
+        for (struct slName *de = de_now_list; de != NULL; de = de->next)
             for (struct slName *dt = dt_now_list; dt != NULL; dt = dt->next)
                 {
                 safef(prioritySetting, sizeof(prioritySetting),
                       "%s_%s_%s.priority", mdid, de->name, dt->name);
                 cartSetInt(cart, prioritySetting, ++priority);
                 }
         }
 
     }
 else
     {
     // Data elements only mode: tracks are identified by mdid_de
 
     // Turn ON: de_now - de_was
     for (struct slName *de = de_now_list; de != NULL; de = de->next)