diff --git a/src/components/HistoryChart.tsx b/src/components/HistoryChart.tsx index 47b2800..d86ba38 100644 --- a/src/components/HistoryChart.tsx +++ b/src/components/HistoryChart.tsx @@ -11,6 +11,9 @@ import { HistoryChartProps, ChartData, } from "../types/historyChart"; +import IconButton from "@mui/material/IconButton"; +import ChevronLeftIcon from "@mui/icons-material/ChevronLeft"; +import ChevronRightIcon from "@mui/icons-material/ChevronRight"; const formatDisplay = ( point: ChartDataPoint, @@ -99,6 +102,32 @@ export default function HistoryChart({ ) : 1; + const [startIndex, setStartIndex] = React.useState(0); + const visibleCount = activeDataKey == 'daily' ? 7 : 6; + const total = currentData.length; + + // clamp startIndex so we always show full 5 (when possible) + const clampedStartIndex = Math.min( + startIndex, + Math.max(total - visibleCount, 0) + ); + + const visibleData = currentData.slice( + clampedStartIndex, + clampedStartIndex + visibleCount + ); + + const canGoLeft = startIndex > 0; + const canGoRight = startIndex + visibleCount < currentData.length; + + const handlePrev = () => { + if (canGoLeft) setStartIndex((prev) => prev - visibleCount); + }; + + const handleNext = () => { + if (canGoRight) setStartIndex((prev) => prev + visibleCount); + }; + return ( {currentData.length > 0 ? ( - - {currentData.map((point) => { - const currentHeight = (point.amount / maxAmount) * 100; - const compareHeight = comparison - ? ((point.compareAmount || 0) / maxAmount) * 100 - : 0; - const labelHeight = Math.max(currentHeight, compareHeight); + - return ( - + {/* LEFT ARROW */} + {canGoLeft && ( + + + + )} + + {/* CHART */} + + {visibleData.map((point) => { + const currentHeight = (point.amount / maxAmount) * 100; + const compareHeight = comparison + ? ((point.compareAmount || 0) / maxAmount) * 100 + : 0; + const labelHeight = Math.max(currentHeight, compareHeight); + + return ( - - {formatDisplay(point, activeTab.toLowerCase(), comparison)} - - - {/* Compare */} - {comparison && ( - - )} - - {/* Spacer */} - - - {/* Current */} - - - - - - {formatLabel(point.id, activeDataKey)} - + + {formatDisplay(point, activeTab.toLowerCase(), comparison)} + - + )} + + {/* Spacer */} + + + {/* Current */} + + + + - {point.compareLabel - ? formatLabel(point.compareLabel, activeDataKey) - : "placeholder"} - + + {formatLabel(point.id, activeDataKey)} + + + + {point.compareLabel + ? formatLabel(point.compareLabel, activeDataKey) + : "placeholder"} + + - - ); - })} + ); + })} + + + {/* RIGHT ARROW */} + {canGoRight && ( + + + + )} ) : (