Skip to content

Commit b4493ac

Browse files
committed
pool+batches: fix chart animation when toggling lease durations
1 parent 70cf1fe commit b4493ac

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

app/src/components/pool/batches/BatchChart.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,14 @@ const BatchChart: React.FC = () => {
7575
outerWidth: width,
7676
outerHeight: height,
7777
batches: batchStore.sortedBatches,
78+
market: batchStore.selectedLeaseDuration,
7879
fetchBatches: batchStore.fetchBatches,
7980
};
8081
setChart(new D3Chart(config));
8182
} else {
82-
chart.update(batchStore.sortedBatches);
83+
chart.update(batchStore.sortedBatches, batchStore.selectedLeaseDuration);
8384
}
84-
}, [chartArea.current, batchStore.sortedBatches]);
85+
}, [chartArea.current, batchStore.sortedBatches, batchStore.selectedLeaseDuration]);
8586

8687
useEffect(() => {
8788
// resize the chart when the dimensions of the wrapper change

app/src/components/pool/batches/chart/D3Chart.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { LeaseDuration } from 'types/state';
12
import * as d3 from 'd3';
23
import BaseEmitter from 'util/BaseEmitter';
34
import { Batch } from 'store/models';
@@ -19,7 +20,6 @@ import type {
1920
Chart,
2021
ChartEvents,
2122
} from './types';
22-
2323
const TOP_HEIGHT_RATIO = 0.6;
2424
const TOP_PADDING = 0.2;
2525
const 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(

app/src/components/pool/batches/chart/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Emitter } from 'types/emitter';
2+
import { LeaseDuration } from 'types/state';
23
import { Batch } from 'store/models';
34
import { BatchDelta } from 'store/models/batch';
45
import { Scales } from './';
@@ -28,6 +29,7 @@ interface BaseChart {
2829
dimensions: ChartDimensions;
2930
scales: Scales;
3031
data: BatchChartData[];
32+
market: LeaseDuration;
3133

3234
palette: d3.ScaleOrdinal<string, string, never>;
3335
duration: number;
@@ -40,6 +42,7 @@ export interface ChartConfig {
4042
outerWidth: number;
4143
outerHeight: number;
4244
batches: Batch[];
45+
market: LeaseDuration;
4346
fetchBatches: () => void;
4447
}
4548

0 commit comments

Comments
 (0)