Skip to content

Commit

Permalink
Change data range for line viz to dates
Browse files Browse the repository at this point in the history
  • Loading branch information
sam17 committed Jul 23, 2023
1 parent 99d7c74 commit bdc8c31
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 4 additions & 3 deletions viz/frontend/src/components/LineChartViz.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class LineChartViz extends React.Component<IProps, IState> {
const negativeColorDark = "#340909";

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

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

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

chartData.setData(chartData.getData().filter(d => d.date >= startDayForViz && d.date <= lastDayForViz));
x.domain([startDayForViz, lastDayForViz]);
svg
.append("g")
Expand Down
5 changes: 5 additions & 0 deletions viz/frontend/src/models/date_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ class ArrayDateData {
return this.data;
}

// set data
setData(data: Array<DateData>) {
this.data = data;
}

getValueInWeekOfDate(d: Date): { date: Date | null; value: number | null } {
const targetWeekStart = this.getWeekStart(d);

Expand Down

0 comments on commit bdc8c31

Please sign in to comment.