Spaces:
Build error
Build error
File size: 4,995 Bytes
49e53ae | 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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | 'use client';
import { TrendingUp, TrendingDown, Activity } from 'lucide-react';
interface RiskDistributionCardProps {
lowRisk: number;
mediumRisk: number;
highRisk: number;
criticalRisk: number;
}
export default function RiskDistributionCard({
lowRisk,
mediumRisk,
highRisk,
criticalRisk
}: RiskDistributionCardProps) {
const total = lowRisk + mediumRisk + highRisk + criticalRisk;
const data = [
{ label: 'Low Risk', value: lowRisk, color: 'bg-emerald-400', percentage: (lowRisk / total * 100).toFixed(1) },
{ label: 'Medium Risk', value: mediumRisk, color: 'bg-yellow-400', percentage: (mediumRisk / total * 100).toFixed(1) },
{ label: 'High Risk', value: highRisk, color: 'bg-orange-400', percentage: (highRisk / total * 100).toFixed(1) },
{ label: 'Critical', value: criticalRisk, color: 'bg-red-400', percentage: (criticalRisk / total * 100).toFixed(1) },
];
// Create a simple scatter-like visualization
const generatePoints = () => {
const points: { x: number; y: number; risk: string; color: string }[] = [];
// Generate clustered points for each risk level
data.forEach((item, riskIndex) => {
const count = Math.min(item.value, 30); // Cap at 30 points per category
for (let i = 0; i < count; i++) {
const baseX = 20 + (riskIndex * 20) + Math.random() * 15;
const baseY = 20 + Math.random() * 60;
points.push({
x: Math.min(95, Math.max(5, baseX)),
y: Math.min(95, Math.max(5, baseY)),
risk: item.label,
color: item.color.replace('bg-', '')
});
}
});
return points;
};
const points = generatePoints();
return (
<div className="card-teal rounded-3xl p-6 card-hover h-full">
{/* Header */}
<div className="flex items-center justify-between mb-4">
<div className="flex items-center gap-3">
<div className="w-10 h-10 rounded-xl bg-white/20 flex items-center justify-center">
<Activity className="w-5 h-5" />
</div>
<div>
<h3 className="text-xl font-bold">RISK DISTRIBUTION</h3>
<p className="text-xs text-white/60">Transaction Risk Mapping</p>
</div>
</div>
<button className="text-white/60 hover:text-white transition-colors">
<svg className="w-5 h-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<circle cx="11" cy="11" r="8" />
<path d="m21 21-4.35-4.35" />
</svg>
</button>
</div>
{/* Scatter Plot Visualization */}
<div className="relative h-40 mb-4 bg-white/10 rounded-2xl overflow-hidden">
{/* Grid lines */}
<div className="absolute inset-0">
{[...Array(5)].map((_, i) => (
<div key={`h-${i}`} className="absolute w-full border-t border-white/10" style={{ top: `${i * 25}%` }} />
))}
{[...Array(5)].map((_, i) => (
<div key={`v-${i}`} className="absolute h-full border-l border-white/10" style={{ left: `${i * 25}%` }} />
))}
</div>
{/* Points */}
{points.map((point, i) => {
const colorMap: Record<string, string> = {
'emerald-400': '#34d399',
'yellow-400': '#facc15',
'orange-400': '#fb923c',
'red-400': '#f87171'
};
return (
<div
key={i}
className="absolute w-2 h-2 rounded-full animate-float"
style={{
left: `${point.x}%`,
top: `${point.y}%`,
backgroundColor: colorMap[point.color] || '#fff',
animationDelay: `${i * 0.1}s`,
opacity: 0.8
}}
/>
);
})}
</div>
{/* Legend & Stats */}
<div className="grid grid-cols-2 gap-2">
{data.map((item) => (
<div key={item.label} className="flex items-center gap-2 bg-white/10 rounded-xl p-2">
<div className={`w-3 h-3 rounded-full ${item.color}`} />
<div className="flex-1">
<p className="text-xs text-white/80">{item.label}</p>
<div className="flex items-baseline gap-1">
<span className="text-sm font-bold">{item.value}</span>
<span className="text-xs text-white/60">({item.percentage}%)</span>
</div>
</div>
</div>
))}
</div>
{/* Trend indicator */}
<div className="mt-4 flex items-center justify-between text-sm">
<span className="text-white/60">Risk Trend</span>
<div className="flex items-center gap-1 text-emerald-300">
<TrendingDown className="w-4 h-4" />
<span>-2.3% this week</span>
</div>
</div>
</div>
);
}
|