From 591bdbcf101c4d28cee791cc2444c414e460f7be Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 9 Aug 2022 23:30:53 -0700 Subject: [PATCH] CTABLES fix DISPLAY=NONE for scale variable names --- src/language/stats/ctables.c | 22 +++++++++ tests/language/stats/ctables.at | 83 +++++++++++++++++++++++++++++++-- 2 files changed, 101 insertions(+), 4 deletions(-) diff --git a/src/language/stats/ctables.c b/src/language/stats/ctables.c index da511b6951..0d2399f310 100644 --- a/src/language/stats/ctables.c +++ b/src/language/stats/ctables.c @@ -4359,6 +4359,23 @@ ctables_format (double d, const struct fmt_spec *format, return s; } +static bool +all_hidden_vlabels (const struct ctables_table *t, enum pivot_axis_type a) +{ + for (size_t i = 0; i < t->stacks[a].n; i++) + { + struct ctables_nest *nest = &t->stacks[a].nests[i]; + if (nest->n != 1 || nest->scale_idx != 0) + return false; + + enum ctables_vlabel vlabel + = t->ctables->vlabels[var_get_dict_index (nest->vars[0])]; + if (vlabel != CTVL_NONE) + return false; + } + return true; +} + static void ctables_table_output (struct ctables *ct, struct ctables_table *t) { @@ -4509,6 +4526,8 @@ ctables_table_output (struct ctables *ct, struct ctables_table *t) for (size_t k = 0; k < nest->n; k++) { enum ctables_vlabel vlabel = ct->vlabels[var_get_dict_index (nest->vars[k])]; + if (vlabel == CTVL_NONE && nest->scale_idx == k) + vlabel = CTVL_NAME; if (vlabel != CTVL_NONE) { levels[n_levels++] = (struct ctables_level) { @@ -4637,7 +4656,10 @@ ctables_table_output (struct ctables *ct, struct ctables_table *t) free (groups); free (levels); free (sections); + } + + d[a]->hide_all_labels = all_hidden_vlabels (t, a); } { diff --git a/tests/language/stats/ctables.at b/tests/language/stats/ctables.at index 26ff5f9de5..5f8120c69b 100644 --- a/tests/language/stats/ctables.at +++ b/tests/language/stats/ctables.at @@ -3230,16 +3230,91 @@ AT_CHECK([pspp ctables.sps -O box=unicode -O width=120], [0], [dnl AT_CLEANUP -AT_SETUP([CTABLES scale summary functions - assertion failure]) +AT_SETUP([CTABLES hidden scale VLABELS]) AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .]) AT_DATA([ctables.sps], [[GET 'nhtsa.sav'. +CTABLES + /TABLE region BY qn19a + qn35 + /SLABELS POSITION=ROW. CTABLES /VLABELS VARIABLE=qn19a DISPLAY=NONE - /TABLE region BY qn19a - /CATEGORIES VARIABLES=qn19a TOTAL=YES MISSING=INCLUDE + /TABLE region BY qn19a + qn35 + /SLABELS POSITION=ROW. +CTABLES + /VLABELS VARIABLE=qn35 DISPLAY=NONE + /TABLE region BY qn19a + qn35 + /SLABELS POSITION=ROW. + +* This one in particular caused a crash because no categories were + created on the column axis, so passing in 0 for the index was still + too big for that number of categories. It was fixed by creating a + name-only category for each variable despite the "NONE" request, + then hiding the entire dimension's labels if all its labels were + set to "NONE". +CTABLES + /VLABELS VARIABLE=qn19a qn35 DISPLAY=NONE + /TABLE region BY qn19a + qn35 /SLABELS POSITION=ROW. ]]) -AT_CHECK([pspp ctables.sps -O box=unicode -O width=120], [0], []) +AT_CHECK([pspp ctables.sps -O box=unicode], [0], [dnl + Custom Tables +╭──────────────┬────────────────────────────┬─────────────────────────────────╮ +│ │ 19a. About how old were you│ 35. In the past thirty days, how│ +│ │ when you first starting │ many times have you driven a │ +│ │ drinking alcohol, not │ motor vehicle WITHIN TWO HOURS │ +│ │ counting small tastes or │ AFTER drinking alcoholic │ +│ │ sips of alcohol. │ beverages? │ +├──────────────┼────────────────────────────┼─────────────────────────────────┤ +│Region NE Mean│ 19.33│ 2│ +│ ╶───────┼────────────────────────────┼─────────────────────────────────┤ +│ MW Mean│ 19.83│ 2│ +│ ╶───────┼────────────────────────────┼─────────────────────────────────┤ +│ S Mean│ 20.29│ 2│ +│ ╶───────┼────────────────────────────┼─────────────────────────────────┤ +│ W Mean│ 19.87│ 2│ +╰──────────────┴────────────────────────────┴─────────────────────────────────╯ + + Custom Tables +╭──────────────┬─────┬────────────────────────────────────────────────────────╮ +│ │ │ 35. In the past thirty days, how many times have you │ +│ │ │ driven a motor vehicle WITHIN TWO HOURS AFTER drinking │ +│ │QN19A│ alcoholic beverages? │ +├──────────────┼─────┼────────────────────────────────────────────────────────┤ +│Region NE Mean│19.33│ 2│ +│ ╶───────┼─────┼────────────────────────────────────────────────────────┤ +│ MW Mean│19.83│ 2│ +│ ╶───────┼─────┼────────────────────────────────────────────────────────┤ +│ S Mean│20.29│ 2│ +│ ╶───────┼─────┼────────────────────────────────────────────────────────┤ +│ W Mean│19.87│ 2│ +╰──────────────┴─────┴────────────────────────────────────────────────────────╯ + + Custom Tables +╭──────────────┬─────────────────────────────────────────────────────────┬────╮ +│ │ 19a. About how old were you when you first starting │ │ +│ │ drinking alcohol, not counting small tastes or sips of │ │ +│ │ alcohol. │qn35│ +├──────────────┼─────────────────────────────────────────────────────────┼────┤ +│Region NE Mean│ 19.33│ 2│ +│ ╶───────┼─────────────────────────────────────────────────────────┼────┤ +│ MW Mean│ 19.83│ 2│ +│ ╶───────┼─────────────────────────────────────────────────────────┼────┤ +│ S Mean│ 20.29│ 2│ +│ ╶───────┼─────────────────────────────────────────────────────────┼────┤ +│ W Mean│ 19.87│ 2│ +╰──────────────┴─────────────────────────────────────────────────────────┴────╯ + + Custom Tables +╭──────────────┬───────╮ +│Region NE Mean│19.33 2│ +│ ╶───────┼───────┤ +│ MW Mean│19.83 2│ +│ ╶───────┼───────┤ +│ S Mean│20.29 2│ +│ ╶───────┼───────┤ +│ W Mean│19.87 2│ +╰──────────────┴───────╯ +]) AT_CLEANUP -- 2.30.2