|
7 | 7 |
|
8 | 8 | <script> |
9 | 9 | window.addEventListener('DOMContentLoaded', function() { |
10 | | -const inverseData = { |
| 10 | + |
| 11 | +function sbGetThemeColors() { |
| 12 | + var ls = localStorage.getItem('theme'); |
| 13 | + var hugo = document.body.classList.contains('dark-theme') ? 'dark' : 'light'; |
| 14 | + var dark = (ls || hugo) === 'dark'; |
| 15 | + return { font: dark ? '#cbd5e1' : '#475569', grid: dark ? '#334155' : '#f1f5f9' }; |
| 16 | +} |
| 17 | + |
| 18 | +var tc = sbGetThemeColors(); |
| 19 | +var inverseData = { |
11 | 20 | labels: ['GPT-5', 'Grok-4.1', 'GPT-4o', 'Perplexity', 'Tavily'], |
12 | 21 | score: [89.1, 83.4, 81.5, 78.5, 78.3], |
13 | 22 | overlap: [16.0, 29.7, 27.5, 40.0, 55.5] |
14 | 23 | }; |
15 | 24 |
|
16 | | -new Chart(document.getElementById('inverseChart'), { |
| 25 | +var inverseChart = new Chart(document.getElementById('inverseChart'), { |
17 | 26 | type: 'bar', |
18 | 27 | data: { |
19 | 28 | labels: inverseData.labels, |
20 | 29 | datasets: [ |
21 | | - { |
22 | | - label: 'SourceBench Score', |
23 | | - data: inverseData.score, |
24 | | - backgroundColor: '#10b981', |
25 | | - yAxisID: 'y', |
26 | | - borderRadius: 4, |
27 | | - barPercentage: 0.6 |
28 | | - }, |
29 | | - { |
30 | | - label: 'Google Overlap %', |
31 | | - data: inverseData.overlap, |
32 | | - backgroundColor: '#94a3b8', |
33 | | - yAxisID: 'y1', |
34 | | - borderRadius: 4, |
35 | | - barPercentage: 0.6 |
36 | | - } |
| 30 | + { label: 'SourceBench Score', data: inverseData.score, backgroundColor: '#10b981', yAxisID: 'y', borderRadius: 4, barPercentage: 0.6 }, |
| 31 | + { label: 'Google Overlap %', data: inverseData.overlap, backgroundColor: '#94a3b8', yAxisID: 'y1', borderRadius: 4, barPercentage: 0.6 } |
37 | 32 | ] |
38 | 33 | }, |
39 | 34 | options: { |
40 | 35 | responsive: true, |
41 | 36 | maintainAspectRatio: false, |
42 | 37 | interaction: { mode: 'index', intersect: false }, |
43 | | - plugins: { legend: { position: 'top', labels: { usePointStyle: true } } }, |
| 38 | + color: tc.font, |
| 39 | + plugins: { legend: { position: 'top', labels: { usePointStyle: true, color: tc.font } } }, |
44 | 40 | scales: { |
45 | | - x: { grid: { display: false } }, |
46 | | - y: { type: 'linear', display: true, position: 'left', min: 70, max: 95, title: { display: true, text: 'Weighted Score' } }, |
47 | | - y1: { type: 'linear', display: true, position: 'right', min: 0, max: 60, grid: { drawOnChartArea: false }, title: { display: true, text: 'Overlap %' } } |
| 41 | + x: { grid: { display: false }, ticks: { color: tc.font } }, |
| 42 | + y: { type: 'linear', display: true, position: 'left', min: 70, max: 95, grid: { color: tc.grid }, ticks: { color: tc.font }, title: { display: true, text: 'Weighted Score', color: tc.font } }, |
| 43 | + y1: { type: 'linear', display: true, position: 'right', min: 0, max: 60, grid: { drawOnChartArea: false }, ticks: { color: tc.font }, title: { display: true, text: 'Overlap %', color: tc.font } } |
48 | 44 | } |
49 | 45 | } |
50 | 46 | }); |
| 47 | + |
| 48 | +function sbUpdateInverseColors() { |
| 49 | + var c = sbGetThemeColors(); |
| 50 | + inverseChart.options.color = c.font; |
| 51 | + inverseChart.options.plugins.legend.labels.color = c.font; |
| 52 | + inverseChart.options.scales.x.ticks.color = c.font; |
| 53 | + inverseChart.options.scales.y.ticks.color = c.font; |
| 54 | + inverseChart.options.scales.y.grid.color = c.grid; |
| 55 | + inverseChart.options.scales.y.title.color = c.font; |
| 56 | + inverseChart.options.scales.y1.ticks.color = c.font; |
| 57 | + inverseChart.options.scales.y1.title.color = c.font; |
| 58 | + inverseChart.update(); |
| 59 | +} |
| 60 | + |
| 61 | +var toggleBtn = document.querySelector('.btn-light-dark'); |
| 62 | +if (toggleBtn) toggleBtn.addEventListener('click', function() { setTimeout(sbUpdateInverseColors, 50); }); |
| 63 | + |
51 | 64 | }); |
52 | 65 | </script> |
0 commit comments