From f74ed20e80f9f92a687d118e79b50e470cb6ff0f Mon Sep 17 00:00:00 2001 From: trotFunky Date: Wed, 24 Jul 2024 18:11:37 +0100 Subject: [PATCH] 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. --- static_files/vote_chart.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/static_files/vote_chart.js b/static_files/vote_chart.js index 8dd6869..09850d4 100644 --- a/static_files/vote_chart.js +++ b/static_files/vote_chart.js @@ -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