Skip to content

Commit bc801d3

Browse files
committed
components/download-graph: Adjust font and border colors for color scheme
1 parent 1336b7c commit bc801d3

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

app/components/download-graph.hbs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<canvas
1212
{{did-insert this.createChart}}
1313
{{did-update this.updateChart @data}}
14+
{{did-update this.updateColorScheme this.colorScheme.resolvedScheme}}
1415
{{did-update this.updateStacked @stacked}}
1516
{{will-destroy this.destroyChart}}
1617
/>

app/components/download-graph.js

+34-2
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,32 @@ const ONE_DAY = 24 * 60 * 60 * 1000;
1515

1616
export default class DownloadGraph extends Component {
1717
@service chartjs;
18+
@service colorScheme;
1819

1920
@action loadChartJs() {
2021
waitForPromise(this.chartjs.loadTask.perform()).catch(() => {
2122
// Ignore Promise rejections. We'll handle them through the derived state properties.
2223
});
2324
}
2425

26+
get fontColor() {
27+
return this.colorScheme.isDark ? '#ADBABD' : '#666';
28+
}
29+
30+
get borderColor() {
31+
return this.colorScheme.isDark ? 'rgba(255, 255, 255, 0.1)' : 'rgba(0, 0, 0, 0.1)';
32+
}
33+
2534
@action createChart(element) {
2635
let Chart = this.chartjs.loadTask.lastSuccessful.value;
2736

37+
let { fontColor: color, borderColor } = this;
38+
2839
this.chart = new Chart(element, {
2940
type: 'line',
3041
data: this.data,
3142
options: {
43+
color,
3244
maintainAspectRatio: false,
3345
layout: {
3446
padding: 10,
@@ -37,9 +49,15 @@ export default class DownloadGraph extends Component {
3749
x: {
3850
type: 'time',
3951
time: { tooltipFormat: 'MMM d', unit: 'day' },
40-
ticks: { maxTicksLimit: 13 },
52+
ticks: { maxTicksLimit: 13, color },
53+
grid: { color: borderColor },
54+
},
55+
y: {
56+
beginAtZero: true,
57+
stacked: true,
58+
ticks: { precision: 0, color },
59+
grid: { color: borderColor },
4160
},
42-
y: { beginAtZero: true, stacked: true, ticks: { precision: 0 } },
4361
},
4462
interaction: {
4563
mode: 'index',
@@ -50,6 +68,20 @@ export default class DownloadGraph extends Component {
5068
});
5169
}
5270

71+
@action updateColorScheme() {
72+
let { chart } = this;
73+
74+
if (chart) {
75+
let { fontColor, borderColor } = this;
76+
chart.options.color = fontColor;
77+
chart.options.scales.x.ticks.color = fontColor;
78+
chart.options.scales.x.grid.color = borderColor;
79+
chart.options.scales.y.ticks.color = fontColor;
80+
chart.options.scales.y.grid.color = borderColor;
81+
chart.update();
82+
}
83+
}
84+
5385
@action updateChart() {
5486
let { chart } = this;
5587

0 commit comments

Comments
 (0)