- /* One column for the name,
- two columns for general description,
- one column for dictionary index. */
- nc = 1;
- if (flags & ~DF_DICT_INDEX)
- nc += 2;
- pc = nc;
- if (flags & DF_DICT_INDEX)
- nc++;
-
- t = tab_create (nc, n + 5);
- tab_headers (t, 0, 0, 1, 0);
- tab_hline (t, TAL_2, 0, nc - 1, 1);
- tab_text (t, 0, 0, TAB_LEFT | TAT_TITLE, _("Variable"));
- if (flags & ~DF_DICT_INDEX)
- tab_joint_text (t, 1, 0, 2, 0, TAB_LEFT | TAT_TITLE,
- (flags & ~(DF_DICT_INDEX | DF_VARIABLE_LABELS)
- ? _("Description") : _("Label")));
- if (flags & DF_DICT_INDEX)
- tab_text (t, pc, 0, TAB_LEFT | TAT_TITLE, _("Position"));
-
- r = 1;
- for (i = 0; i < n; i++)
- r = describe_variable (vl[i], t, r, pc, flags);
- tab_hline (t, flags & ~DF_DICT_INDEX ? TAL_2 : TAL_1, 0, nc - 1, 1);
- if (flags)
+ struct pivot_dimension *attributes = pivot_dimension_create (
+ table, PIVOT_AXIS_COLUMN, N_("Attributes"));
+
+ struct heading
+ {
+ int flag;
+ const char *title;
+ };
+ static const struct heading headings[] = {
+ { DF_POSITION, N_("Position") },
+ { DF_LABEL, N_("Label") },
+ { DF_MEASUREMENT_LEVEL, N_("Measurement Level") },
+ { DF_ROLE, N_("Role") },
+ { DF_WIDTH, N_("Width") },
+ { DF_ALIGNMENT, N_("Alignment") },
+ { DF_PRINT_FORMAT, N_("Print Format") },
+ { DF_WRITE_FORMAT, N_("Write Format") },
+ { DF_MISSING_VALUES, N_("Missing Values") },
+ };
+ for (size_t i = 0; i < sizeof headings / sizeof *headings; i++)
+ if (flags & headings[i].flag)
+ pivot_category_create_leaf (attributes->root,
+ pivot_value_new_text (headings[i].title));
+
+ struct pivot_dimension *names = pivot_dimension_create (
+ table, PIVOT_AXIS_ROW, N_("Name"));
+ names->root->show_label = true;
+
+ for (size_t i = 0; i < n; i++)
+ {
+ const struct variable *v = vl[i];
+
+ struct pivot_value *name = pivot_value_new_variable (v);
+ name->variable.show = SETTINGS_VALUE_SHOW_VALUE;
+ int row = pivot_category_create_leaf (names->root, name);
+
+ int x = 0;
+ if (flags & DF_POSITION)
+ pivot_table_put2 (table, x++, row, pivot_value_new_integer (
+ var_get_dict_index (v) + 1));
+
+ if (flags & DF_LABEL)
+ {
+ const char *label = var_get_label (v);
+ if (label)
+ pivot_table_put2 (table, x, row,
+ pivot_value_new_user_text (label, -1));
+ x++;
+ }
+
+ if (flags & DF_MEASUREMENT_LEVEL)
+ pivot_table_put2 (
+ table, x++, row,
+ pivot_value_new_text (measure_to_string (var_get_measure (v))));
+
+ if (flags & DF_ROLE)
+ pivot_table_put2 (
+ table, x++, row,
+ pivot_value_new_text (var_role_to_string (var_get_role (v))));
+
+ if (flags & DF_WIDTH)
+ pivot_table_put2 (
+ table, x++, row,
+ pivot_value_new_integer (var_get_display_width (v)));
+
+ if (flags & DF_ALIGNMENT)
+ pivot_table_put2 (
+ table, x++, row,
+ pivot_value_new_text (alignment_to_string (
+ var_get_alignment (v))));
+
+ if (flags & DF_PRINT_FORMAT)
+ {
+ const struct fmt_spec *print = var_get_print_format (v);
+ char s[FMT_STRING_LEN_MAX + 1];
+
+ pivot_table_put2 (
+ table, x++, row,
+ pivot_value_new_user_text (fmt_to_string (print, s), -1));
+ }
+
+ if (flags & DF_WRITE_FORMAT)
+ {
+ const struct fmt_spec *write = var_get_write_format (v);
+ char s[FMT_STRING_LEN_MAX + 1];
+
+ pivot_table_put2 (
+ table, x++, row,
+ pivot_value_new_user_text (fmt_to_string (write, s), -1));
+ }
+
+ if (flags & DF_MISSING_VALUES)
+ {
+ char *s = mv_to_string (var_get_missing_values (v),
+ var_get_encoding (v));
+ if (s)
+ pivot_table_put2 (
+ table, x, row,
+ pivot_value_new_user_text_nocopy (s));
+
+ x++;
+ }
+ }
+
+ pivot_table_submit (table);
+}
+
+static bool
+any_value_labels (const struct variable **vars, size_t n_vars)
+{
+ for (size_t i = 0; i < n_vars; i++)
+ if (val_labs_count (var_get_value_labels (vars[i])))
+ return true;
+ return false;
+}
+
+static void
+display_value_labels (const struct variable **vars, size_t n_vars)
+{
+ if (!any_value_labels (vars, n_vars))
+ return;
+
+ struct pivot_table *table = pivot_table_create (N_("Value Labels"));
+
+ pivot_dimension_create (table, PIVOT_AXIS_COLUMN,
+ N_("Label"), N_("Label"));
+
+ struct pivot_dimension *values = pivot_dimension_create (
+ table, PIVOT_AXIS_ROW, N_("Variable Value"));
+ values->root->show_label = true;
+
+ struct pivot_footnote *missing_footnote = pivot_table_create_footnote (
+ table, pivot_value_new_text (N_("User-missing value")));
+
+ for (size_t i = 0; i < n_vars; i++)