fix(analysis): pad comparison chart Y domain to 20% around the range

This commit is contained in:
Jose Selesan
2026-08-20 14:38:57 -03:00
parent 48c4c892cd
commit a6e95f0c05

View File

@@ -130,6 +130,24 @@ export function AnalysisPage({ currency }: { currency: string }) {
.map(({ date, ...rest }) => ({ date: formatShortDate(date), ...rest }));
}, [beloDaily, blueDaily, bnaDaily]);
const comparisonDomain = useMemo(() => {
if (comparisonData.length === 0) return [0, 0] as [number, number];
let min = Infinity;
let max = -Infinity;
for (const d of comparisonData) {
for (const key of ["BELO", "BLUE", "BNA"] as const) {
const value = d[key];
if (value === undefined) continue;
if (value < min) min = value;
if (value > max) max = value;
}
}
if (!Number.isFinite(min) || !Number.isFinite(max))
return [0, 0] as [number, number];
const range = max - min;
return [min - range * 0.2, max + range * 0.2] as [number, number];
}, [comparisonData]);
const { yDomain, minBuyValue, maxBuyValue, avgBuyValue } = useMemo(() => {
if (chartData.length === 0)
return {
@@ -480,6 +498,7 @@ export function AnalysisPage({ currency }: { currency: string }) {
`$${priceFormatter.format(v)}`
}
width={80}
domain={comparisonDomain}
/>
<Tooltip
formatter={(value: unknown, name: unknown) => [