1+ import { LeaseDuration } from 'types/state' ;
12import * as d3 from 'd3' ;
23import BaseEmitter from 'util/BaseEmitter' ;
34import { Batch } from 'store/models' ;
@@ -19,7 +20,6 @@ import type {
1920 Chart ,
2021 ChartEvents ,
2122} from './types' ;
22-
2323const TOP_HEIGHT_RATIO = 0.6 ;
2424const TOP_PADDING = 0.2 ;
2525const MARGIN = { top : 0 , right : 30 , bottom : 30 , left : 50 } ;
@@ -37,15 +37,17 @@ export default class D3Chart extends BaseEmitter<ChartEvents> implements Chart {
3737 dimensions : ChartDimensions ;
3838 scales : Scales ;
3939 data : BatchChartData [ ] ;
40+ market : LeaseDuration ;
4041
4142 palette : d3 . ScaleOrdinal < string , string , never > ;
4243 duration = ANIMATION_DURATION ;
4344
4445 constructor ( config : ChartConfig ) {
4546 super ( ) ;
4647
47- const { element, batches, outerWidth, outerHeight } = config ;
48+ const { element, batches, market , outerWidth, outerHeight } = config ;
4849 this . data = this . _convertData ( batches ) ;
50+ this . market = market ;
4951 this . dimensions = this . _getDimensions ( outerWidth , outerHeight , batches . length ) ;
5052 const { width, height, margin } = this . dimensions ;
5153
@@ -97,18 +99,24 @@ export default class D3Chart extends BaseEmitter<ChartEvents> implements Chart {
9799 new BlocksChart ( this ) ;
98100 new Zoomer ( this , config . fetchBatches ) ;
99101
100- this . update ( batches ) ;
102+ this . update ( batches , market ) ;
101103 this . resize ( outerWidth , outerHeight ) ;
102104 }
103105
104106 /**
105107 * Updates the chart with a new list of batches
106108 */
107- update = ( batches : Batch [ ] ) => {
109+ update = ( batches : Batch [ ] , market : number ) => {
108110 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+
111118 this . data = data ;
119+ this . market = market ;
112120
113121 const prev = this . dimensions ;
114122 this . dimensions = this . _getDimensions (
0 commit comments