Feature/star rating #46
No files matched your search
@@ -230,12 +230,13 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures
|
|||||||
- **Sterne-Bewertung** (Skala mit Setting `style = stars`, `Slide::isStarRating()`, Standard `numbers`): immer 1 bis `scale_max`
|
- **Sterne-Bewertung** (Skala mit Setting `style = stars`, `Slide::isStarRating()`, Standard `numbers`): immer 1 bis `scale_max`
|
||||||
Sterne (`SlidesTable::sanitizeSettings()` erzwingt `scale_min = 1`), gespeichert wie jede Skala als `numeric_value`.
|
Sterne (`SlidesTable::sanitizeSettings()` erzwingt `scale_min = 1`), gespeichert wie jede Skala als `numeric_value`.
|
||||||
Teilnehmende wählen Sterne (Radios in DOM-Reihenfolge 1..n, Füllung per CSS `:has()`), der State enthält `results.stars`;
|
Teilnehmende wählen Sterne (Radios in DOM-Reihenfolge 1..n, Füllung per CSS `:has()`), der State enthält `results.stars`;
|
||||||
`Results.stars` in `plenario.js` zeigt den Durchschnitt als teilweise gefüllte Sterne und die Verteilung als Balken 5 → 1.
|
`Results.stars` in `plenario.js` zeigt den Durchschnitt als teilweise gefüllte Sterne und die Verteilung als Donut 5 → 1.
|
||||||
Text-Ausgabe (Auswertung, PDF) über `Slide::ratingText()` (`★★★★☆`), barrierearm über `element/rating`.
|
Text-Ausgabe (Auswertung, PDF) über `Slide::ratingText()` (`★★★★☆`), barrierearm über `element/rating`.
|
||||||
- **Skala-Teile in der Präsentation** (Settings `show_average` / `show_distribution`, Standard an): blenden Durchschnitt
|
- **Skala-Darstellung auf der Bühne:** Durchschnitt (große Zahl + Skala bzw. Sterne) und Verteilung (Donut per CSS
|
||||||
bzw. Verteilung nur auf der Bühne (Presenter/Embed) aus; das JSON bleibt vollständig und trägt `results.showAverage` /
|
`conic-gradient`, Abstufungen einer Farbe, Legende mit „% (Anzahl)“ und den Beschriftungen der Enden) nebeneinander
|
||||||
`showDistribution`, `Results.scaleLayout()` in `plenario.js` ordnet die Teile an (ohne Durchschnitt bleibt die Anzahl
|
(`Results.scaleLayout()` / `Results.donut()`). Setting `scale_view` (`Slide::SCALE_VIEWS`: `both` | `average` | `chart`,
|
||||||
sichtbar, ohne Verteilung wandern die Beschriftungen zum Durchschnitt). Auswertung und PDF zeigen immer alles.
|
Dropdown im Formular) zeigt nur einen Teil, dann zentriert; im JSON `results.view`, die Daten bleiben vollständig.
|
||||||
|
Gilt nur für Presenter/Embed, Auswertung und PDF zeigen immer beides.
|
||||||
- **Antwort nachträglich bearbeiten** (gegen Tippfehler, `VoteService::hasEditableText()`): Antwort einer offenen Frage
|
- **Antwort nachträglich bearbeiten** (gegen Tippfehler, `VoteService::hasEditableText()`): Antwort einer offenen Frage
|
||||||
(darf nicht leer werden) bzw. Kommentar einer Skala (ändern, ergänzen, leeren; die Bewertung bleibt unveränderlich),
|
(darf nicht leer werden) bzw. Kommentar einer Skala (ändern, ergänzen, leeren; die Bewertung bleibt unveränderlich),
|
||||||
nur solange die Abstimmung offen ist. `participate:edit` → `VoteService::editText()`, gleiche Vorbedingungen wie
|
nur solange die Abstimmung offen ist. `participate:edit` → `VoteService::editText()`, gleiche Vorbedingungen wie
|
||||||
|
|||||||
@@ -61,6 +61,14 @@ class Slide extends Entity
|
|||||||
public const SCALE_NUMBERS = 'numbers';
|
public const SCALE_NUMBERS = 'numbers';
|
||||||
public const SCALE_STARS = 'stars';
|
public const SCALE_STARS = 'stars';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What a scale shows in the presentation: average and distribution (chart), or only one of them.
|
||||||
|
*/
|
||||||
|
public const SCALE_VIEW_BOTH = 'both';
|
||||||
|
public const SCALE_VIEW_AVERAGE = 'average';
|
||||||
|
public const SCALE_VIEW_CHART = 'chart';
|
||||||
|
public const SCALE_VIEWS = [self::SCALE_VIEW_BOTH, self::SCALE_VIEW_AVERAGE, self::SCALE_VIEW_CHART];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Q&A stages, see qaStage(): participants submit questions, then upvote
|
* Q&A stages, see qaStage(): participants submit questions, then upvote
|
||||||
* them, then the presenter discusses them one by one (most upvoted first).
|
* them, then the presenter discusses them one by one (most upvoted first).
|
||||||
@@ -95,13 +103,13 @@ class Slide extends Entity
|
|||||||
// comment_ratings: show the rating next to each comment in the presentation
|
// comment_ratings: show the rating next to each comment in the presentation
|
||||||
// (time per comment depends on its length, see Comments.delay() in plenario.js)
|
// (time per comment depends on its length, see Comments.delay() in plenario.js)
|
||||||
// style: numbers or stars (SCALE_*), stars always start at scale_min = 1
|
// style: numbers or stars (SCALE_*), stars always start at scale_min = 1
|
||||||
// show_average / show_distribution: parts of the result shown in the presentation (presenter/embed);
|
// scale_view: parts of the result shown in the presentation (presenter/embed, SCALE_VIEWS);
|
||||||
// the evaluation in the admin area and the PDF export always contain both
|
// the evaluation in the admin area and the PDF export always contain both
|
||||||
self::TYPE_SCALE => [
|
self::TYPE_SCALE => [
|
||||||
'style' => self::SCALE_NUMBERS,
|
'style' => self::SCALE_NUMBERS,
|
||||||
'scale_min' => 1, 'scale_max' => 5, 'min_label' => '', 'max_label' => '', 'private' => false,
|
'scale_min' => 1, 'scale_max' => 5, 'min_label' => '', 'max_label' => '', 'private' => false,
|
||||||
'comments' => false, 'comment_ratings' => false,
|
'comments' => false, 'comment_ratings' => false,
|
||||||
'show_average' => true, 'show_distribution' => true,
|
'scale_view' => self::SCALE_VIEW_BOTH,
|
||||||
],
|
],
|
||||||
self::TYPE_CONTENT => [],
|
self::TYPE_CONTENT => [],
|
||||||
// time_limit in seconds, 0 = no limit (presenter ends the quiz)
|
// time_limit in seconds, 0 = no limit (presenter ends the quiz)
|
||||||
|
|||||||
@@ -162,8 +162,8 @@ class SlidesTable extends Table
|
|||||||
$settings['private'] = filter_var($input['private'] ?? false, FILTER_VALIDATE_BOOLEAN);
|
$settings['private'] = filter_var($input['private'] ?? false, FILTER_VALIDATE_BOOLEAN);
|
||||||
$settings['comments'] = filter_var($input['comments'] ?? false, FILTER_VALIDATE_BOOLEAN);
|
$settings['comments'] = filter_var($input['comments'] ?? false, FILTER_VALIDATE_BOOLEAN);
|
||||||
$settings['comment_ratings'] = filter_var($input['comment_ratings'] ?? false, FILTER_VALIDATE_BOOLEAN);
|
$settings['comment_ratings'] = filter_var($input['comment_ratings'] ?? false, FILTER_VALIDATE_BOOLEAN);
|
||||||
$settings['show_average'] = filter_var($input['show_average'] ?? true, FILTER_VALIDATE_BOOLEAN);
|
$view = $input['scale_view'] ?? null;
|
||||||
$settings['show_distribution'] = filter_var($input['show_distribution'] ?? true, FILTER_VALIDATE_BOOLEAN);
|
$settings['scale_view'] = in_array($view, Slide::SCALE_VIEWS, true) ? $view : Slide::SCALE_VIEW_BOTH;
|
||||||
break;
|
break;
|
||||||
case Slide::TYPE_QUIZ:
|
case Slide::TYPE_QUIZ:
|
||||||
$limit = (int)($input['time_limit'] ?? $settings['time_limit']);
|
$limit = (int)($input['time_limit'] ?? $settings['time_limit']);
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ use Cake\ORM\Locator\LocatorAwareTrait;
|
|||||||
* 'min', 'max', 'minLabel', 'maxLabel', 'private' (bool), 'stars' (bool: star rating, min = 1);
|
* 'min', 'max', 'minLabel', 'maxLabel', 'private' (bool), 'stars' (bool: star rating, min = 1);
|
||||||
* 'comments' => [['id', 'text', 'value' (int|null)]] oldest first (only with the comment field, else [];
|
* 'comments' => [['id', 'text', 'value' (int|null)]] oldest first (only with the comment field, else [];
|
||||||
* 'value' is null unless the setting comment_ratings is on;
|
* 'value' is null unless the setting comment_ratings is on;
|
||||||
* 'showAverage', 'showDistribution' (bool): parts shown in the presentation (settings
|
* 'view' (both|average|chart): parts shown in the presentation (setting scale_view,
|
||||||
* show_average/show_distribution, the data is always complete);
|
* the data is always complete);
|
||||||
* presentation only: participants never get results of scale slides, see PollStateService);
|
* presentation only: participants never get results of scale slides, see PollStateService);
|
||||||
* open/scale with 'private' (anonymous/internal feedback): contents are included for the
|
* open/scale with 'private' (anonymous/internal feedback): contents are included for the
|
||||||
* presenter/embed, which start with the results hidden and may show them on demand;
|
* presenter/embed, which start with the results hidden and may show them on demand;
|
||||||
@@ -337,8 +337,7 @@ class ResultsService
|
|||||||
return $this->scaleResults($slide) + [
|
return $this->scaleResults($slide) + [
|
||||||
'private' => $slide->isPrivate(),
|
'private' => $slide->isPrivate(),
|
||||||
'comments' => $comments,
|
'comments' => $comments,
|
||||||
'showAverage' => (bool)$slide->setting('show_average'),
|
'view' => $slide->setting('scale_view'),
|
||||||
'showDistribution' => (bool)$slide->setting('show_distribution'),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+11
-14
@@ -180,20 +180,17 @@ $optionsError = $slide->getError('options_text');
|
|||||||
'placeholder' => __('z. B. sehr'), 'value' => $settings['max_label'],
|
'placeholder' => __('z. B. sehr'), 'value' => $settings['max_label'],
|
||||||
]) ?>
|
]) ?>
|
||||||
</div>
|
</div>
|
||||||
<fieldset class="scale-parts">
|
<?= $this->Form->control('settings.scale_view', [
|
||||||
<legend><?= __('In der Präsentation zeigen') ?></legend>
|
'type' => 'select',
|
||||||
<?= $this->Form->control('settings.show_average', [
|
'label' => __('In der Präsentation zeigen'),
|
||||||
'type' => 'checkbox',
|
'options' => [
|
||||||
'label' => __('Durchschnitt'),
|
\App\Model\Entity\Slide::SCALE_VIEW_BOTH => __('Durchschnitt und Verteilung'),
|
||||||
'checked' => (bool)$settings['show_average'],
|
\App\Model\Entity\Slide::SCALE_VIEW_AVERAGE => __('Nur Durchschnitt'),
|
||||||
]) ?>
|
\App\Model\Entity\Slide::SCALE_VIEW_CHART => __('Nur Verteilung (Diagramm)'),
|
||||||
<?= $this->Form->control('settings.show_distribution', [
|
],
|
||||||
'type' => 'checkbox',
|
'value' => $settings['scale_view'],
|
||||||
'label' => __('Verteilung der Stimmen'),
|
]) ?>
|
||||||
'checked' => (bool)$settings['show_distribution'],
|
<p class="hint"><?= __('Die Auswertung in der Verwaltung und der PDF-Export enthalten immer beides.') ?></p>
|
||||||
]) ?>
|
|
||||||
<p class="hint"><?= __('Ohne beides zeigt die Präsentation nur die Anzahl der Bewertungen (und ggf. die Kommentare). Die Auswertung in der Verwaltung und der PDF-Export enthalten immer alles.') ?></p>
|
|
||||||
</fieldset>
|
|
||||||
<?= $this->Form->control('settings.comments', [
|
<?= $this->Form->control('settings.comments', [
|
||||||
'type' => 'checkbox',
|
'type' => 'checkbox',
|
||||||
'label' => __('Kommentarfeld anzeigen (Teilnehmende können ihre Bewertung optional begründen)'),
|
'label' => __('Kommentarfeld anzeigen (Teilnehmende können ihre Bewertung optional begründen)'),
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use Cake\TestSuite\IntegrationTestTrait;
|
|||||||
use Cake\TestSuite\TestCase;
|
use Cake\TestSuite\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scale slides can hide the average and/or the distribution in the presentation.
|
* Scale slides show average and distribution in the presentation, or only one of them (setting scale_view).
|
||||||
*/
|
*/
|
||||||
class ScalePartsTest extends TestCase
|
class ScalePartsTest extends TestCase
|
||||||
{
|
{
|
||||||
@@ -47,44 +47,39 @@ class ScalePartsTest extends TestCase
|
|||||||
|
|
||||||
public function testBothPartsAreShownByDefault(): void
|
public function testBothPartsAreShownByDefault(): void
|
||||||
{
|
{
|
||||||
$settings = SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, []);
|
$this->assertSame(Slide::SCALE_VIEW_BOTH, SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, [])['scale_view']);
|
||||||
$this->assertTrue($settings['show_average']);
|
$this->assertSame(Slide::SCALE_VIEW_BOTH, $this->presenterResults([])['view']);
|
||||||
$this->assertTrue($settings['show_distribution']);
|
|
||||||
|
|
||||||
$results = $this->presenterResults([]);
|
|
||||||
$this->assertTrue($results['showAverage']);
|
|
||||||
$this->assertTrue($results['showDistribution']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPartsCanBeHidden(): void
|
public function testUnknownViewFallsBackToBoth(): void
|
||||||
{
|
{
|
||||||
$settings = SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, ['show_average' => '0', 'show_distribution' => '0']);
|
$settings = SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, ['scale_view' => 'nothing']);
|
||||||
$this->assertFalse($settings['show_average']);
|
$this->assertSame(Slide::SCALE_VIEW_BOTH, $settings['scale_view']);
|
||||||
$this->assertFalse($settings['show_distribution']);
|
}
|
||||||
|
|
||||||
$results = $this->presenterResults(['show_average' => false, 'show_distribution' => false]);
|
public function testOnlyOnePartKeepsTheDataComplete(): void
|
||||||
$this->assertFalse($results['showAverage']);
|
{
|
||||||
$this->assertFalse($results['showDistribution']);
|
$results = $this->presenterResults(['scale_view' => Slide::SCALE_VIEW_CHART]);
|
||||||
// The data stays complete (evaluation, PDF), only the presentation hides it.
|
|
||||||
|
$this->assertSame(Slide::SCALE_VIEW_CHART, $results['view']);
|
||||||
|
// The data stays complete (evaluation, PDF), only the presentation hides a part.
|
||||||
$this->assertEqualsWithDelta(4.0, $results['average'], 0.001);
|
$this->assertEqualsWithDelta(4.0, $results['average'], 0.001);
|
||||||
$this->assertSame(1, $results['participants']);
|
$this->assertSame(1, $results['participants']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFormSavesParts(): void
|
public function testFormSavesView(): void
|
||||||
{
|
{
|
||||||
[$poll, $token] = $this->createPoll();
|
[$poll, $token] = $this->createPoll();
|
||||||
$this->get("/admin/$token/slides/add?type=scale");
|
$this->get("/admin/$token/slides/add?type=scale");
|
||||||
$this->assertResponseContains('name="settings[show_average]"');
|
$this->assertResponseContains('name="settings[scale_view]"');
|
||||||
$this->assertResponseContains('name="settings[show_distribution]"');
|
|
||||||
|
|
||||||
$this->post("/admin/$token/slides/add?type=scale", [
|
$this->post("/admin/$token/slides/add?type=scale", [
|
||||||
'type' => 'scale',
|
'type' => 'scale',
|
||||||
'question' => 'Wie fandest du den Abend?',
|
'question' => 'Wie fandest du den Abend?',
|
||||||
'settings' => ['scale_min' => '1', 'scale_max' => '5', 'show_average' => '1', 'show_distribution' => '0'],
|
'settings' => ['scale_min' => '1', 'scale_max' => '5', 'scale_view' => Slide::SCALE_VIEW_AVERAGE],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$slide = $this->slidesTable()->find()->where(['poll_id' => $poll->id])->firstOrFail();
|
$slide = $this->slidesTable()->find()->where(['poll_id' => $poll->id])->firstOrFail();
|
||||||
$this->assertTrue($slide->setting('show_average'));
|
$this->assertSame(Slide::SCALE_VIEW_AVERAGE, $slide->setting('scale_view'));
|
||||||
$this->assertFalse($slide->setting('show_distribution'));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+34
-41
@@ -309,8 +309,6 @@ textarea { resize: vertical; }
|
|||||||
.export-choice legend, .scale-style legend { font-weight: 600; margin-bottom: 4px; }
|
.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, .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 label:has(input:checked), .scale-style label:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
|
||||||
.scale-parts { border: 0; padding: 0; margin: 0 0 12px; }
|
|
||||||
.scale-parts legend { font-weight: 600; margin-bottom: 4px; }
|
|
||||||
.export-choice input, .scale-style input { width: 18px; height: 18px; margin: 2px 0 0; flex: none; accent-color: var(--primary); }
|
.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 strong { display: block; }
|
||||||
.export-choice .hint { display: block; margin: 2px 0 0; }
|
.export-choice .hint { display: block; margin: 2px 0 0; }
|
||||||
@@ -435,36 +433,37 @@ textarea { resize: vertical; }
|
|||||||
.bar--c4 .bar__fill { background: var(--c4); }
|
.bar--c4 .bar__fill { background: var(--c4); }
|
||||||
.bar--c5 .bar__fill { background: var(--c5); }
|
.bar--c5 .bar__fill { background: var(--c5); }
|
||||||
|
|
||||||
.columns { display: flex; gap: 8px; align-items: stretch; height: 180px; }
|
/* scale results: average and distribution (donut) side by side, one alone is centred */
|
||||||
.column { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
|
.scale-results__row { display: flex; flex-wrap: wrap; justify-content: center; align-items: stretch; gap: 16px; }
|
||||||
.column__count { font-size: .85rem; color: var(--muted); }
|
.scale-results__row > * { flex: 1 1 300px; min-width: 0; }
|
||||||
.column__track { flex: 1; width: 100%; display: flex; align-items: flex-end; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
|
.scale-results__row--single > * { flex: 0 1 640px; }
|
||||||
.column__fill { width: 100%; background: var(--c3); transition: height .6s ease; }
|
.average { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 16px 20px; background: var(--surface-2); border-radius: 14px; text-align: center; line-height: 1.1; }
|
||||||
.column__label { font-weight: 700; }
|
|
||||||
.column--avg .column__fill { background: var(--c1); }
|
|
||||||
.column--avg .column__label { color: var(--c1); }
|
|
||||||
.average { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 32px; margin: 0 0 20px; padding: 16px 20px; background: var(--surface-2); border-radius: 14px; }
|
|
||||||
.average__figure { display: flex; flex-direction: column; line-height: 1.1; }
|
|
||||||
.average__label { text-transform: uppercase; letter-spacing: .1em; font-size: .8rem; font-weight: 700; color: var(--muted); }
|
.average__label { text-transform: uppercase; letter-spacing: .1em; font-size: .8rem; font-weight: 700; color: var(--muted); }
|
||||||
.average__value { font-variant-numeric: tabular-nums; white-space: nowrap; }
|
.average__value { font-variant-numeric: tabular-nums; white-space: nowrap; }
|
||||||
.average__value strong { font-size: 3.2rem; font-weight: 800; color: var(--c1); }
|
.average__value strong { font-size: 4rem; font-weight: 800; color: var(--c1); }
|
||||||
.average__of { font-size: 1.4rem; font-weight: 600; color: var(--muted); }
|
.average__of { font-size: 1.6rem; font-weight: 600; color: var(--muted); }
|
||||||
.average__count { font-size: .85rem; color: var(--muted); }
|
.average__count { font-size: .85rem; color: var(--muted); }
|
||||||
.average__gauge { flex: 1 1 200px; }
|
.average__gauge { align-self: stretch; margin: 8px 0 4px; }
|
||||||
.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__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__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); }
|
.average__ends { display: flex; justify-content: space-between; gap: 12px; 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; max-width: 100%; font-size: 2.6rem; line-height: 1; letter-spacing: .08em; white-space: nowrap; }
|
||||||
.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__base { color: var(--star-empty); }
|
||||||
.star-meter__fill { position: absolute; top: 0; left: 0; overflow: hidden; color: var(--star); transition: width .6s ease; }
|
.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); }
|
.donut { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 16px 28px; padding: 16px 20px; background: var(--surface-2); border-radius: 14px; }
|
||||||
.stars-legend { margin: 10px 0 0; font-size: .85rem; color: var(--muted); }
|
.donut__chart { position: relative; flex: none; display: grid; place-items: center; width: 180px; aspect-ratio: 1; }
|
||||||
.average .stars-legend { flex-basis: 100%; margin: 0; }
|
/* the hole is masked out, so the card background shows through (gaps between slices are transparent too) */
|
||||||
/* parts hidden per slide (show_average/show_distribution): only the number of ratings remains */
|
.donut__ring { position: absolute; inset: 0; border-radius: 50%; -webkit-mask: radial-gradient(farthest-side, transparent 60%, #000 calc(60% + 1px)); mask: radial-gradient(farthest-side, transparent 60%, #000 calc(60% + 1px)); }
|
||||||
.scale-count { margin: 0 0 10px; font-size: .85rem; font-weight: 700; color: var(--muted); }
|
.donut__ring--empty { background: var(--border); }
|
||||||
.scale-total { display: flex; flex-direction: column; align-items: center; gap: .2em; padding: 16px 20px; background: var(--surface-2); border-radius: 14px; color: var(--muted); }
|
.donut__count { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; margin: 0; line-height: 1.1; color: var(--muted); font-size: .8rem; }
|
||||||
.scale-total strong { font-size: 3em; font-weight: 800; line-height: 1; color: var(--c1); font-variant-numeric: tabular-nums; }
|
.donut__count strong { font-size: 2.2em; font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; }
|
||||||
|
.donut__legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; min-width: 0; }
|
||||||
|
.donut__legend--wide { grid-template-columns: repeat(2, auto); column-gap: 24px; }
|
||||||
|
.donut__item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 10px; }
|
||||||
|
.donut__item.is-empty { opacity: .5; }
|
||||||
|
.donut__swatch { width: .9em; height: .9em; border-radius: 3px; }
|
||||||
|
.donut__label { font-weight: 600; overflow-wrap: anywhere; }
|
||||||
|
.donut__value { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
|
||||||
|
|
||||||
.cloud { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: .2em .6em; line-height: 1.15; padding: 8px; }
|
.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; }
|
.cloud__word { font-weight: 800; color: var(--c0); transition: font-size .6s ease; }
|
||||||
@@ -658,24 +657,18 @@ body.present {
|
|||||||
.stage--content .stage__description { color: var(--text); font-size: clamp(1.3rem, 2.6vw, 2.2rem); }
|
.stage--content .stage__description { color: var(--text); font-size: clamp(1.3rem, 2.6vw, 2.2rem); }
|
||||||
.stage__results { font-size: clamp(1rem, 1.8vw, 1.5rem); margin-top: 2vh; }
|
.stage__results { font-size: clamp(1rem, 1.8vw, 1.5rem); margin-top: 2vh; }
|
||||||
.stage .bar__track { height: 1.1em; }
|
.stage .bar__track { height: 1.1em; }
|
||||||
/* scale on stage: the average is the headline, the distribution a compact detail below */
|
/* scale on stage: big average next to a compact donut */
|
||||||
.stage .columns { height: 13vh; gap: .6vw; font-size: .75em; }
|
.stage .scale-results__row { gap: 2vw; }
|
||||||
.stage .average { padding: 2vh 2.5vw; gap: 1.5vh 4vw; margin-bottom: 1.5vh; background: rgba(var(--tint), .06); }
|
.stage .average, .stage .donut { padding: 2.5vh 2.5vw; background: rgba(var(--tint), .06); }
|
||||||
.stage .average__value strong { font-size: clamp(3.4rem, 7.5vw, 7rem); }
|
.stage .average__value strong { font-size: clamp(4rem, 9vw, 9rem); }
|
||||||
.stage .average__of { font-size: clamp(1.4rem, 2.8vw, 2.6rem); }
|
.stage .average__of { font-size: clamp(1.6rem, 3vw, 3rem); }
|
||||||
.stage .average__label, .stage .average__count, .stage .average__ends { font-size: clamp(.95rem, 1.5vw, 1.4rem); }
|
.stage .average__label, .stage .average__count, .stage .average__ends { font-size: clamp(.95rem, 1.5vw, 1.4rem); }
|
||||||
.stage .average__track { height: 1em; box-shadow: none; background: linear-gradient(90deg, var(--surface-2), var(--c1)); }
|
.stage .average__track { height: 1em; box-shadow: none; background: linear-gradient(90deg, var(--surface-2), var(--c1)); }
|
||||||
.stage .average__ends { margin-top: 6px; }
|
.stage .star-meter { font-size: clamp(2.4rem, 4.5vw, 5rem); }
|
||||||
.stage .star-meter { font-size: clamp(3rem, 7.5vw, 7rem); }
|
.stage .scale-results__row--single .star-meter { font-size: clamp(3rem, 7vw, 7rem); }
|
||||||
.stage .bars--stars { gap: .8vh; font-size: .75em; }
|
.stage .donut__chart { width: clamp(150px, 28vh, 340px); }
|
||||||
.stage .bars--stars .bar__track { height: .8em; }
|
.stage .donut__count { font-size: clamp(.85rem, 1.3vw, 1.2rem); }
|
||||||
.stage .stars-legend, .stage .scale-count, .stage .scale__labels { font-size: clamp(.85rem, 1.2vw, 1.1rem); }
|
.stage .donut__legend { font-size: clamp(.9rem, 1.4vw, 1.3rem); }
|
||||||
.stage .scale-total { padding: 3vh 2.5vw; background: rgba(var(--tint), .06); }
|
|
||||||
.stage .scale-total strong { font-size: clamp(3.4rem, 7.5vw, 7rem); }
|
|
||||||
/* average without distribution: room for an even bigger figure */
|
|
||||||
.stage .scale-results--average .average { padding: 4vh 3vw; }
|
|
||||||
.stage .scale-results--average .average__value strong { font-size: clamp(4.5rem, 10vw, 9rem); }
|
|
||||||
.stage .scale-results--average .star-meter { font-size: clamp(4rem, 10vw, 9rem); }
|
|
||||||
.stage .cloud { font-size: clamp(1.4rem, 2.6vw, 2.6rem); }
|
.stage .cloud { font-size: clamp(1.4rem, 2.6vw, 2.6rem); }
|
||||||
.stage .answers { columns: 340px; }
|
.stage .answers { columns: 340px; }
|
||||||
.stage .quiz-timer { font-size: clamp(3rem, 7vw, 6rem); }
|
.stage .quiz-timer { font-size: clamp(3rem, 7vw, 6rem); }
|
||||||
|
|||||||
+102
-102
@@ -539,29 +539,9 @@
|
|||||||
if (results.stars) {
|
if (results.stars) {
|
||||||
return Results.stars(results);
|
return Results.stars(results);
|
||||||
}
|
}
|
||||||
var max = Math.max.apply(null, results.buckets.map(function (b) { return b.count; }).concat([1]));
|
var total = Results.scaleTotal(results);
|
||||||
var total = results.buckets.reduce(function (sum, b) { return sum + b.count; }, 0);
|
|
||||||
var hasAverage = results.average !== null;
|
var hasAverage = results.average !== null;
|
||||||
var showAverage = results.showAverage !== false;
|
var averageText = Results.averageText(results);
|
||||||
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) }),
|
|
||||||
el('div', { class: 'column__track' }, [
|
|
||||||
el('div', { class: 'column__fill', style: 'height:' + (bucket.count / max * 100) + '%' })
|
|
||||||
]),
|
|
||||||
el('div', { class: 'column__label', text: String(bucket.value) })
|
|
||||||
]);
|
|
||||||
}));
|
|
||||||
var labels = el('div', { class: 'scale__labels' }, [
|
|
||||||
el('span', { text: results.minLabel || '' }),
|
|
||||||
el('span', { text: results.maxLabel || '' })
|
|
||||||
]);
|
|
||||||
var averageText = hasAverage
|
|
||||||
? Number(results.average).toLocaleString('de-DE', { minimumFractionDigits: 1, maximumFractionDigits: 1 })
|
|
||||||
: '–';
|
|
||||||
var span = results.max - results.min;
|
var span = results.max - results.min;
|
||||||
var position = hasAverage && span > 0 ? (results.average - results.min) / span * 100 : 50;
|
var position = hasAverage && span > 0 ? (results.average - results.min) / span * 100 : 50;
|
||||||
var gauge = el('div', {
|
var gauge = el('div', {
|
||||||
@@ -572,60 +552,26 @@
|
|||||||
el('div', { class: 'average__track' }, [
|
el('div', { class: 'average__track' }, [
|
||||||
hasAverage ? el('div', { class: 'average__marker', style: 'left:' + position + '%' }) : null
|
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('div', { class: 'average__ends' }, [
|
||||||
el('span', { text: results.min + (!showDistribution && results.minLabel ? ' · ' + results.minLabel : '') }),
|
el('span', { text: results.min + (results.minLabel ? ' · ' + results.minLabel : '') }),
|
||||||
el('span', { text: (!showDistribution && results.maxLabel ? results.maxLabel + ' · ' : '') + results.max })
|
el('span', { text: (results.maxLabel ? results.maxLabel + ' · ' : '') + results.max })
|
||||||
])
|
])
|
||||||
]);
|
]);
|
||||||
var average = el('div', { class: 'average' }, [
|
var average = Results.averageCard(results, total, ' / ' + results.max, gauge, '');
|
||||||
el('div', { class: 'average__figure' }, [
|
var donut = Results.donut(results, total, results.buckets, function (bucket) {
|
||||||
el('span', { class: 'average__label', text: 'Durchschnitt' }),
|
return String(bucket.value);
|
||||||
el('span', { class: 'average__value' }, [
|
}, 'var(--c1)');
|
||||||
el('strong', { text: averageText }),
|
|
||||||
el('span', { class: 'average__of', text: ' / ' + results.max })
|
|
||||||
]),
|
|
||||||
el('span', { class: 'average__count', text: total + (total === 1 ? ' Bewertung' : ' Bewertungen') })
|
|
||||||
]),
|
|
||||||
gauge
|
|
||||||
]);
|
|
||||||
var comments = results.comments && results.comments.length ? Comments.render(results.comments, String) : null;
|
var comments = results.comments && results.comments.length ? Comments.render(results.comments, String) : null;
|
||||||
return Results.scaleLayout(total, showAverage ? average : null, showDistribution ? [columns, labels] : null, comments);
|
return Results.scaleLayout(results, average, donut, comments);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Arranges the parts of a scale result according to showAverage/showDistribution:
|
* Star rating (scale with stars): average as partly filled stars, distribution as a
|
||||||
* without the average the number of ratings stays visible above the distribution,
|
* donut from most to fewest stars.
|
||||||
* 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]));
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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) {
|
stars: function (results) {
|
||||||
var max = Math.max.apply(null, results.buckets.map(function (b) { return b.count; }).concat([1]));
|
var total = Results.scaleTotal(results);
|
||||||
var total = results.buckets.reduce(function (sum, b) { return sum + b.count; }, 0);
|
var averageText = Results.averageText(results);
|
||||||
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 row = Array(results.max + 1).join('★');
|
||||||
var meter = el('div', {
|
var meter = el('div', {
|
||||||
class: 'star-meter',
|
class: 'star-meter',
|
||||||
@@ -637,50 +583,104 @@
|
|||||||
el('span', {
|
el('span', {
|
||||||
class: 'star-meter__fill',
|
class: 'star-meter__fill',
|
||||||
'aria-hidden': 'true',
|
'aria-hidden': 'true',
|
||||||
style: 'width:' + (hasAverage ? results.average / results.max * 100 : 0) + '%',
|
style: 'width:' + (results.average !== null ? results.average / results.max * 100 : 0) + '%',
|
||||||
text: row
|
text: row
|
||||||
})
|
})
|
||||||
]);
|
]);
|
||||||
var average = el('div', { class: 'average average--stars' }, [
|
var average = Results.averageCard(results, total, ' von ' + results.max, meter, ' average--stars');
|
||||||
el('div', { class: 'average__figure' }, [
|
var donut = Results.donut(results, total, results.buckets.slice().reverse(), function (bucket) {
|
||||||
el('span', { class: 'average__label', text: 'Durchschnitt' }),
|
return bucket.value + (bucket.value === 1 ? ' Stern' : ' Sterne');
|
||||||
el('span', { class: 'average__value' }, [
|
}, 'var(--star)');
|
||||||
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
|
var comments = results.comments && results.comments.length
|
||||||
? Comments.render(results.comments, function (value) {
|
? Comments.render(results.comments, function (value) {
|
||||||
return row.slice(0, value) + Array(results.max - value + 1).join('☆')
|
return row.slice(0, value) + Array(results.max - value + 1).join('☆')
|
||||||
+ ' (' + value + ' von ' + results.max + ')';
|
+ ' (' + value + ' von ' + results.max + ')';
|
||||||
})
|
})
|
||||||
: null;
|
: null;
|
||||||
var showDistribution = results.showDistribution !== false;
|
return Results.scaleLayout(results, average, donut, comments);
|
||||||
if (!showDistribution && labels) {
|
},
|
||||||
// Without the distribution the legend stays with the average.
|
|
||||||
average.appendChild(labels);
|
scaleTotal: function (results) {
|
||||||
}
|
return results.buckets.reduce(function (sum, b) { return sum + b.count; }, 0);
|
||||||
return Results.scaleLayout(
|
},
|
||||||
total,
|
|
||||||
results.showAverage !== false ? average : null,
|
averageText: function (results) {
|
||||||
showDistribution ? [bars, labels] : null,
|
return results.average !== null
|
||||||
comments
|
? Number(results.average).toLocaleString('de-DE', { minimumFractionDigits: 1, maximumFractionDigits: 1 })
|
||||||
);
|
: '–';
|
||||||
|
},
|
||||||
|
|
||||||
|
/** Card with the average as a big figure, its visual (gauge or stars) and the number of ratings. */
|
||||||
|
averageCard: function (results, total, ofText, visual, modifier) {
|
||||||
|
return el('div', { class: 'average' + modifier }, [
|
||||||
|
el('span', { class: 'average__label', text: 'Durchschnitt' }),
|
||||||
|
el('span', { class: 'average__value' }, [
|
||||||
|
el('strong', { text: Results.averageText(results) }),
|
||||||
|
el('span', { class: 'average__of', text: ofText })
|
||||||
|
]),
|
||||||
|
visual,
|
||||||
|
el('span', { class: 'average__count', text: total + (total === 1 ? ' Bewertung' : ' Bewertungen') })
|
||||||
|
]);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Distribution of a scale as a donut (conic-gradient) with a legend in the same order.
|
||||||
|
* The scale is ordinal, so the slices are shades of one colour (lowest value = palest);
|
||||||
|
* transparent gaps keep neighbouring shades apart. The labels of both ends go into the legend,
|
||||||
|
* the number of ratings into the hole.
|
||||||
|
*/
|
||||||
|
donut: function (results, total, buckets, label, color) {
|
||||||
|
var shade = function (bucket) {
|
||||||
|
var rank = (bucket.value - results.min) / Math.max(1, results.max - results.min);
|
||||||
|
return 'color-mix(in srgb, ' + color + ' ' + Math.round(30 + rank * 70) + '%, transparent)';
|
||||||
|
};
|
||||||
|
var used = buckets.filter(function (b) { return b.count > 0; }).length;
|
||||||
|
var gap = used > 1 ? 0.6 : 0;
|
||||||
|
var stops = [];
|
||||||
|
var at = 0;
|
||||||
|
buckets.forEach(function (bucket) {
|
||||||
|
if (!bucket.count) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var end = at + bucket.count / total * 100;
|
||||||
|
stops.push(shade(bucket) + ' ' + at + '% ' + (end - gap) + '%');
|
||||||
|
stops.push('transparent ' + (end - gap) + '% ' + end + '%');
|
||||||
|
at = end;
|
||||||
|
});
|
||||||
|
var countText = total === 1 ? 'Bewertung' : 'Bewertungen';
|
||||||
|
var ring = el('div', { class: 'donut__chart' }, [
|
||||||
|
el('div', {
|
||||||
|
class: 'donut__ring' + (total ? '' : ' donut__ring--empty'),
|
||||||
|
'aria-hidden': 'true',
|
||||||
|
style: total ? 'background:conic-gradient(' + stops.join(',') + ')' : ''
|
||||||
|
}),
|
||||||
|
el('p', { class: 'donut__count' }, [
|
||||||
|
el('strong', { text: String(total) }),
|
||||||
|
el('span', { text: countText })
|
||||||
|
])
|
||||||
|
]);
|
||||||
|
var ends = {};
|
||||||
|
ends[results.min] = results.minLabel;
|
||||||
|
ends[results.max] = results.maxLabel;
|
||||||
|
var legend = el('ul', { class: 'donut__legend' + (buckets.length > 6 ? ' donut__legend--wide' : '') }, buckets.map(function (bucket) {
|
||||||
|
return el('li', { class: 'donut__item' + (bucket.count ? '' : ' is-empty') }, [
|
||||||
|
el('span', { class: 'donut__swatch', 'aria-hidden': 'true', style: 'background:' + shade(bucket) }),
|
||||||
|
el('span', { class: 'donut__label', text: label(bucket) + (ends[bucket.value] ? ' – ' + ends[bucket.value] : '') }),
|
||||||
|
el('span', { class: 'donut__value', text: formatNumber(bucket.percent) + ' % (' + bucket.count + ')' })
|
||||||
|
]);
|
||||||
|
}));
|
||||||
|
return el('div', { class: 'donut' }, [ring, legend]);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Average and distribution side by side; with the slide setting scale_view (results.view:
|
||||||
|
* both|average|chart) only one of them is shown, centred.
|
||||||
|
*/
|
||||||
|
scaleLayout: function (results, average, donut, comments) {
|
||||||
|
var view = results.view || 'both';
|
||||||
|
var parts = [view !== 'chart' ? average : null, view !== 'average' ? donut : null];
|
||||||
|
var row = el('div', { class: 'scale-results__row' + (view === 'both' ? '' : ' scale-results__row--single') }, parts);
|
||||||
|
return el('div', { class: 'scale-results' }, [row, comments]);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user