From bdc8c315f43c906a5d265e6931ea98004d2b8c78 Mon Sep 17 00:00:00 2001 From: soumyadeep Date: Sun, 23 Jul 2023 20:29:43 +0530 Subject: [PATCH] Change data range for line viz to dates --- viz/frontend/src/components/LineChartViz.tsx | 7 ++++--- viz/frontend/src/models/date_data.ts | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/viz/frontend/src/components/LineChartViz.tsx b/viz/frontend/src/components/LineChartViz.tsx index bfc0ab7..ab71e14 100644 --- a/viz/frontend/src/components/LineChartViz.tsx +++ b/viz/frontend/src/components/LineChartViz.tsx @@ -52,6 +52,8 @@ class LineChartViz extends React.Component { 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 }>() @@ -84,12 +86,11 @@ class LineChartViz extends React.Component { 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") diff --git a/viz/frontend/src/models/date_data.ts b/viz/frontend/src/models/date_data.ts index 6c63ebb..5b4fa48 100644 --- a/viz/frontend/src/models/date_data.ts +++ b/viz/frontend/src/models/date_data.ts @@ -87,6 +87,11 @@ class ArrayDateData { return this.data; } + // set data + setData(data: Array) { + this.data = data; + } + getValueInWeekOfDate(d: Date): { date: Date | null; value: number | null } { const targetWeekStart = this.getWeekStart(d);