File size: 1,903 Bytes
fe1519f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import React from 'react';
import {
  Radar,
  RadarChart,
  PolarGrid,
  PolarAngleAxis,
  PolarRadiusAxis,
  ResponsiveContainer,
  Tooltip
} from 'recharts';

const PersonaChart = ({ scores }) => {
  const data = Object.keys(scores).map(key => ({
    subject: key.split(" / ")[0].toUpperCase(), // Truncate and Uppercase for cleanliness
    value: scores[key] * 100,
    fullMark: 100,
  }));

  const CustomTooltip = ({ active, payload }) => {
    if (active && payload && payload.length) {
      return (
        <div className="bg-black border border-zinc-700 p-2 shadow-xl">
          <div className="flex justify-between items-center gap-4 mb-1 border-b border-zinc-800 pb-1">
             <span className="text-[10px] font-mono text-zinc-400 uppercase">{payload[0].payload.subject}</span>
          </div>
          <div className="flex items-baseline gap-1">
            <span className="text-amber-500 font-bold font-mono text-sm">
              {payload[0].value.toFixed(1)}%
            </span>
          </div>
        </div>
      );
    }
    return null;
  };

  return (
    <ResponsiveContainer width="100%" height="100%">
      <RadarChart cx="50%" cy="50%" outerRadius="70%" data={data}>
        <PolarGrid stroke="#27272a" />
        <PolarAngleAxis 
            dataKey="subject" 
            tick={{ fill: '#71717a', fontSize: 10, fontFamily: 'JetBrains Mono', fontWeight: 500 }} 
        />
        <PolarRadiusAxis angle={30} domain={[0, 100]} tick={false} axisLine={false} />
        <Radar
          name="Confidence"
          dataKey="value"
          stroke="#f59e0b"
          strokeWidth={2}
          fill="#f59e0b"
          fillOpacity={0.2}
          isAnimationActive={true}
        />
        <Tooltip content={<CustomTooltip />} cursor={{ stroke: '#f59e0b', strokeWidth: 1 }} />
      </RadarChart>
    </ResponsiveContainer>
  );
};

export default PersonaChart;