CIOAgent / frontend /src /components /SectorExposure.jsx
bhuvighosh3
Deployment with restored Stress Specialist data
9fbb3f2
Raw History Blame Contribute Delete
2.67 kB
import React from "react";
import { BarChart, Bar, XAxis, YAxis, Tooltip, ResponsiveContainer, Cell } from "recharts";
const COLORS = ["#6366f1", "#8b5cf6", "#a78bfa", "#c4b5fd", "#818cf8", "#6d28d9", "#4f46e5"];
export default function SectorExposure({ data }) {
if (!data) return null;
const chartData = data.sector_breakdown.map((s) => ({
name: s.sector,
weight: +(s.weight * 100).toFixed(1),
}));
return (
<div className="section">
<h2>Sector Exposure</h2>
<div className="metrics-row" style={{ marginBottom: "1rem" }}>
<div className="metric-card">
<span className="metric-label">Concentration Risk</span>
<span className="metric-value" style={{
color: data.concentration_risk === "High" ? "var(--error)" :
data.concentration_risk === "Moderate" ? "var(--warning)" : "var(--success)"
}}>{data.concentration_risk}</span>
</div>
<div className="metric-card">
<span className="metric-label">HHI Index</span>
<span className="metric-value">{data.hhi.toFixed(3)}</span>
</div>
<div className="metric-card">
<span className="metric-label">Sectors</span>
<span className="metric-value">{data.sector_breakdown.length}</span>
</div>
</div>
<div className="two-col">
<div>
<h3>Sector Weights</h3>
<ResponsiveContainer width="100%" height={200}>
<BarChart data={chartData} layout="vertical" margin={{ left: 80 }}>
<XAxis type="number" tickFormatter={(v) => `${v}%`} />
<YAxis type="category" dataKey="name" width={80} tick={{ fontSize: 12 }} />
<Tooltip formatter={(v) => `${v}%`} />
<Bar dataKey="weight" radius={[0, 4, 4, 0]}>
{chartData.map((_, i) => (
<Cell key={i} fill={COLORS[i % COLORS.length]} />
))}
</Bar>
</BarChart>
</ResponsiveContainer>
</div>
<div>
<h3>Holdings Detail</h3>
<table className="data-table">
<thead><tr><th>Ticker</th><th>Sector</th><th>Industry</th><th>Weight</th></tr></thead>
<tbody>
{data.holdings.map((h, i) => (
<tr key={i}>
<td><strong>{h.ticker}</strong></td>
<td>{h.sector}</td>
<td style={{ fontSize: "0.8rem" }}>{h.industry}</td>
<td>{(h.weight * 100).toFixed(1)}%</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
</div>
);
}