From 6e9a9fa3503f071aaf27921da0ae75eb17f1e587 Mon Sep 17 00:00:00 2001 From: Manuel Rego Casasnovas Date: Thu, 30 Jan 2025 16:29:30 +0100 Subject: [PATCH 1/2] Add dark-mode support --- site/index.html | 51 +++++++++++++++++++++++++++++----------------- site/load-chart.js | 28 ++++++++++++++++++++----- 2 files changed, 55 insertions(+), 24 deletions(-) diff --git a/site/index.html b/site/index.html index 2fb218f..33cec69 100644 --- a/site/index.html +++ b/site/index.html @@ -10,22 +10,36 @@ font-size: 26px; } - html.embed { - background: #121619; - color: #f5f5f5; - } - html.embed * { - /* simple-grid has a *{color} rule */ - color: revert; - } - html.embed .google-visualization-tooltip { - background: #121619; - color: #f5f5f5; - } html.embed .hide-in-embed { display: none; } + .odd { + background-color: #f0efef; + } + + @media (prefers-color-scheme: dark) { + html * { + /* simple-grid has a *{color} rule */ + color: revert; + } + html { + background: #121619; + color: #f5f5f5; + } + html .google-visualization-tooltip { + background: #121619; + color: #f5f5f5; + } + .odd { + background-color: #25292c; + } + select { + background: #121619; + color: #f5f5f5; + } + } + #selected-area { padding: 10px; } @@ -34,10 +48,6 @@ padding: 10px; } - .odd { - background-color: #f0efef; - } - #score-table { margin-top: 30px; } @@ -70,9 +80,12 @@
- - + + + + +
diff --git a/site/load-chart.js b/site/load-chart.js index 359a918..6b96b13 100644 --- a/site/load-chart.js +++ b/site/load-chart.js @@ -5,6 +5,7 @@ google.charts.setOnLoadCallback(setupChart) const fetchData = fetch('scores.json') const embed = location.search === '?embed' +let dark_mode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches const periodRanges = { 'last month': 1, @@ -51,7 +52,7 @@ function setupChart () { fontSize: 16, legend: { position: 'top', - ...(embed + ...(dark_mode ? { textStyle: { color: '#f5f5f5' } } @@ -62,7 +63,7 @@ function setupChart () { viewWindow: { max: maxDate }, - ...(embed + ...(dark_mode ? { textStyle: { color: '#f5f5f5' } } @@ -74,7 +75,7 @@ function setupChart () { min: 0, max: 1 }, - ...(embed + ...(dark_mode ? { textStyle: { color: '#f5f5f5' } } @@ -91,7 +92,7 @@ function setupChart () { isHtml: true, trigger: 'both' }, - ...(embed + ...(dark_mode ? { backgroundColor: '#121619' } @@ -126,7 +127,7 @@ function setupChart () { table.addColumn('date', 'runOn') - options.series.push({ color: '#3366CC' }) + options.series.push({ color: dark_mode ? '#CC9933' : '#3366CC' }) table.addColumn('number', 'Servo') table.addColumn({ type: 'string', role: 'tooltip', p: { html: true } }) @@ -191,6 +192,23 @@ function setupChart () { area_dropdown.onchange = update_chart period_dropdown.onchange = update_chart + if (window.matchMedia) { + window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change',({ matches }) => { + dark_mode = matches + if (dark_mode) { + options.legend.textStyle = { color: '#f5f5f5' } + options.hAxis.textStyle = { color: '#f5f5f5' } + options.vAxis.textStyle = { color: '#f5f5f5' } + options.backgroundColor = '#121619' + } else { + options.legend.textStyle = { color: 'black' } + options.hAxis.textStyle = { color: 'black' } + options.vAxis.textStyle = { color: 'black' } + options.backgroundColor = 'white' + } + update_chart() + }) + } area_dropdown.value = scores.area_keys[0] period_dropdown.value = Object.keys(periodRanges)[4] update_table(scores) From e32bce7a874d72a02d102c04717f934d1a8ede2b Mon Sep 17 00:00:00 2001 From: Manuel Rego Date: Fri, 31 Jan 2025 07:41:35 +0100 Subject: [PATCH 2/2] Update site/load-chart.js Co-authored-by: Mukilan Thiyagarajan Signed-off-by: Manuel Rego --- site/load-chart.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/load-chart.js b/site/load-chart.js index 6b96b13..98c00a0 100644 --- a/site/load-chart.js +++ b/site/load-chart.js @@ -193,7 +193,7 @@ function setupChart () { area_dropdown.onchange = update_chart period_dropdown.onchange = update_chart if (window.matchMedia) { - window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change',({ matches }) => { + window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', ({ matches }) => { dark_mode = matches if (dark_mode) { options.legend.textStyle = { color: '#f5f5f5' }