Skip to content

Commit 1ba38ab

Browse files
authored
Merge pull request #51 from thebayesianconspiracy/fix-date-range
Change data range for line viz to dates
2 parents 99d7c74 + bdc8c31 commit 1ba38ab

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

viz/frontend/src/components/LineChartViz.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class LineChartViz extends React.Component<IProps, IState> {
5252
const negativeColorDark = "#340909";
5353

5454
const colourDark = this.isPositive ? positiveColorDark : negativeColorDark;
55+
let lastDayForViz = getLastDateToBeShownInViz(new Date());
56+
let startDayForViz = getStartDateToBeShownInViz(new Date());
5557

5658
const line = d3
5759
.line<{ date: Date; value: number }>()
@@ -84,12 +86,11 @@ class LineChartViz extends React.Component<IProps, IState> {
8486
d3.extent(chartData.getData(), (d) => new Date(d.date)) as [Date, Date]
8587
);
8688

87-
let lastDayForViz = getLastDateToBeShownInViz(new Date());
88-
let startDayForViz = getStartDateToBeShownInViz(new Date());
89-
const dateFormat = "%d-%m";
89+
const dateFormat = "%d-%m";
9090
const formatDate = (domainValue: Date | d3.NumberValue, index: number) =>
9191
timeFormat(dateFormat)(domainValue as Date);
9292

93+
chartData.setData(chartData.getData().filter(d => d.date >= startDayForViz && d.date <= lastDayForViz));
9394
x.domain([startDayForViz, lastDayForViz]);
9495
svg
9596
.append("g")

viz/frontend/src/models/date_data.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ class ArrayDateData {
8787
return this.data;
8888
}
8989

90+
// set data
91+
setData(data: Array<DateData>) {
92+
this.data = data;
93+
}
94+
9095
getValueInWeekOfDate(d: Date): { date: Date | null; value: number | null } {
9196
const targetWeekStart = this.getWeekStart(d);
9297

0 commit comments

Comments
 (0)