Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ gcpdeploy.md
deploy.sh
todo.md
.agent/*
.github/copilot-instructions.md

.agent/*

Expand Down
14 changes: 12 additions & 2 deletions src/components/features/LongevityAnalysis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React from 'react';
import { LongevityResult, UserProfile } from '../../types';
import { AreaChart, Area, XAxis, YAxis, CartesianGrid, Tooltip as RechartsTooltip, ResponsiveContainer, BarChart, Bar, Legend } from 'recharts';
import Tooltip from '../common/Tooltip';
import { AlertTriangle, CheckCircle, HelpCircle } from 'lucide-react';
import { AlertTriangle, CheckCircle, HelpCircle, Download } from 'lucide-react';
import { exportLongevityToCsv } from '../../utils/exportCsv';

interface LongevityAnalysisProps {
longevity: LongevityResult;
Expand Down Expand Up @@ -72,7 +73,16 @@ const LongevityAnalysis: React.FC<LongevityAnalysisProps> = ({ longevity, profil

{/* Chart */}
<div className="bg-white dark:bg-slate-900 p-6 rounded-xl border border-slate-200 dark:border-slate-800 shadow-sm min-h-[400px] transition-colors">
<h3 className="text-lg font-bold text-slate-800 dark:text-white mb-4">Portfolio Balance Projection</h3>
<div className="flex justify-between items-center mb-4">
<h3 className="text-lg font-bold text-slate-800 dark:text-white">Portfolio Balance Projection</h3>
<button
onClick={() => exportLongevityToCsv(projection)}
className="flex items-center gap-2 px-3 py-1.5 text-sm font-medium text-slate-700 bg-white border border-slate-300 rounded-lg hover:bg-slate-50 focus:outline-none focus:ring-2 focus:ring-slate-500 focus:border-slate-500 dark:bg-slate-800 dark:text-slate-200 dark:border-slate-600 dark:hover:bg-slate-700 transition-colors"
>
<Download className="w-4 h-4" />
Export to CSV
</button>
</div>
<div className="h-[300px] w-full">
<ResponsiveContainer width="100%" height="100%">
<AreaChart
Expand Down
66 changes: 66 additions & 0 deletions src/utils/exportCsv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { YearProjection } from '../types';

export const exportLongevityToCsv = (projection: YearProjection[]) => {
if (!projection || projection.length === 0) return;

const headers = [
'Age',
'Year',
'Total Assets',
'Brokerage Balance',
'Trad IRA Balance',
'Roth IRA Balance',
'HSA Balance',
'Total Withdrawal',
'Brokerage Withdrawal',
'Trad IRA Withdrawal',
'Roth IRA Withdrawal',
'HSA Withdrawal',
'Early Withdrawal Penalty',
'RMD Amount',
'Social Security Income',
'Pension Income',
'Dividend Income',
'Estimated Tax',
'Effective Tax Rate (%)'
];

const rows = projection.map(data => {
// Math.round to match the displayed values which are generally rounded for ease of reading
return [
data.age,
data.year,
Math.round(data.totalAssets),
Math.round(data.brokerage),
Math.round(data.traditionalIRA),
Math.round(data.rothIRA),
Math.round(data.hsa),
Math.round(data.withdrawal),
Math.round(data.withdrawalBrokerage),
Math.round(data.withdrawalTrad),
Math.round(data.withdrawalRoth),
Math.round(data.withdrawalHSA),
Math.round(data.earlyWithdrawalPenalty || 0),
Math.round(data.rmdAmount || 0),
Math.round(data.socialSecurityIncome || 0),
Math.round(data.pensionIncome || 0),
Math.round(data.dividendIncome || 0),
Math.round(data.estimatedTax || 0),
data.effectiveTaxRate ? (data.effectiveTaxRate * 100).toFixed(2) : '0.00'
];
});

const csvContent = [
headers.join(','),
...rows.map(row => row.join(','))
].join('\n');

const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.setAttribute('href', url);
link.setAttribute('download', 'fiscal_sunset_longevity_projection.csv');
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
};