Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix tooltip issue on chart box in home page #35

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 35 additions & 28 deletions components/home/ChartBox/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const Chart = (props: ChartProps) => {
const currentPeriodKey = `Current ${currentFilter ? currentFilter.name : ''}`;
const prevPeriodKey = `Prev ${currentFilter ? currentFilter.name : ''}`;
// Update the date property of each item in prevWeek with the corresponding item from deepCopyCurrentWeek
if (prevPeriod && currentPeriod)
if (prevPeriod && prevPeriod.length > 0 && currentPeriod)
prevPeriod.forEach((item, index) => {
prevPeriod[index].date = currentPeriod[index]?.date;
});
Expand Down Expand Up @@ -98,13 +98,15 @@ const Chart = (props: ChartProps) => {
{days !== 90 && currentPeriod && prevPeriod && (
<>
{/* previous chart only for week and month */}
<AnimatedLineSeries
curve={curveMonotoneX}
dataKey={prevPeriodKey}
data={prevPeriod}
xAccessor={(d) => d.date}
yAccessor={(d) => d.count}
/>
{prevPeriod.length > 0 && (
<AnimatedLineSeries
curve={curveMonotoneX}
dataKey={prevPeriodKey}
data={prevPeriod}
xAccessor={(d) => d.date}
yAccessor={(d) => d.count}
/>
)}

{/* current chart only for week and month */}
<AreaSeries
Expand Down Expand Up @@ -159,26 +161,31 @@ const Chart = (props: ChartProps) => {
</span>
{currentPeriod && prevPeriod ? (
<div>
<div className="flex items-center mr-20">
<span
className={`w-[0.25rem] md:w-[0.375rem] h-[0.25rem] md:h-[0.375rem] mr-5 rounded-full bg-secondary-500`}></span>
Current:
<span className="text-baseForeground pl-1">
{AmountConverter(
tooltipData.datumByKey[currentPeriodKey].datum.count,
)}
</span>
</div>
<div className="flex items-center">
<span
className={`w-[0.25rem] md:w-[0.375rem] h-[0.25rem] md:h-[0.375rem] mr-5 rounded-full bg-primary-600`}></span>
Previous:
<span className="text-baseForeground pl-1">
{AmountConverter(
tooltipData.datumByKey[prevPeriodKey].datum.count,
)}
</span>
</div>
{currentPeriod && (
<div className="flex items-center mr-20">
<span
className={`w-[0.25rem] md:w-[0.375rem] h-[0.25rem] md:h-[0.375rem] mr-5 rounded-full bg-secondary-500`}></span>
Current:
<span className="text-baseForeground pl-1">
{AmountConverter(
tooltipData.datumByKey[currentPeriodKey].datum
.count,
)}
</span>
</div>
)}
{prevPeriod.length > 0 && (
<div className="flex items-center">
<span
className={`w-[0.25rem] md:w-[0.375rem] h-[0.25rem] md:h-[0.375rem] mr-5 rounded-full bg-primary-600`}></span>
Previous:
<span className="text-baseForeground pl-1">
{AmountConverter(
tooltipData.datumByKey[prevPeriodKey].datum.count,
)}
</span>
</div>
)}
</div>
) : (
<div className="flex items-center">
Expand Down
Loading