diff --git a/app/components/graphs/UpfrontComparisonBarChart.tsx b/app/components/graphs/UpfrontComparisonBarChart.tsx new file mode 100644 index 0000000..85c4eb3 --- /dev/null +++ b/app/components/graphs/UpfrontComparisonBarChart.tsx @@ -0,0 +1,113 @@ +"use client"; + +import { Bar, BarChart, CartesianGrid, XAxis } from "recharts"; +import { + Card, + CardContent, + CardDescription, + CardFooter, + CardHeader, + CardTitle, +} from "@/components/ui/card"; +import { + ChartConfig, + ChartContainer, + ChartLegend, + ChartLegendContent, + ChartTooltip, + ChartTooltipContent, +} from "@/components/ui/chart"; + +const chartConfig = { + land: { + label: "Land", + color: "hsl(var(--chart-1))", + }, + house: { + label: "House", + color: "hsl(var(--chart-2))", + }, +} satisfies ChartConfig; + +import React from "react"; + +// Define type for DataInput +type DataInput = { + category: string; + marketPurchase: number; + fairholdLandPurchase: number; + fairholdLandRent: number; + [key: string]: string | number; +}; + +// Define the props type for StackedBarChart +interface StackedBarChartProps { + data: DataInput[]; +} + +// Implementation of the Chart.js Stacked Bar Chart +const UpfrontComparisonBarChart: React.FC = ({ + data, +}) => { + const chartData = [ + { + tenure: "market: purchase", + land: data[0].marketPurchase, + house: data[1].marketPurchase, + }, + { + tenure: "fairhold: land purchase", + land: data[0].fairholdLandPurchase, + house: data[1].fairholdLandPurchase, + }, + { + tenure: "fairhold: land rent", + land: data[0].fairholdLandRent, + house: data[1].fairholdLandRent, + }, + ]; + + return ( + + + Tenure comparison + Monthly cost in £ + + + + + + value} + /> + } /> + } /> + + + + + + +
+ Showing the upfront cost. +
+
+
+ ); +}; + +export default UpfrontComparisonBarChart; diff --git a/app/components/graphs/UpfrontComparisonWrapper.tsx b/app/components/graphs/UpfrontComparisonWrapper.tsx new file mode 100644 index 0000000..edcf339 --- /dev/null +++ b/app/components/graphs/UpfrontComparisonWrapper.tsx @@ -0,0 +1,59 @@ +"use client"; +import React from "react"; +import ErrorBoundary from "../ErrorBoundary"; +import { Household } from "@/app/models/Household"; +import UpfrontComparisonBarChart from "./UpfrontComparisonBarChart"; + +interface UpfrontComparisonWrapperProps { + household: Household; + mortgageLand?: number; + averageRentLand?: number; + socialRentMonthlyLand?: number; + mortgageFairholdLandPurchase?: number; + fairholdLandRent?: number; + mortgageHouse?: number; + mortgageDepreciatedHouse?: number; + averageRentHouse?: number; + socialRentMonthlyHouse?: number; +} + +const UpfrontComparisonWrapper: React.FC = ({ + household, +}) => { + if (!household) { + return
No household data available
; + } + + const formatData = (household: Household) => { + return [ + { + category: "Land price", + marketPurchase: household.property.landPrice || 0, + fairholdLandPurchase: + household.tenure.fairholdLandPurchase?.discountedLandPrice || 0, + fairholdLandRent: 0, + }, + { + category: "House price", + marketPurchase: + household.property.averageMarketPrice - + household.property.landPrice || 0, + fairholdLandPurchase: household.property.depreciatedBuildPrice || 0, + fairholdLandRent: household.property.depreciatedBuildPrice || 0, + }, + ]; + }; + + const formattedData = formatData(household); + + return ( + +
+

Tenure Comparison Chart

+ +
+
+ ); +}; + +export default UpfrontComparisonWrapper; diff --git a/app/components/ui/Dashboard.tsx b/app/components/ui/Dashboard.tsx index d1961b7..2e23393 100644 --- a/app/components/ui/Dashboard.tsx +++ b/app/components/ui/Dashboard.tsx @@ -1,5 +1,6 @@ import React from "react"; import TenureComparisonWrapper from "../graphs/TenureComparisonWrapper"; +import UpfrontComparisonWrapper from "../graphs/UpfrontComparisonWrapper"; import TotalPaymentWrapper from "../graphs/TotalPaymentWrapper"; import LifetimeMarketPurchaseWrapper from "../graphs/LifetimeMarketPurchaseWrapper"; import LifetimeMarketRentWrapper from "../graphs/LifetimeMarketRentWrapper"; @@ -16,6 +17,7 @@ const Dashboard: React.FC = ({ data }) => {

Dashboard

{/* Render multiple graph components here */} +