@@ -15,20 +15,32 @@ const ONE_DAY = 24 * 60 * 60 * 1000;
1515
1616export 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