@@ -30,31 +30,71 @@ document.addEventListener("DOMContentLoaded", async function () {
3030 // Build a debug table of ballots (optional)
3131 buildVotesTable ( rawBallots , choices ) ;
3232
33+ // Helper function to detect dark mode
34+ function isDarkMode ( ) {
35+ return (
36+ window . matchMedia &&
37+ window . matchMedia ( "(prefers-color-scheme: dark)" ) . matches
38+ ) ;
39+ }
40+
41+ // Get chart colors based on dark mode
42+ function getChartColors ( ) {
43+ if ( isDarkMode ( ) ) {
44+ // Dark mode colors - brighter and more saturated
45+ return {
46+ backgroundColor : [
47+ "rgba(75, 192, 192, 0.8)" ,
48+ "rgba(255, 99, 132, 0.8)" ,
49+ "rgba(255, 206, 86, 0.8)" ,
50+ "rgba(54, 162, 235, 0.8)" ,
51+ "rgba(153, 102, 255, 0.8)" ,
52+ "rgba(255, 159, 64, 0.8)" ,
53+ ] ,
54+ borderColor : [
55+ "rgba(75, 192, 192, 1)" ,
56+ "rgba(255, 99, 132, 1)" ,
57+ "rgba(255, 206, 86, 1)" ,
58+ "rgba(54, 162, 235, 1)" ,
59+ "rgba(153, 102, 255, 1)" ,
60+ "rgba(255, 159, 64, 1)" ,
61+ ] ,
62+ } ;
63+ } else {
64+ // Light mode colors
65+ return {
66+ backgroundColor : [
67+ "rgba(75, 192, 192, 0.6)" ,
68+ "rgba(255, 99, 132, 0.6)" ,
69+ "rgba(255, 206, 86, 0.6)" ,
70+ "rgba(54, 162, 235, 0.6)" ,
71+ "rgba(153, 102, 255, 0.6)" ,
72+ "rgba(255, 159, 64, 0.6)" ,
73+ ] ,
74+ borderColor : [
75+ "rgba(75, 192, 192, 1)" ,
76+ "rgba(255, 99, 132, 1)" ,
77+ "rgba(255, 206, 86, 1)" ,
78+ "rgba(54, 162, 235, 1)" ,
79+ "rgba(153, 102, 255, 1)" ,
80+ "rgba(255, 159, 64, 1)" ,
81+ ] ,
82+ } ;
83+ }
84+ }
85+
3386 // 2. Create Chart.js pie chart
3487 const ctx = document . getElementById ( "spavChart" ) . getContext ( "2d" ) ;
88+ const chartColors = getChartColors ( ) ;
3589 const spavChart = new Chart ( ctx , {
3690 type : "pie" ,
3791 data : {
3892 labels : choices . map ( ( c ) => c . choice_text ) ,
3993 datasets : [
4094 {
4195 data : choices . map ( ( ) => 0 ) ,
42- backgroundColor : [
43- "rgba(75, 192, 192, 0.6)" ,
44- "rgba(255, 99, 132, 0.6)" ,
45- "rgba(255, 206, 86, 0.6)" ,
46- "rgba(54, 162, 235, 0.6)" ,
47- "rgba(153, 102, 255, 0.6)" ,
48- "rgba(255, 159, 64, 0.6)" ,
49- ] ,
50- borderColor : [
51- "rgba(75, 192, 192, 1)" ,
52- "rgba(255, 99, 132, 1)" ,
53- "rgba(255, 206, 86, 1)" ,
54- "rgba(54, 162, 235, 1)" ,
55- "rgba(153, 102, 255, 1)" ,
56- "rgba(255, 159, 64, 1)" ,
57- ] ,
96+ backgroundColor : chartColors . backgroundColor ,
97+ borderColor : chartColors . borderColor ,
5898 borderWidth : 1 ,
5999 } ,
60100 ] ,
@@ -64,11 +104,28 @@ document.addEventListener("DOMContentLoaded", async function () {
64104 plugins : {
65105 legend : {
66106 position : "bottom" ,
107+ labels : {
108+ color : isDarkMode ( ) ? "#e0e0e0" : "#000000" ,
109+ } ,
67110 } ,
68111 } ,
69112 } ,
70113 } ) ;
71114
115+ // Listen for dark mode changes and update chart colors
116+ if ( window . matchMedia ) {
117+ const darkModeQuery = window . matchMedia ( "(prefers-color-scheme: dark)" ) ;
118+ darkModeQuery . addEventListener ( "change" , ( e ) => {
119+ const newColors = getChartColors ( ) ;
120+ spavChart . data . datasets [ 0 ] . backgroundColor = newColors . backgroundColor ;
121+ spavChart . data . datasets [ 0 ] . borderColor = newColors . borderColor ;
122+ spavChart . options . plugins . legend . labels . color = e . matches
123+ ? "#e0e0e0"
124+ : "#000000" ;
125+ spavChart . update ( ) ;
126+ } ) ;
127+ }
128+
72129 // 3. SPAV allowing multiple seats, now with a debug log
73130 function spav ( choices , ballots , seats ) {
74131 const debugLines = [ ] ;
0 commit comments