- struct ctables_cell *cell;
- HMAP_FOR_EACH (cell, struct ctables_cell, node, &t->cells)
- if (!cell->hide)
- sorted[n_sorted++] = cell;
- assert (n_sorted <= t->cells.count);
-
- struct ctables_cell_sort_aux aux = { .t = t, .a = a };
- sort (sorted, n_sorted, sizeof *sorted, ctables_cell_compare_3way, &aux);
-
- size_t max_depth = 0;
- for (size_t j = 0; j < t->stacks[a].n; j++)
- if (t->stacks[a].nests[j].n > max_depth)
- max_depth = t->stacks[a].nests[j].n;
-
- /* Pivot categories:
-
- - variable label for nest->vars[0], if vlabel != CTVL_NONE
- - category for nest->vars[0], if nest->scale_idx != 0
- - variable label for nest->vars[1], if vlabel != CTVL_NONE
- - category for nest->vars[1], if nest->scale_idx != 1
- ...
- - variable label for nest->vars[n - 1], if vlabel != CTVL_NONE
- - category for nest->vars[n - 1], if t->label_axis[a] == a && nest->scale_idx != n - 1.
- - summary function, if 'a == t->slabels_axis && a ==
- t->summary_axis'.
-
- Additional dimensions:
-
- - If 'a == t->slabels_axis && a != t->summary_axis', add a summary
- dimension.
- - If 't->label_axis[b] == a' for some 'b != a', add a category
- dimension to 'a'.
- */
-
- struct ctables_level
- {
- enum ctables_level_type
+ size_t n_total_cells = 0;
+ size_t max_depth = 0;
+ for (size_t j = 0; j < t->n_sections; j++)
+ if (t->sections[j].nests[a] == nest)
+ {
+ struct ctables_section *s = &t->sections[j];
+ sections[n_sections++] = s;
+ n_total_cells += s->cells.count;
+
+ size_t depth = s->nests[a]->n;
+ max_depth = MAX (depth, max_depth);
+ }
+
+ struct ctables_cell **sorted = xnmalloc (n_total_cells,
+ sizeof *sorted);
+ size_t n_sorted = 0;
+
+ for (size_t j = 0; j < n_sections; j++)