import React, { useMemo } from 'react';
import { Treemap, ResponsiveContainer, Tooltip } from 'recharts';
import { getHistoricalData } from '../data/historicalData';
import { motion } from 'framer-motion';
import { X, Info } from 'lucide-react';
const HeatmapContent = (props) => {
const { x, y, width, height, name, performance } = props;
if (width < 5 || height < 5) return null;
const color = performance > 0
? `rgba(0, 200, 5, ${Math.min(0.2 + Math.abs(performance) / 5, 0.9)})`
: `rgba(255, 80, 0, ${Math.min(0.2 + Math.abs(performance) / 5, 0.9)})`;
return (
{width > 40 && height > 30 && (
{name}
)}
);
};
export default function PortfolioHeatmap({ onClose, allocation }) {
const heatmapData = useMemo(() => {
if (!allocation) return [];
return allocation.map(asset => {
try {
const hist = getHistoricalData(asset.ticker);
return {
name: asset.ticker,
size: asset.value || 1,
performance: hist?.percentChange || 0,
fullName: asset.name
};
} catch (e) {
return {
name: asset.ticker,
size: asset.value || 1,
performance: 0,
fullName: asset.name
};
}
});
}, [allocation]);
return (
{/* Header */}
Portfolio Heatmap
Live Analysis
Box size: Allocation % | Color: Daily Performance
}
>
{
if (active && payload && payload.length) {
const data = payload[0].payload;
return (
{data.name}
{data.fullName}
Allocation
{data.size}%
Day Change
0 ? 'text-[#00C805]' : 'text-[#FF5000]'}`}>
{data.performance > 0 ? '+' : ''}{data.performance}%
);
}
return null;
}}
/>
{/* Legend */}
Color intensity scales with volatility
);
}