fix allowance y-axis and chart styling

This commit is contained in:
Felix Schulze 2025-05-01 20:12:30 +02:00
parent 541c443efd
commit f96648e162

View File

@ -383,8 +383,8 @@ export default function FireCalculatorForm() {
<Slider <Slider
name="retirementAge" name="retirementAge"
value={[field.value]} value={[field.value]}
min={18} min={25}
max={form.getValues("lifeExpectancy")} max={75}
step={1} step={1}
onValueChange={(value) => { onValueChange={(value) => {
field.onChange(...value); field.onChange(...value);
@ -412,23 +412,14 @@ export default function FireCalculatorForm() {
Projected balance growth with your selected retirement age Projected balance growth with your selected retirement age
</CardDescription> </CardDescription>
</CardHeader> </CardHeader>
<CardContent> <CardContent className="px-2">
<ChartContainer <ChartContainer
className="aspect-auto h-80 w-full" className="aspect-auto h-80 w-full"
config={{ config={{}}
balance: {
label: "Balance",
color: "var(--chart-1)",
},
realBalance: {
label: "Real Balance",
color: "var(--chart-3)",
},
}}
> >
<AreaChart <AreaChart
data={result.yearlyData} data={result.yearlyData}
margin={{ top: 20, right: 30, left: 20, bottom: 20 }} margin={{ top: 10, right: 20, left: 20, bottom: 10 }}
> >
<CartesianGrid strokeDasharray="3 3" /> <CartesianGrid strokeDasharray="3 3" />
<XAxis <XAxis
@ -439,7 +430,10 @@ export default function FireCalculatorForm() {
offset: -10, offset: -10,
}} }}
/> />
{/* Left Y axis */}
<YAxis <YAxis
yAxisId={"left"}
orientation="left"
tickFormatter={(value: number) => { tickFormatter={(value: number) => {
if (value >= 1000000) { if (value >= 1000000) {
return `${(value / 1000000).toPrecision(3)}M`; return `${(value / 1000000).toPrecision(3)}M`;
@ -452,7 +446,21 @@ export default function FireCalculatorForm() {
} }
return value.toString(); return value.toString();
}} }}
width={25} width={30}
/>
{/* Right Y axis */}
<YAxis
yAxisId="right"
orientation="right"
tickFormatter={(value: number) => {
if (value >= 1000000) {
return `${(value / 1000000).toPrecision(3)}M`;
} else if (value >= 1000) {
return `${(value / 1000).toPrecision(3)}K`;
}
return value.toString();
}}
width={30}
/> />
<ChartTooltip content={tooltipRenderer} /> <ChartTooltip content={tooltipRenderer} />
<defs> <defs>
@ -474,24 +482,6 @@ export default function FireCalculatorForm() {
stopOpacity={0.1} stopOpacity={0.1}
/> />
</linearGradient> </linearGradient>
<linearGradient
id="fillAllowance"
x1="0"
y1="0"
x2="0"
y2="1"
>
<stop
offset="5%"
stopColor="var(--chart-2)"
stopOpacity={0.8}
/>
<stop
offset="95%"
stopColor="var(--chart-2)"
stopOpacity={0.1}
/>
</linearGradient>
</defs> </defs>
<Area <Area
type="monotone" type="monotone"
@ -499,17 +489,20 @@ export default function FireCalculatorForm() {
name="balance" name="balance"
stroke="var(--chart-1)" stroke="var(--chart-1)"
fill="url(#fillBalance)" fill="url(#fillBalance)"
fillOpacity={0.4} fillOpacity={0.9}
activeDot={{ r: 6 }} activeDot={{ r: 6 }}
yAxisId={"left"}
stackId={"a"}
/> />
<Area <Area
type="monotone" type="monotone"
dataKey="monthlyAllowance" dataKey="monthlyAllowance"
name="allowance" name="allowance"
stroke="var(--chart-2)" stroke="var(--chart-2)"
fill="url(#fillAllowance)" fill="none"
fillOpacity={0.4}
activeDot={{ r: 6 }} activeDot={{ r: 6 }}
yAxisId="right"
stackId={"a"}
/> />
{result.fireNumber && ( {result.fireNumber && (
<ReferenceLine <ReferenceLine
@ -521,6 +514,7 @@ export default function FireCalculatorForm() {
value: "FIRE Number", value: "FIRE Number",
position: "insideBottomRight", position: "insideBottomRight",
}} }}
yAxisId={"left"}
/> />
)} )}
<ReferenceLine <ReferenceLine
@ -535,6 +529,7 @@ export default function FireCalculatorForm() {
value: "Retirement", value: "Retirement",
position: "insideTopRight", position: "insideTopRight",
}} }}
yAxisId={"left"}
/> />
</AreaChart> </AreaChart>
</ChartContainer> </ChartContainer>