"use client" interface Stats { no_report: number in_shelter: number not_in_shelter: number no_alarm: number } interface SimplePieChartProps { stats: Stats onCategoryClick: (category: string, categoryName: string) => void } export function SimplePieChart({ stats, onCategoryClick }: SimplePieChartProps) { const data = [ { name: "לא דיווחו", value: stats?.no_report || 0, color: "#ef4444", category: "no_report" }, { name: "במקלט/חדר מוגן", value: stats?.in_shelter || 0, color: "#22c55e", category: "in_shelter" }, { name: "לא במקלט", value: stats?.not_in_shelter || 0, color: "#f97316", category: "not_in_shelter" }, { name: "אין אזעקה", value: stats?.no_alarm || 0, color: "#3b82f6", category: "no_alarm" }, ] const total = data.reduce((sum, item) => sum + item.value, 0) if (total === 0) { return (
📊

אין נתונים להצגה

הוסף משתמשים כדי לראות סטטיסטיקות

) } let currentAngle = 0 return (
{data.map((item, index) => { if (item.value === 0) return null const percentage = (item.value / total) * 100 const angle = (item.value / total) * 360 const startAngle = currentAngle const endAngle = currentAngle + angle const startAngleRad = (startAngle * Math.PI) / 180 const endAngleRad = (endAngle * Math.PI) / 180 const largeArcFlag = angle > 180 ? 1 : 0 const x1 = 96 + 80 * Math.cos(startAngleRad) const y1 = 96 + 80 * Math.sin(startAngleRad) const x2 = 96 + 80 * Math.cos(endAngleRad) const y2 = 96 + 80 * Math.sin(endAngleRad) const pathData = [`M 96 96`, `L ${x1} ${y1}`, `A 80 80 0 ${largeArcFlag} 1 ${x2} ${y2}`, `Z`].join(" ") currentAngle += angle return ( onCategoryClick(item.category, item.name)} /> ) })} {/* Center text */}
{total}
סה"כ
{/* Legend */}
{data .filter((item) => item.value > 0) .map((item, index) => (
onCategoryClick(item.category, item.name)} >
{item.name}: {item.value}
))}
) }