axes marked properly
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 2 Jan 2022 00:47:29 +0000 (16:47 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 13 Mar 2022 23:56:02 +0000 (16:56 -0700)
src/language/stats/ctables.c

index 22ca909d9897d933b246a75e4bcb920c53479a11..9f8223cbb6936a1afe3da25c8c265d965acc756e 100644 (file)
@@ -2034,12 +2034,14 @@ ctables_execute (struct dataset *ds, struct ctables *ct)
             [PIVOT_AXIS_COLUMN] = N_("Columns"),
             [PIVOT_AXIS_LAYER] = N_("Layers"),
           };
-          d[a] = (t->axes[a]
+          d[a] = (t->axes[a] || a == t->summary_axis
                   ? pivot_dimension_create (pt, a, names[a])
                   : NULL);
           if (!d[a])
             continue;
 
+          assert (t->axes[a]);
+
           struct ctables_freq **sorted = xnmalloc (t->ft.count, sizeof *sorted);
 
           struct ctables_freq *f;
@@ -2090,32 +2092,28 @@ ctables_execute (struct dataset *ds, struct ctables *ct)
                 {
                   struct pivot_category *parent = k > 0 ? groups[k - 1] : top;
 
+                  struct pivot_value *label = pivot_value_new_var_value (
+                    va->vars[k], &f->axes[a].values[k]);
+
                   if (k == va->n - 1)
                     {
-                      pivot_category_create_leaf (
-                        parent,
-                        pivot_value_new_var_value (va->vars[va->n - 1],
-                                                   &f->axes[a].values[va->n - 1]));
+                      if (a == t->summary_axis)
+                        {
+                          parent = pivot_category_create_group__ (parent, label);
+                          for (size_t m = 0; m < va->n_summaries; m++)
+                            pivot_category_create_leaf (
+                              parent, pivot_value_new_text (va->summaries[m].label));
+                        }
+                      else
+                        pivot_category_create_leaf (parent, label);
                       break;
                     }
 
-                  parent = pivot_category_create_group__ (
-                    parent,
-                    pivot_value_new_var_value (va->vars[k], &f->axes[a].values[k]));
+                  parent = pivot_category_create_group__ (parent, label);
 
                   parent = pivot_category_create_group__ (
                     parent, pivot_value_new_variable (va->vars[k]));
                   groups[k] = parent;
-
-#if 0
-                      for (size_t p = 0; p < ft->n_summaries; p++)
-                        {
-                          if (a == t->slabels_position)
-                            pivot_category_create_leaf (
-                              c, pivot_value_new_text (ft->summaries[p].label));
-                          //pivot_table_put1 (pt, leaf, pivot_value_new_number (value));
-                        }
-#endif
                     }
                 }
           free (groups);