vote_chart: Add custom colors

I didn't like the default colors, so introduce a new set of them and
set them to the datasets.
Do it after the sort, otherwise the colors wouldn't stay consistent.
This commit is contained in:
trotFunky 2024-07-24 18:11:37 +01:00
parent 4c89a0783d
commit f74ed20e80

View file

@ -1,5 +1,5 @@
const limit_ratio = 1.3
const colors = ['#b6b8fc', '#b6f4fc', '#fcb6cc', '#e0fcb6', '#fcdcb6', '#b6fcc8', '#f0b6fc']
async function main() {
const vote_response = await fetch(document.URL+"/votes");
if (!vote_response.ok) {
@ -23,8 +23,12 @@ async function main() {
return;
}
// Sort by label to maintain the same graph order, as it goes through a hash map in the backend.
datasets.sort((a, b) => a.label > b.label)
for (let i = 0; i < datasets.length; i++) {
datasets[i].backgroundColor = colors[i % colors.length]
}
const chart_canvas = document.getElementById("vote_chart")
let chart