}
}
-static char *
-ctables_summary_default_label (enum ctables_summary_function function,
- double percentile)
+static struct pivot_value *
+ctables_summary_label (const struct ctables_summary_spec *spec, double cilevel)
{
- static const char *default_labels[] = {
+ if (!spec->label)
+ {
+ static const char *default_labels[] = {
#define S(ENUM, NAME, LABEL, FORMAT, AVAILABILITY) [ENUM] = LABEL,
- SUMMARIES
+ SUMMARIES
#undef S
- };
+ };
- return (function == CTSF_PTILE
- ? xasprintf (_("Percentile %.2f"), percentile)
- : xstrdup (gettext (default_labels[function])));
+ return (spec->function == CTSF_PTILE
+ ? pivot_value_new_text_format (N_("Percentile %.2f"),
+ spec->percentile)
+ : pivot_value_new_text (default_labels[spec->function]));
+ }
+ else
+ {
+ struct substring in = ss_cstr (spec->label);
+ struct substring target = ss_cstr (")CILEVEL");
+
+ struct string out = DS_EMPTY_INITIALIZER;
+ for (;;)
+ {
+ size_t chunk = ss_find_substring (in, target);
+ ds_put_substring (&out, ss_head (in, chunk));
+ ss_advance (&in, chunk);
+ if (!in.length)
+ return pivot_value_new_user_text_nocopy (ds_steal_cstr (&out));
+
+ ss_advance (&in, target.length);
+ ds_put_format (&out, "%g", cilevel);
+ }
+ }
}
static const char *
*dst = (struct ctables_summary_spec) {
.function = function,
.percentile = percentile,
- .label = xstrdup (label),
+ .label = xstrdup_if_nonnull (label),
.format = (format ? *format
: ctables_summary_default_format (function, axis->var)),
.is_ctables_format = is_ctables_format,
}
/* Parse label. */
- char *label;
+ char *label = NULL;
if (lex_is_string (ctx->lexer))
{
label = ss_xstrdup (lex_tokss (ctx->lexer));
lex_get (ctx->lexer);
}
- else
- label = ctables_summary_default_label (function, percentile);
/* Parse format. */
struct fmt_spec format;
return as->function > bs->function ? 1 : -1;
else if (as->percentile != bs->percentile)
return as->percentile < bs->percentile ? 1 : -1;
- return strcmp (as->label, bs->label);
+
+ const char *as_label = as->label ? as->label : "";
+ const char *bs_label = bs->label ? bs->label : "";
+ return strcmp (as_label, bs_label);
}
static struct pivot_value *
d->hide_all_labels = true;
for (size_t i = 0; i < specs->n; i++)
pivot_category_create_leaf (
- d->root, pivot_value_new_text (specs->specs[i].label));
+ d->root, ctables_summary_label (&specs->specs[i], t->cilevel));
}
bool categories_dimension = t->clabels_example != NULL;
for (size_t m = 0; m < specs->n; m++)
{
int leaf = pivot_category_create_leaf (
- parent, pivot_value_new_text (specs->specs[m].label));
+ parent, ctables_summary_label (&specs->specs[m],
+ t->cilevel));
if (!m)
prev_leaf = leaf;
}
*specs->specs = (struct ctables_summary_spec) {
.function = function,
.format = ctables_summary_default_format (function, specs->var),
- .label = ctables_summary_default_label (function, 0),
};
if (!specs->var)
specs->var = nest->vars[0];