Let scale slides hide the average or the distribution on stage

The average is now the headline of a scale result and the distribution a
compact detail below it. Two new settings (show_average, show_distribution)
hide either part in the presentation; evaluation and PDF stay complete.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Opus 5.5 committed 2026-11-11 13:29:35 +01:00
1 parent 239599e6a3
commit bf16ac0d3b
8 files changed
+183 -15

No files matched your search

+41 -5
View File
@@ -542,7 +542,10 @@
var max = Math.max.apply(null, results.buckets.map(function (b) { return b.count; }).concat([1]));
var total = results.buckets.reduce(function (sum, b) { return sum + b.count; }, 0);
var hasAverage = results.average !== null;
var nearest = hasAverage ? Math.round(results.average) : null;
var showAverage = results.showAverage !== false;
var showDistribution = results.showDistribution !== false;
// Highlight the column of the average only where the average is shown.
var nearest = hasAverage && showAverage ? Math.round(results.average) : null;
var columns = el('div', { class: 'columns' }, results.buckets.map(function (bucket) {
return el('div', { class: 'column' + (bucket.value === nearest ? ' column--avg' : '') }, [
el('div', { class: 'column__count', text: String(bucket.count) }),
@@ -569,9 +572,10 @@
el('div', { class: 'average__track' }, [
hasAverage ? el('div', { class: 'average__marker', style: 'left:' + position + '%' }) : null
]),
// Without the distribution the labels of both ends move here.
el('div', { class: 'average__ends' }, [
el('span', { text: String(results.min) }),
el('span', { text: String(results.max) })
el('span', { text: results.min + (!showDistribution && results.minLabel ? ' · ' + results.minLabel : '') }),
el('span', { text: (!showDistribution && results.maxLabel ? results.maxLabel + ' · ' : '') + results.max })
])
]);
var average = el('div', { class: 'average' }, [
@@ -586,7 +590,29 @@
gauge
]);
var comments = results.comments && results.comments.length ? Comments.render(results.comments, String) : null;
return el('div', { class: 'scale-results' }, [average, columns, labels, comments]);
return Results.scaleLayout(total, showAverage ? average : null, showDistribution ? [columns, labels] : null, comments);
},
/**
* Arranges the parts of a scale result according to showAverage/showDistribution:
* without the average the number of ratings stays visible above the distribution,
* without both it is the only figure (besides the comments).
*/
scaleLayout: function (total, average, distribution, comments) {
var countText = total === 1 ? 'Bewertung' : 'Bewertungen';
var parts = [];
if (average) {
parts.push(average);
} else if (distribution) {
parts.push(el('p', { class: 'scale-count', text: total + ' ' + countText }));
} else {
parts.push(el('div', { class: 'scale-total' }, [
el('strong', { text: String(total) }),
el('span', { text: countText })
]));
}
var modifier = average && !distribution ? ' scale-results--average' : '';
return el('div', { class: 'scale-results' + modifier }, parts.concat(distribution || [], [comments]));
},
/**
@@ -644,7 +670,17 @@
+ ' (' + value + ' von ' + results.max + ')';
})
: null;
return el('div', { class: 'scale-results' }, [average, bars, labels, comments]);
var showDistribution = results.showDistribution !== false;
if (!showDistribution && labels) {
// Without the distribution the legend stays with the average.
average.appendChild(labels);
}
return Results.scaleLayout(
total,
results.showAverage !== false ? average : null,
showDistribution ? [bars, labels] : null,
comments
);
},
/**