From 17d55caeb97f23f16818e88ddeb5319d8c4f2369 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sat, 28 Jan 2023 10:02:37 -0800 Subject: [PATCH] pivot-output: When there's no dimension border, use the category border. This is compatible behavior. --- src/output/pivot-output.c | 72 ++++++++++++++++++++++++++++++++----- tests/output/pivot-table.at | 58 ++++++++++++++++-------------- 2 files changed, 95 insertions(+), 35 deletions(-) diff --git a/src/output/pivot-output.c b/src/output/pivot-output.c index 8a6e9c8659..3666ffbcee 100644 --- a/src/output/pivot-output.c +++ b/src/output/pivot-output.c @@ -432,10 +432,70 @@ collect_footnotes (const struct pivot_table *pt, return footnotes; } +static enum pivot_border +pivot_border_fallback (enum pivot_border border) +{ + switch (border) + { + case PIVOT_BORDER_TITLE: + case PIVOT_BORDER_OUTER_LEFT: + case PIVOT_BORDER_OUTER_TOP: + case PIVOT_BORDER_OUTER_RIGHT: + case PIVOT_BORDER_OUTER_BOTTOM: + case PIVOT_BORDER_INNER_LEFT: + case PIVOT_BORDER_INNER_TOP: + case PIVOT_BORDER_INNER_RIGHT: + case PIVOT_BORDER_INNER_BOTTOM: + case PIVOT_BORDER_DATA_LEFT: + case PIVOT_BORDER_DATA_TOP: + return border; + + /* Dimensions. */ + case PIVOT_BORDER_DIM_ROW_HORZ: + return PIVOT_BORDER_CAT_ROW_HORZ; + case PIVOT_BORDER_DIM_ROW_VERT: + return PIVOT_BORDER_CAT_ROW_VERT; + case PIVOT_BORDER_DIM_COL_HORZ: + return PIVOT_BORDER_CAT_COL_HORZ; + case PIVOT_BORDER_DIM_COL_VERT: + return PIVOT_BORDER_CAT_COL_VERT; + + /* Categories. */ + case PIVOT_BORDER_CAT_ROW_HORZ: + case PIVOT_BORDER_CAT_ROW_VERT: + case PIVOT_BORDER_CAT_COL_HORZ: + case PIVOT_BORDER_CAT_COL_VERT: + return border; + + case PIVOT_N_BORDERS: + default: + NOT_REACHED (); + } +} + +static struct table_border_style +resolve_border_style (const struct pivot_table_look *look, enum pivot_border b, + bool show_grid_lines) +{ + struct table_border_style style = look->borders[b]; + if (style.stroke != TABLE_STROKE_NONE) + return style; + + style = look->borders[pivot_border_fallback (b)]; + if (style.stroke != TABLE_STROKE_NONE) + return style; + + if (show_grid_lines) + return (struct table_border_style) { .stroke = TABLE_STROKE_DASHED, + .color = CELL_COLOR_BLACK }; + + return style; +} + void pivot_output (const struct pivot_table *pt, const size_t *layer_indexes, - bool printing UNUSED, + bool printing, struct table **titlep, struct table **layersp, struct table **bodyp, @@ -467,14 +527,8 @@ pivot_output (const struct pivot_table *pt, body->borders = pool_nmalloc (body->container, PIVOT_N_BORDERS, sizeof *body->borders); for (size_t i = 0; i < PIVOT_N_BORDERS; i++) - { - const struct table_border_style *src = &pt->look->borders[i]; - struct table_border_style *dst = &body->borders[i]; - *dst = (!printing && pt->show_grid_lines && src->stroke == TABLE_STROKE_NONE - ? (struct table_border_style) { .stroke = TABLE_STROKE_DASHED, - .color = CELL_COLOR_BLACK } - : *src); - } + body->borders[i] = resolve_border_style (pt->look, i, + printing && pt->show_grid_lines); compose_headings (body, &pt->axes[PIVOT_AXIS_COLUMN], H, &pt->axes[PIVOT_AXIS_ROW], diff --git a/tests/output/pivot-table.at b/tests/output/pivot-table.at index 96138610be..9e006eac0a 100644 --- a/tests/output/pivot-table.at +++ b/tests/output/pivot-table.at @@ -700,23 +700,28 @@ d3 c1 54│55 56│57│58 59│60│61 62 Category Borders 1 b - bg1 - b1 b2 b3 - a a a - ag1 ag1 ag1 -d c a1 a2┊a3 a1 a2┊a3 a1 a2┊a3 -dg1 d1 c1 0 1┊ 2 3 4┊ 5 6 7┊ 8 - cg1 c2 9 10┊11 12 13┊14 15 16┊17 - ╶╌╌╌╌╌╌╌╌+╌╌╌╌╌╌╌╌+╌╌╌╌╌╌╌╌+╌╌ - c3 18 19┊20 21 22┊23 24 25┊26 - d2 c1 27 28┊29 30 31┊32 33 34┊35 - cg1 c2 36 37┊38 39 40┊41 42 43┊44 - ╶╌╌╌╌╌╌╌╌+╌╌╌╌╌╌╌╌+╌╌╌╌╌╌╌╌+╌╌ - c3 45 46┊47 48 49┊50 51 52┊53 -d3 c1 54 55┊56 57 58┊59 60 61┊62 - cg1 c2 63 64┊65 66 67┊68 69 70┊71 - ╶╌╌╌╌╌╌╌╌+╌╌╌╌╌╌╌╌+╌╌╌╌╌╌╌╌+╌╌ - c3 72 73┊74 75 76┊77 78 79┊80 + bg1 ┊ + b1 ┊ b2 ┊ b3 + a ┊ a ┊ a + ┊ ag1 ┊ ┊ ag1 ┊ ┊ ag1 +d c a1┊a2┊a3┊a1┊a2┊a3┊a1┊a2┊a3 +dg1 d1 c1 0┊ 1┊ 2┊ 3┊ 4┊ 5┊ 6┊ 7┊ 8 + ╶╌╌╌╌╌╌╌╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌ + cg1 c2 9┊10┊11┊12┊13┊14┊15┊16┊17 + ╶╌╌╌╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌ + c3 18┊19┊20┊21┊22┊23┊24┊25┊26 + ╶╌╌╌╌╌╌╌╌╌╌╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌ + d2 c1 27┊28┊29┊30┊31┊32┊33┊34┊35 + ╶╌╌╌╌╌╌╌╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌ + cg1 c2 36┊37┊38┊39┊40┊41┊42┊43┊44 + ╶╌╌╌╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌ + c3 45┊46┊47┊48┊49┊50┊51┊52┊53 +╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌ +d3 c1 54┊55┊56┊57┊58┊59┊60┊61┊62 + ╶╌╌╌╌╌╌╌╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌ + cg1 c2 63┊64┊65┊66┊67┊68┊69┊70┊71 + ╶╌╌╌╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌+╌╌ + c3 72┊73┊74┊75┊76┊77┊78┊79┊80 Category and Dimension Borders 1 b @@ -796,20 +801,21 @@ Category Borders 2 bg1 ╶╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╴ b1 b2 b3 + ╶╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ a a a ╶╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ag1 ag1 ag1 ╶╌╌╌╌╌╴ ╶╌╌╌╌╌╴ ╶╌╌╌╌╌ d c a1 a2 a3 a1 a2 a3 a1 a2 a3 -dg1┊d1 c1 0 1 2 3 4 5 6 7 8 - ┊ cg1┊c2 9 10 11 12 13 14 15 16 17 - ┊ ┊c3 18 19 20 21 22 23 24 25 26 - ┊d2 c1 27 28 29 30 31 32 33 34 35 - ┊ cg1┊c2 36 37 38 39 40 41 42 43 44 - ┊ ┊c3 45 46 47 48 49 50 51 52 53 -d3 c1 54 55 56 57 58 59 60 61 62 - cg1┊c2 63 64 65 66 67 68 69 70 71 - ┊c3 72 73 74 75 76 77 78 79 80 +dg1┊d1┊c1 0 1 2 3 4 5 6 7 8 + ┊ ┊cg1┊c2 9 10 11 12 13 14 15 16 17 + ┊ ┊ ┊c3 18 19 20 21 22 23 24 25 26 + ┊d2┊c1 27 28 29 30 31 32 33 34 35 + ┊ ┊cg1┊c2 36 37 38 39 40 41 42 43 44 + ┊ ┊ ┊c3 45 46 47 48 49 50 51 52 53 +d3 ┊c1 54 55 56 57 58 59 60 61 62 + ┊cg1┊c2 63 64 65 66 67 68 69 70 71 + ┊ ┊c3 72 73 74 75 76 77 78 79 80 Category and Dimension Borders 2 b -- 2.30.2