Skip to content

Commit

Permalink
fix issue in down-sampling data
Browse files Browse the repository at this point in the history
  • Loading branch information
anshuthopsee committed Dec 13, 2023
1 parent 385c060 commit 501e164
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/components/Chart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const Chart = () => {
const fundData = useSelector(getSelectedFundData);
const fundStatus = useSelector(getSelectedFundStatus);
const [navChange, setNavChange] = useState(0);

const [dataPeriod, setDataPeriod] = useState("");

const resizeObserver = new ResizeObserver((entries) => {
Expand All @@ -53,7 +52,7 @@ const Chart = () => {
.append('g')
.attr('transform', `translate(${margin.left}, ${margin.top})`);

const step = Math.ceil(fundData.length / 125);
let step = Math.ceil(fundData.length / 125);

const data = [];

Expand All @@ -63,6 +62,10 @@ const Chart = () => {
date: parseDate(d.date),
nav: Number(d.nav),
});

if (i === 0) break;

if (i - step < 0) step = i;
};

const xScale = d3.scaleTime()
Expand Down Expand Up @@ -383,6 +386,7 @@ const Chart = () => {
Number(fundData[fundData.length - 1].nav)
) * 100
);

setDataPeriod(`${formatDate(fundData[fundData.length - 1].date)} to ${formatDate(fundData[0].date)}`);
};
}, [fundData]);
Expand Down

0 comments on commit 501e164

Please sign in to comment.