Give each value of the scale donut its own colour
Shades of one colour were too hard to tell apart on the projector. The slices now use the theme colours in a fixed order along the scale, mixed for scales with more values than colours. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2f6375cd6d
commit
14916f46fb
2 files changed
+17
-8
No files matched your search
+16
-7
@@ -560,7 +560,7 @@
|
||||
var average = Results.averageCard(results, total, ' / ' + results.max, gauge, '');
|
||||
var donut = Results.donut(results, total, results.buckets, function (bucket) {
|
||||
return String(bucket.value);
|
||||
}, 'var(--c1)');
|
||||
});
|
||||
var comments = results.comments && results.comments.length ? Comments.render(results.comments, String) : null;
|
||||
return Results.scaleLayout(results, average, donut, comments);
|
||||
},
|
||||
@@ -590,7 +590,7 @@
|
||||
var average = Results.averageCard(results, total, ' von ' + results.max, meter, ' average--stars');
|
||||
var donut = Results.donut(results, total, results.buckets.slice().reverse(), function (bucket) {
|
||||
return bucket.value + (bucket.value === 1 ? ' Stern' : ' Sterne');
|
||||
}, 'var(--star)');
|
||||
});
|
||||
var comments = results.comments && results.comments.length
|
||||
? Comments.render(results.comments, function (value) {
|
||||
return row.slice(0, value) + Array(results.max - value + 1).join('☆')
|
||||
@@ -625,17 +625,26 @@
|
||||
|
||||
/**
|
||||
* 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,
|
||||
* Each value gets its own colour (fixed order along the scale, see palette); small
|
||||
* transparent gaps separate the slices. The labels of both ends go into the legend,
|
||||
* the number of ratings into the hole.
|
||||
*/
|
||||
donut: function (results, total, buckets, label, color) {
|
||||
donut: function (results, total, buckets, label) {
|
||||
// Distinct theme colours in a fixed order along the scale; scales with more values
|
||||
// than colours get mixed colours in between.
|
||||
var palette = ['--c0', '--c4', '--c2', '--c3', '--c1', '--c5'];
|
||||
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 pos = rank * (palette.length - 1);
|
||||
var i = Math.floor(pos);
|
||||
var f = pos - i;
|
||||
if (f < 0.01 || i >= palette.length - 1) {
|
||||
return 'var(' + palette[Math.min(i, palette.length - 1)] + ')';
|
||||
}
|
||||
return 'color-mix(in oklab, var(' + palette[i] + ') ' + Math.round((1 - f) * 100) + '%, var(' + palette[i + 1] + '))';
|
||||
};
|
||||
var used = buckets.filter(function (b) { return b.count > 0; }).length;
|
||||
var gap = used > 1 ? 0.6 : 0;
|
||||
var gap = used > 1 ? 0.8 : 0;
|
||||
var stops = [];
|
||||
var at = 0;
|
||||
buckets.forEach(function (bucket) {
|
||||
|
||||
Reference in new issue
Block a user