@@ -23,8 +23,9 @@ import { Amount } from '../../../components/amount/amount';
23
23
import { PercentageDiff } from './percentage-diff' ;
24
24
import { Filters } from './filters' ;
25
25
import { getDarkmode } from '../../../components/darkmode/darkmode' ;
26
- import { TChartDisplay , TChartFiltersProps } from './types' ;
26
+ import { TChartFiltersProps } from './types' ;
27
27
import { DefaultCurrencyRotator } from '../../../components/rates/rates' ;
28
+ import { AppContext } from '../../../contexts/AppContext' ;
28
29
import styles from './chart.module.css' ;
29
30
30
31
export interface FormattedLineData extends LineData {
@@ -40,7 +41,6 @@ type ChartProps = {
40
41
} ;
41
42
42
43
type State = {
43
- display : TChartDisplay ;
44
44
source : 'daily' | 'hourly' ;
45
45
difference ?: number ;
46
46
diffSince ?: string ;
@@ -58,6 +58,8 @@ type FormattedData = {
58
58
[ key : number ] : string ;
59
59
}
60
60
class Chart extends Component < Props , State > {
61
+ static contextType = AppContext ;
62
+ context ! : React . ContextType < typeof AppContext > ;
61
63
private ref = createRef < HTMLDivElement > ( ) ;
62
64
private refToolTip = createRef < HTMLSpanElement > ( ) ;
63
65
private chart ?: IChartApi ;
@@ -81,7 +83,6 @@ class Chart extends Component<Props, State> {
81
83
} ;
82
84
83
85
public readonly state : State = {
84
- display : 'all' ,
85
86
source : 'daily' ,
86
87
toolTipVisible : false ,
87
88
toolTipValue : undefined ,
@@ -230,7 +231,7 @@ class Chart extends Component<Props, State> {
230
231
lineColor : 'rgba(94, 148, 192, 1)' ,
231
232
crosshairMarkerRadius : 6 ,
232
233
} ) ;
233
- switch ( this . state . display ) {
234
+ switch ( this . context . chartDisplay ) {
234
235
case 'week' :
235
236
this . displayWeek ( ) ;
236
237
break ;
@@ -241,8 +242,17 @@ class Chart extends Component<Props, State> {
241
242
this . displayYear ( ) ;
242
243
break ;
243
244
}
244
- this . lineSeries . setData ( this . props . data . chartDataDaily as ChartData ) ;
245
- this . setFormattedData ( this . props . data . chartDataDaily as ChartData ) ;
245
+ const isChartDisplayWeekly = this . context . chartDisplay === 'week' ;
246
+ this . lineSeries . setData (
247
+ ( isChartDisplayWeekly ?
248
+ this . props . data . chartDataHourly :
249
+ this . props . data . chartDataDaily ) as ChartData
250
+ ) ;
251
+ this . setFormattedData (
252
+ ( isChartDisplayWeekly ?
253
+ this . props . data . chartDataHourly :
254
+ this . props . data . chartDataDaily ) as ChartData
255
+ ) ;
246
256
this . chart . timeScale ( ) . subscribeVisibleLogicalRangeChange ( this . calculateChange ) ;
247
257
this . chart . subscribeCrosshairMove ( this . handleCrosshair ) ;
248
258
this . chart . timeScale ( ) . fitContent ( ) ;
@@ -312,8 +322,9 @@ class Chart extends Component<Props, State> {
312
322
this . setFormattedData ( this . props . data . chartDataHourly || [ ] ) ;
313
323
this . chart . applyOptions ( { timeScale : { timeVisible : true } } ) ;
314
324
}
325
+ this . context . setChartDisplay ( 'week' ) ;
315
326
this . setState (
316
- { display : 'week' , source : 'hourly' } ,
327
+ { source : 'hourly' } ,
317
328
( ) => {
318
329
if ( ! this . chart ) {
319
330
return ;
@@ -334,8 +345,9 @@ class Chart extends Component<Props, State> {
334
345
this . setFormattedData ( this . props . data . chartDataDaily || [ ] ) ;
335
346
this . chart . applyOptions ( { timeScale : { timeVisible : false } } ) ;
336
347
}
348
+ this . context . setChartDisplay ( 'month' ) ;
337
349
this . setState (
338
- { display : 'month' , source : 'daily' } ,
350
+ { source : 'daily' } ,
339
351
( ) => {
340
352
if ( ! this . chart ) {
341
353
return ;
@@ -356,8 +368,9 @@ class Chart extends Component<Props, State> {
356
368
this . setFormattedData ( this . props . data . chartDataDaily ) ;
357
369
this . chart . applyOptions ( { timeScale : { timeVisible : false } } ) ;
358
370
}
371
+ this . context . setChartDisplay ( 'year' ) ;
359
372
this . setState (
360
- { display : 'year' , source : 'daily' } ,
373
+ { source : 'daily' } ,
361
374
( ) => {
362
375
if ( ! this . chart ) {
363
376
return ;
@@ -378,8 +391,9 @@ class Chart extends Component<Props, State> {
378
391
this . setFormattedData ( this . props . data . chartDataDaily ) ;
379
392
this . chart . applyOptions ( { timeScale : { timeVisible : false } } ) ;
380
393
}
394
+ this . context . setChartDisplay ( 'all' ) ;
381
395
this . setState (
382
- { display : 'all' , source : 'daily' } ,
396
+ { source : 'daily' } ,
383
397
( ) => {
384
398
if ( ! this . chart ) {
385
399
return ;
@@ -498,7 +512,6 @@ class Chart extends Component<Props, State> {
498
512
const {
499
513
difference,
500
514
diffSince,
501
- display,
502
515
toolTipVisible,
503
516
toolTipValue,
504
517
toolTipTop,
@@ -513,7 +526,7 @@ class Chart extends Component<Props, State> {
513
526
const disableWeeklyFilters = ! hasHourlyData || chartDataMissing ;
514
527
const showMobileTotalValue = toolTipVisible && ! ! toolTipValue && isMobile ;
515
528
const chartFiltersProps = {
516
- display,
529
+ display : this . context . chartDisplay ,
517
530
disableFilters,
518
531
disableWeeklyFilters,
519
532
onDisplayWeek : this . displayWeek ,
0 commit comments