Add a star rating style to scale slides

Scales can now be shown as stars (1 to n) instead of numbered steps:
participants tap stars, the stage shows the average as partly filled
stars and the distribution as bars from most to fewest stars, and the
evaluation page and PDF export print ratings as stars.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Opus 5.5 committed 2026-11-11 12:46:33 +01:00
1 parent 1ee870d67c
commit c1f9be2eef
14 files changed
+400 -31

No files matched your search

+40 -6
View File
@@ -30,6 +30,8 @@
--qa: #1f6bb0; /* Q&A accent, AA contrast with white text */
--notice-bg: #fff6e0;
--notice-ink: #6b4a00;
--star: #d48500; /* star rating, 3:1 against light surfaces */
--star-empty: #c3c8da;
color-scheme: light;
}
@@ -50,6 +52,8 @@
--shadow: none;
--notice-bg: #3a2f12;
--notice-ink: #f3d98f;
--star: #ffc233;
--star-empty: #464a66;
color-scheme: dark;
}
@@ -67,6 +71,8 @@
--shadow: none;
--notice-bg: #3a2f12;
--notice-ink: #f3d98f;
--star: #ffc233;
--star-empty: #464a66;
color-scheme: dark;
}
}
@@ -298,12 +304,12 @@ textarea { resize: vertical; }
.order-option__pos { min-width: 2em; text-align: right; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.order-options.error .order-options__list input[type=text] { border-color: var(--danger); }
/* dashboard: PDF export, choice between public and complete version */
.export-choice { border: 0; padding: 0; margin: 0 0 12px; display: grid; gap: 8px; }
.export-choice legend { font-weight: 600; margin-bottom: 4px; }
.export-choice label { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 2px solid var(--border); border-radius: 8px; cursor: pointer; }
.export-choice label:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.export-choice input { width: 18px; height: 18px; margin: 2px 0 0; flex: none; accent-color: var(--primary); }
/* radio cards: PDF export (public/complete version), scale style (numbers/stars) */
.export-choice, .scale-style { border: 0; padding: 0; margin: 0 0 12px; display: grid; gap: 8px; }
.export-choice legend, .scale-style legend { font-weight: 600; margin-bottom: 4px; }
.export-choice label, .scale-style label { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 2px solid var(--border); border-radius: 8px; cursor: pointer; }
.export-choice label:has(input:checked), .scale-style label:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.export-choice input, .scale-style input { width: 18px; height: 18px; margin: 2px 0 0; flex: none; accent-color: var(--primary); }
.export-choice strong { display: block; }
.export-choice .hint { display: block; margin: 2px 0 0; }
@@ -352,6 +358,20 @@ textarea { resize: vertical; }
.scale__step input:checked + span { border-color: var(--primary); background: var(--primary); color: #fff; }
.scale__step input:focus-visible + span { outline: 3px solid var(--primary-soft); }
.scale__labels { display: flex; justify-content: space-between; font-size: .85rem; color: var(--muted); }
/* star rating: stars up to the checked (or hovered) one are filled; :has() keeps the DOM order 1..n for arrow keys */
.stars { display: flex; justify-content: center; margin: 20px 0 6px; }
.stars__star { position: relative; padding: 0 4px; cursor: pointer; font-size: clamp(2.4rem, 13vw, 3.4rem); line-height: 1; color: var(--star); }
.stars--many .stars__star { padding: 0 1px; font-size: clamp(1.5rem, 7.5vw, 2.4rem); }
.stars__star input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.stars__icon { display: block; transition: color .15s, transform .15s; }
/* :where() keeps these weaker than the hover preview below */
:where(.stars:not(:has(input:checked))) .stars__star, :where(.stars__star:has(input:checked)) ~ .stars__star { color: var(--star-empty); }
.stars__star:has(input:focus-visible) .stars__icon { outline: 3px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
@media (hover: hover) {
.stars:hover .stars__star { color: var(--star); }
.stars .stars__star:hover ~ .stars__star { color: var(--star-empty); }
.stars__star:hover .stars__icon { transform: scale(1.12); }
}
.done { font-size: 1.1rem; font-weight: 600; color: var(--ok); }
.waiting { padding: 48px 24px; }
.pulse { width: 18px; height: 18px; border-radius: 50%; background: var(--primary); margin: 0 auto 24px; animation: pulse 1.6s infinite; }
@@ -432,6 +452,12 @@ textarea { resize: vertical; }
.average__track { position: relative; height: 12px; border-radius: 99px; background: linear-gradient(90deg, var(--bg), var(--c1)); box-shadow: inset 0 0 0 1px var(--border); }
.average__marker { position: absolute; top: 50%; width: 1.6em; height: 1.6em; margin: -.8em 0 0 -.8em; border-radius: 50%; background: var(--c1); border: .25em solid var(--bg); box-shadow: 0 1px 4px rgba(0, 0, 0, .35); transition: left .6s ease; }
.average__ends { display: flex; justify-content: space-between; margin-top: 8px; font-size: .85rem; font-weight: 700; color: var(--muted); }
/* star rating results: average as partly filled stars, bars from most to fewest stars */
.star-meter { position: relative; display: inline-block; font-size: 2.6rem; line-height: 1; letter-spacing: .08em; white-space: nowrap; }
.star-meter__base { color: var(--star-empty); }
.star-meter__fill { position: absolute; top: 0; left: 0; overflow: hidden; color: var(--star); transition: width .6s ease; }
.bar--star .bar__fill { background: var(--star); }
.stars-legend { margin: 10px 0 0; font-size: .85rem; color: var(--muted); }
.cloud { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: .2em .6em; line-height: 1.15; padding: 8px; }
.cloud__word { font-weight: 800; color: var(--c0); transition: font-size .6s ease; }
@@ -576,6 +602,7 @@ button.qa-steps__step:hover:not(:disabled) { color: var(--text); border-color: v
.scale-table th, .scale-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.scale-table td:last-child { width: 50%; }
.scale-table__bar { display: block; height: 6px; min-width: 2px; margin-bottom: 4px; border-radius: 3px; background: var(--c2); }
.rating-stars { color: var(--star); letter-spacing: .05em; white-space: nowrap; }
/* ---------------------------------------------------------------- presenter */
/* Dark by default (beamer); the presenter's own switch can make it light (data-theme="light"). */
@@ -588,6 +615,8 @@ body.present {
--stage-glow: #2a1f6e;
--stage-ok: #3ddc97; /* brighter green for contrast on the dark stage */
--overlay-bg: rgba(8, 9, 20, .92);
--star: #ffc233;
--star-empty: #3a3d60;
background: radial-gradient(1200px 600px at 10% -10%, var(--stage-glow) 0%, transparent 60%), var(--bg);
color: var(--text);
overflow: hidden;
@@ -602,6 +631,8 @@ body.present {
--stage-glow: #dcd8ff;
--stage-ok: var(--ok);
--overlay-bg: rgba(245, 246, 251, .95);
--star: #d48500;
--star-empty: #c3c8da;
}
.stage__top { display: flex; justify-content: space-between; align-items: center; gap: 16px; font-size: clamp(1rem, 1.6vw, 1.4rem); color: var(--muted); }
.stage__top strong { color: var(--text); }
@@ -627,6 +658,9 @@ body.present {
.stage .average__label, .stage .average__count, .stage .average__ends { font-size: clamp(.85rem, 1.2vw, 1.1rem); }
.stage .average__track { height: .7em; box-shadow: none; background: linear-gradient(90deg, var(--surface-2), var(--c1)); }
.stage .average__ends { margin-top: 4px; }
.stage .star-meter { font-size: clamp(2.4rem, 5.5vw, 5rem); }
.stage .bars--stars { gap: 1.2vh; }
.stage .stars-legend { font-size: clamp(.85rem, 1.2vw, 1.1rem); }
.stage .cloud { font-size: clamp(1.4rem, 2.6vw, 2.6rem); }
.stage .answers { columns: 340px; }
.stage .quiz-timer { font-size: clamp(3rem, 7vw, 6rem); }
+95 -3
View File
@@ -302,6 +302,7 @@
paused: false,
timer: null,
items: [],
format: String,
node: null,
// Countdown of the comment shown (drives the progress bar across re-renders).
startedAt: 0,
@@ -315,8 +316,10 @@
/**
* @param {Array} items comments, oldest first
* @param {Function} format turns a rating into display text (number or stars)
*/
render: function (items) {
render: function (items, format) {
Comments.format = format || String;
// A different first comment means a different slide (or a reset): start over.
var key = String(items[0].id);
if (key !== Comments.key) {
@@ -443,7 +446,7 @@
'Kommentar ' + (Comments.index + 1) + ' von ' + Comments.items.length;
text.textContent = item.text;
var value = node.querySelector('[data-comment-value]');
value.textContent = item.value === null || item.value === undefined ? '' : 'Bewertung: ' + item.value;
value.textContent = item.value === null || item.value === undefined ? '' : 'Bewertung: ' + Comments.format(item.value);
value.hidden = value.textContent === '';
// Only announce changes the viewer triggered, not every automatic rotation.
node.setAttribute('aria-live', Comments.paused ? 'polite' : 'off');
@@ -529,6 +532,9 @@
},
scale: function (results) {
if (results.stars) {
return Results.stars(results);
}
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;
@@ -575,10 +581,68 @@
]),
gauge
]);
var comments = results.comments && results.comments.length ? Comments.render(results.comments) : null;
var comments = results.comments && results.comments.length ? Comments.render(results.comments, String) : null;
return el('div', { class: 'scale-results' }, [average, columns, labels, comments]);
},
/**
* Star rating (scale with stars): average as partly filled stars, distribution as
* horizontal bars from most to fewest stars, like a product rating.
*/
stars: function (results) {
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 averageText = hasAverage
? Number(results.average).toLocaleString('de-DE', { minimumFractionDigits: 1, maximumFractionDigits: 1 })
: '–';
var row = Array(results.max + 1).join('★');
var meter = el('div', {
class: 'star-meter',
role: 'img',
'aria-label': 'Durchschnitt ' + averageText + ' von ' + results.max + ' Sternen'
}, [
// Same glyphs twice: the filled layer is clipped to the average.
el('span', { class: 'star-meter__base', 'aria-hidden': 'true', text: row }),
el('span', {
class: 'star-meter__fill',
'aria-hidden': 'true',
style: 'width:' + (hasAverage ? results.average / results.max * 100 : 0) + '%',
text: row
})
]);
var average = el('div', { class: 'average average--stars' }, [
el('div', { class: 'average__figure' }, [
el('span', { class: 'average__label', text: 'Durchschnitt' }),
el('span', { class: 'average__value' }, [
el('strong', { text: averageText }),
el('span', { class: 'average__of', text: ' von ' + results.max })
]),
el('span', { class: 'average__count', text: total + (total === 1 ? ' Bewertung' : ' Bewertungen') })
]),
meter
]);
var bars = el('div', { class: 'bars bars--stars' }, results.buckets.slice().reverse().map(function (bucket) {
return el('div', { class: 'bar bar--star' }, [
el('div', { class: 'bar__label', text: bucket.value + (bucket.value === 1 ? ' Stern' : ' Sterne') }),
el('div', { class: 'bar__track' }, [
el('div', { class: 'bar__fill', style: 'width:' + (bucket.count / max * 100) + '%' })
]),
el('div', { class: 'bar__value', text: formatNumber(bucket.percent) + ' % (' + bucket.count + ')' })
]);
}));
var labels = results.minLabel || results.maxLabel
? el('p', { class: 'stars-legend', text: '1 Stern: ' + (results.minLabel || '–') + ' · ' + results.max + ' Sterne: ' + (results.maxLabel || '–') })
: null;
var comments = results.comments && results.comments.length
? Comments.render(results.comments, function (value) {
return row.slice(0, value) + Array(results.max - value + 1).join('☆')
+ ' (' + value + ' von ' + results.max + ')';
})
: null;
return el('div', { class: 'scale-results' }, [average, bars, labels, comments]);
},
/**
* options: {mine: [keys], down: [keys], onUpvote: fn(word)|null, onDownvote: fn(word)|null}
* Counts are shown as "+up" and "−down" (down only when > 0 or clickable).
@@ -2196,6 +2260,33 @@
});
}
// ------------------------------------------------------------------ scale style (slide form)
/**
* Stars always start at one star: hide "Von" and call "Bis" the number of stars.
* Without JS both fields stay visible and the server ignores "Von" for stars.
*/
function initScaleStyle(fieldset) {
var form = fieldset.form || fieldset.closest('form');
var min = form.querySelector('[data-scale-min]');
var max = form.querySelector('[data-label-stars]');
var maxLabel = max && form.querySelector('label[for="' + max.id + '"]');
function update() {
var checked = fieldset.querySelector('input[type=radio]:checked');
var stars = checked !== null && checked.value === 'stars';
if (min) {
min.hidden = stars;
}
if (maxLabel) {
maxLabel.textContent = max.getAttribute(stars ? 'data-label-stars' : 'data-label-numbers');
}
}
fieldset.addEventListener('change', update);
update();
}
// ------------------------------------------------------------------ theme switch
var THEME_ICONS = { auto: '◐', light: '☀', dark: '☾' };
@@ -2264,6 +2355,7 @@
document.querySelectorAll('[data-sortable]').forEach(initSortable);
document.querySelectorAll('[data-order-options]').forEach(initOrderOptions);
document.querySelectorAll('[data-order-form]').forEach(initOrderForm);
document.querySelectorAll('[data-scale-style]').forEach(initScaleStyle);
// Prevent double submits of vote forms.
document.querySelectorAll('.vote-form').forEach(function (form) {