1
+ import { LeaseDuration } from 'types/state' ;
1
2
import * as d3 from 'd3' ;
2
3
import BaseEmitter from 'util/BaseEmitter' ;
3
4
import { Batch } from 'store/models' ;
@@ -19,7 +20,6 @@ import type {
19
20
Chart ,
20
21
ChartEvents ,
21
22
} from './types' ;
22
-
23
23
const TOP_HEIGHT_RATIO = 0.6 ;
24
24
const TOP_PADDING = 0.2 ;
25
25
const MARGIN = { top : 0 , right : 30 , bottom : 30 , left : 50 } ;
@@ -37,15 +37,17 @@ export default class D3Chart extends BaseEmitter<ChartEvents> implements Chart {
37
37
dimensions : ChartDimensions ;
38
38
scales : Scales ;
39
39
data : BatchChartData [ ] ;
40
+ market : LeaseDuration ;
40
41
41
42
palette : d3 . ScaleOrdinal < string , string , never > ;
42
43
duration = ANIMATION_DURATION ;
43
44
44
45
constructor ( config : ChartConfig ) {
45
46
super ( ) ;
46
47
47
- const { element, batches, outerWidth, outerHeight } = config ;
48
+ const { element, batches, market , outerWidth, outerHeight } = config ;
48
49
this . data = this . _convertData ( batches ) ;
50
+ this . market = market ;
49
51
this . dimensions = this . _getDimensions ( outerWidth , outerHeight , batches . length ) ;
50
52
const { width, height, margin } = this . dimensions ;
51
53
@@ -97,18 +99,24 @@ export default class D3Chart extends BaseEmitter<ChartEvents> implements Chart {
97
99
new BlocksChart ( this ) ;
98
100
new Zoomer ( this , config . fetchBatches ) ;
99
101
100
- this . update ( batches ) ;
102
+ this . update ( batches , market ) ;
101
103
this . resize ( outerWidth , outerHeight ) ;
102
104
}
103
105
104
106
/**
105
107
* Updates the chart with a new list of batches
106
108
*/
107
- update = ( batches : Batch [ ] ) => {
109
+ update = ( batches : Batch [ ] , market : number ) => {
108
110
const data = this . _convertData ( batches ) ;
109
- // determine if we are loading batches from the past
110
- const pastData = this . _hasLoadedPastData ( this . data , data ) ;
111
+ // determine if we are loading batches from the past. if the market changes, then
112
+ // we are not loading new data, just a different subset of batches
113
+ let pastData = this . _hasLoadedPastData ( this . data , data ) ;
114
+ // if the market changes, then we are not loading new data, just a different
115
+ // subset of batches
116
+ if ( this . market !== market ) pastData = false ;
117
+
111
118
this . data = data ;
119
+ this . market = market ;
112
120
113
121
const prev = this . dimensions ;
114
122
this . dimensions = this . _getDimensions (
0 commit comments