Spaces:
Sleeping

File size: 2,672 Bytes
9fbb3f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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>
  );
}