pivot-table: Add support for hiding footnotes.
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 29 Dec 2019 05:46:31 +0000 (05:46 +0000)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 29 Dec 2019 05:53:23 +0000 (05:53 +0000)
This will get its first real user in an upcoming commit.

src/output/pivot-output.c
src/output/pivot-table.c
src/output/pivot-table.h

index 1394af4d09a539572e9a827ed5e2213acd1e1abd..e068a50fc14dfb87999f6ad098f883202582606c 100644 (file)
@@ -121,9 +121,13 @@ fill_cell (struct table *t, int x1, int y1, int x2, int y2,
                          area_style_override (t->container, style,
                                               value->cell_style,
                                               value->font_style));
-      
+
       for (size_t i = 0; i < value->n_footnotes; i++)
-        table_add_footnote (t, x1, y1, footnotes[value->footnotes[i]->idx]);
+        {
+          struct footnote *f = footnotes[value->footnotes[i]->idx];
+          if (f)
+            table_add_footnote (t, x1, y1, f);
+        }
 
       if (value->n_subscripts)
         table_add_subscripts (t, x1, y1,
@@ -148,13 +152,16 @@ pivot_value_to_table_item_text (const struct pivot_value *value,
   *text = (struct table_item_text) {
     .content = ds_steal_cstr (&s),
     .footnotes = xnmalloc (value->n_footnotes, sizeof *text->footnotes),
-    .n_footnotes = value->n_footnotes,
     .style = area_style_override (
       NULL, area, value->cell_style, value->font_style),
   };
 
   for (size_t i = 0; i < value->n_footnotes; i++)
-    text->footnotes[i] = footnotes[value->footnotes[i]->idx];
+    {
+      struct footnote *f = footnotes[value->footnotes[i]->idx];
+      if (f)
+        text->footnotes[text->n_footnotes++] = f;
+    }
 
   return text;
 }
@@ -335,15 +342,20 @@ pivot_table_submit_layer (const struct pivot_table *pt,
   struct footnote **footnotes = xcalloc (pt->n_footnotes, sizeof *footnotes);
   for (size_t i = 0; i < pt->n_footnotes; i++)
     {
-      char *content = pivot_value_to_string (
-        pt->footnotes[i]->content, pt->show_values, pt->show_variables);
-      char *marker = pivot_value_to_string (
-        pt->footnotes[i]->marker, pt->show_values, pt->show_variables);
+      const struct pivot_footnote *pf = pt->footnotes[i];
+
+      if (!pf->show)
+        continue;
+
+      char *content = pivot_value_to_string (pf->content, pt->show_values,
+                                             pt->show_variables);
+      char *marker = pivot_value_to_string (pf->marker, pt->show_values,
+                                            pt->show_variables);
       footnotes[i] = table_create_footnote (
         table, i, content, marker,
         area_style_override (table->container, &pt->areas[PIVOT_AREA_FOOTER],
-                             pt->footnotes[i]->content->cell_style,
-                             pt->footnotes[i]->content->font_style));
+                             pf->content->cell_style,
+                             pf->content->font_style));
       free (marker);
       free (content);
     }
@@ -470,11 +482,15 @@ pivot_table_submit_layer (const struct pivot_table *pt,
           pivot_value_format_body (name, pt->show_values, pt->show_variables,
                                    &s);
           layer->content = ds_steal_cstr (&s);
-          layer->n_footnotes = name->n_footnotes;
-          layer->footnotes = xnmalloc (layer->n_footnotes,
+          layer->n_footnotes = 0;
+          layer->footnotes = xnmalloc (name->n_footnotes,
                                        sizeof *layer->footnotes);
           for (size_t i = 0; i < name->n_footnotes; i++)
-            layer->footnotes[i] = footnotes[name->footnotes[i]->idx];
+            {
+              struct footnote *f = footnotes[name->footnotes[i]->idx];
+              if (f)
+                layer->footnotes[layer->n_footnotes++] = f;
+            }
         }
     }
   if (layers)
index cc7ca59d0fc06487ce00b8c4dc216c13c4ead496..3878b888e51842df6ee63d1ef7d239d640c3a51e 100644 (file)
@@ -1059,6 +1059,7 @@ pivot_table_create_footnote__ (struct pivot_table *table, size_t idx,
           f->marker = pivot_make_default_footnote_marker (
             f->idx, table->show_numeric_markers);
           f->content = NULL;
+          f->show = true;
 
           table->footnotes[table->n_footnotes++] = f;
         }
index e36565bd48815b88678ab327c64ccf95fd464162..ae8a68e844300e1b2a1d037c3c242ba34560f022 100644 (file)
@@ -502,6 +502,7 @@ struct pivot_footnote
     size_t idx;
     struct pivot_value *content;
     struct pivot_value *marker;
+    bool show;
   };
 
 struct pivot_footnote *pivot_table_create_footnote (