labeling, with clabels and slabels, all seems to work right
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 16 Jan 2022 03:48:11 +0000 (19:48 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 2 Apr 2022 01:48:55 +0000 (18:48 -0700)
src/language/stats/ctables.c

index 51a4a102a644ebe33005d3fd4697f00cebfbc582..8dcd682f10d2d667682928e0126ee8687382c525 100644 (file)
@@ -2831,32 +2831,10 @@ ctables_table_output_different_axis (struct ctables *ct, struct ctables_table *t
       for (size_t j = 0; j < n_sorted; j++)
         {
           struct ctables_cell *cell = sorted[j];
+          struct ctables_cell *prev = j > 0 ? sorted[j - 1] : NULL;
           const struct ctables_nest *nest = &t->stacks[a].nests[cell->axes[a].stack_idx];
 
-          size_t n_common = 0;
-          bool new_subtable = false;
-          if (j > 0)
-            {
-              struct ctables_cell *prev = sorted[j - 1];
-              if (prev->axes[a].stack_idx == cell->axes[a].stack_idx)
-                {
-                  for (; n_common < nest->n; n_common++)
-                    if (n_common != nest->scale_idx
-                        && (prev->axes[a].cvs[n_common].category
-                            != cell->axes[a].cvs[n_common].category
-                            || !value_equal (&prev->axes[a].cvs[n_common].value,
-                                             &cell->axes[a].cvs[n_common].value,
-                                             var_get_type (nest->vars[n_common]))))
-                      break;
-                  if (a == PIVOT_AXIS_ROW)
-                    printf ("n_common=%zu\n", n_common);
-                }
-              else
-                new_subtable = true;
-            }
-          else
-            new_subtable = true;
-
+          bool new_subtable = !prev || prev->axes[a].stack_idx != cell->axes[a].stack_idx;
           if (new_subtable)
             {
               n_levels = 0;
@@ -2894,20 +2872,29 @@ ctables_table_output_different_axis (struct ctables *ct, struct ctables_table *t
                 }
               printf ("\n");
             }
-          if (a == PIVOT_AXIS_ROW)
-            printf ("n_common=%zu\n", n_common);
-          if (n_common == nest->n)
+
+          size_t n_common = 0;
+          if (!new_subtable)
             {
-              cell->axes[a].leaf = prev_leaf;
-              continue;
+              for (; n_common < nest->n; n_common++)
+                {
+                  const struct ctables_level *level = &levels[n_common];
+                  if (level->type == CTL_CATEGORY)
+                    {
+                      size_t var_idx = level->var_idx;
+                      if (prev->axes[a].cvs[var_idx].category
+                          != cell->axes[a].cvs[var_idx].category
+                          || !value_equal (&prev->axes[a].cvs[var_idx].value,
+                                           &cell->axes[a].cvs[var_idx].value,
+                                           var_get_type (nest->vars[var_idx])))
+                        break;
+                    }
+                }
             }
 
-          for (size_t k = 0; k < n_levels; k++)
+          for (size_t k = n_common; k < n_levels; k++)
             {
               const struct ctables_level *level = &levels[k];
-              if (n_common > level->var_idx)
-                continue;
-
               struct pivot_category *parent = k ? groups[k - 1] : d[a]->root;
               if (level->type == CTL_SUMMARY)
                 {