File size: 11,394 Bytes
169aba7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
import React from 'react';
import { motion } from 'framer-motion';
import { 
  BookOpen, 
  Database, 
  Zap, 
  Target,
  MousePointerClick
} from 'lucide-react';
import { 
  AreaChart, 
  Area, 
  XAxis, 
  YAxis, 
  CartesianGrid, 
  Tooltip, 
  ResponsiveContainer, 
  PieChart, 
  Pie, 
  Cell,
  LineChart,
  Line,
  ScatterChart,
  Scatter,
  ZAxis
} from 'recharts';
import { 
  ANALYTICS_DATA, 
  TOPIC_DISTRIBUTION, 
  COLORS,
  PR_CURVE_DATA,
  EMBEDDING_DATA
} from '../../constants';

export function StatCard({ i, stat }) {
  return (
    <motion.div 
      initial={{ opacity: 0, y: 20 }}
      animate={{ opacity: 1, y: 0 }}
      transition={{ delay: i * 0.1 }}
      className="bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-800 p-6 rounded-[2rem] shadow-sm hover:shadow-xl transition-all group"
    >
      <div className="flex items-center justify-between mb-4">
        <div className={`p-3 ${stat.bg} dark:bg-brand/10 rounded-2xl group-hover:scale-110 transition-transform`}>
          <stat.icon className={`w-5 h-5 ${stat.color}`} />
        </div>
        <div className="text-[10px] font-bold text-slate-400 uppercase tracking-widest">{stat.label}</div>
      </div>
      <div className="space-y-1">
        <h3 className="text-3xl font-display font-bold text-slate-900 dark:text-white tracking-tighter">{stat.value}</h3>
        <div className="flex items-center gap-1">
          <span className={`text-[10px] font-bold ${stat.trend.startsWith('+') ? 'text-emerald-500' : 'text-blue-500'}`}>
            {stat.trend}
          </span>
          <span className="text-[10px] text-slate-400 font-medium">Since last epoch</span>
        </div>
      </div>
    </motion.div>
  );
}

export function OverviewTab({ isDarkMode, stats }) {
  return (
    <div className="space-y-8">
      {/* Top Row: CTR + Precision + Latency */}
      <div className="grid grid-cols-1 md:grid-cols-3 gap-6">
        {[
          { label: 'CTR (CLICK-THROUGH)', value: '24.8%', trend: '+1.2%', icon: MousePointerClick, color: 'text-brand', bg: 'bg-brand/5' },
          { label: 'PRECISION INDEX', value: '0.982', trend: '+0.002', icon: Target, color: 'text-indigo-500', bg: 'bg-indigo-50' },
          { label: 'LATENCY (AVG)', value: '84ms', trend: '-14ms', icon: Zap, color: 'text-amber-500', bg: 'bg-amber-50' },
        ].map((stat, i) => (
          <StatCard key={i} i={i} stat={stat} />
        ))}
      </div>

      {/* Middle Row: Query Trends + Topics */}
      <div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
        {/* Query Trends Chart */}
        <div className="lg:col-span-2 bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-800 rounded-[2.5rem] p-8 shadow-sm">
          <div className="flex items-center justify-between mb-8">
            <div>
              <h3 className="text-lg font-bold text-slate-900 dark:text-white mb-1">Query Trends</h3>
              <p className="text-xs text-slate-400 font-medium">Daily search volume vs AI usage</p>
            </div>
            <div className="flex gap-6">
              <div className="flex items-center gap-2">
                <div className="w-2.5 h-2.5 rounded-full bg-brand" />
                <span className="text-[10px] font-bold text-slate-500 dark:text-slate-400 uppercase tracking-widest">Searches</span>
              </div>
              <div className="flex items-center gap-2">
                <div className="w-2.5 h-2.5 rounded-full bg-indigo-400" />
                <span className="text-[10px] font-bold text-slate-500 dark:text-slate-400 uppercase tracking-widest">AI Compute</span>
              </div>
            </div>
          </div>
          <div className="h-[320px]">
            <ResponsiveContainer width="100%" height="100%">
              <AreaChart data={ANALYTICS_DATA} margin={{ top: 10, right: 10, left: 0, bottom: 0 }}>
                <defs>
                  <linearGradient id="colorSearches" x1="0" y1="0" x2="0" y2="1">
                    <stop offset="5%" stopColor="#534AB7" stopOpacity={0.1}/>
                    <stop offset="95%" stopColor="#534AB7" stopOpacity={0}/>
                  </linearGradient>
                  <linearGradient id="colorAI" x1="0" y1="0" x2="0" y2="1">
                    <stop offset="5%" stopColor="#818CF8" stopOpacity={0.1}/>
                    <stop offset="95%" stopColor="#818CF8" stopOpacity={0}/>
                  </linearGradient>
                </defs>
                <CartesianGrid strokeDasharray="3 3" vertical={false} stroke={isDarkMode ? "#1E293B" : "#F1F5F9"} />
                <XAxis 
                  dataKey="name" 
                  axisLine={false} 
                  tickLine={false} 
                  tick={{ fontSize: 10, fill: isDarkMode ? '#64748B' : '#94A3B8', fontWeight: 'bold' }}
                  dy={10}
                />
                <YAxis 
                  axisLine={false} 
                  tickLine={false} 
                  tick={{ fontSize: 10, fill: isDarkMode ? '#64748B' : '#94A3B8', fontWeight: 'bold' }}
                />
                <Tooltip 
                  contentStyle={{ borderRadius: '20px', border: 'none', backgroundColor: isDarkMode ? '#0F172A' : '#FFFFFF', boxShadow: '0 10px 25px rgba(0,0,0,0.3)', padding: '16px' }}
                  itemStyle={{ fontWeight: 'bold', fontSize: '11px', color: isDarkMode ? '#F8FAFC' : '#0F172A' }}
                />
                <Area type="monotone" dataKey="searches" stroke="#534AB7" strokeWidth={3} fillOpacity={1} fill="url(#colorSearches)" />
                <Area type="monotone" dataKey="ai" stroke="#818CF8" strokeWidth={3} fillOpacity={1} fill="url(#colorAI)" />
              </AreaChart>
            </ResponsiveContainer>
          </div>
        </div>

        {/* Density Chart (Topics) */}
        <div className="bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-800 rounded-[2.5rem] p-8 shadow-sm flex flex-col items-center">
          <h3 className="text-base font-bold text-slate-900 dark:text-white mb-6 w-full text-left">Topics</h3>
          <div className="h-[200px] w-full">
            <ResponsiveContainer width="100%" height="100%">
              <PieChart>
                <Pie
                  data={stats?.topic_distribution || TOPIC_DISTRIBUTION}
                  cx="50%"
                  cy="50%"
                  innerRadius={60}
                  outerRadius={80}
                  paddingAngle={8}
                  dataKey="value"
                >
                  {(stats?.topic_distribution || TOPIC_DISTRIBUTION).map((entry, index) => (
                    <Cell key={`cell-${index}`} fill={COLORS[index % COLORS.length]} />
                  ))}
                </Pie>
                <Tooltip />
              </PieChart>
            </ResponsiveContainer>
          </div>
          <div className="w-full space-y-3 mt-6">
            {(stats?.topic_distribution || TOPIC_DISTRIBUTION).map((topic, i) => (
              <div key={topic.name} className="flex items-center justify-between">
                <div className="flex items-center gap-2">
                  <div className="w-2 h-2 rounded-full" style={{ backgroundColor: COLORS[i % COLORS.length] }} />
                  <span className="text-[11px] font-bold text-slate-500 dark:text-slate-400 uppercase">{topic.name}</span>
                </div>
                <span className="text-xs font-bold text-slate-900 dark:text-white">{topic.value}</span>
              </div>
            ))}
          </div>
        </div>
      </div>

      {/* Bottom Row: Relevance + Embedding Visualization */}
      <div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
        {/* PR Curve */}
        <div className="bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-800 rounded-[2.5rem] p-8 shadow-sm">
          <div className="mb-6">
            <h3 className="text-lg font-bold text-slate-900 dark:text-white mb-1">Relevance</h3>
            <p className="text-xs text-slate-400 font-medium">Precision-Recall Curve</p>
          </div>
          <div className="h-[250px]">
            <ResponsiveContainer width="100%" height="100%">
              <LineChart data={PR_CURVE_DATA} margin={{ top: 10, right: 10, left: 0, bottom: 0 }}>
                <CartesianGrid strokeDasharray="3 3" vertical={false} stroke={isDarkMode ? "#1E293B" : "#F1F5F9"} />
                <XAxis 
                  dataKey="recall" 
                  type="number"
                  domain={[0, 100]}
                  axisLine={false} 
                  tickLine={false} 
                  tick={{ fontSize: 10, fill: isDarkMode ? '#64748B' : '#94A3B8', fontWeight: 'bold' }}
                  dy={10}
                />
                <YAxis 
                  axisLine={false} 
                  tickLine={false} 
                  tick={{ fontSize: 10, fill: isDarkMode ? '#64748B' : '#94A3B8', fontWeight: 'bold' }}
                />
                <Tooltip 
                  contentStyle={{ borderRadius: '20px', border: 'none', backgroundColor: isDarkMode ? '#0F172A' : '#FFFFFF', boxShadow: '0 10px 25px rgba(0,0,0,0.3)', padding: '16px' }}
                  itemStyle={{ fontWeight: 'bold', fontSize: '11px', color: isDarkMode ? '#F8FAFC' : '#0F172A' }}
                />
                <Line type="monotone" dataKey="precision" stroke="#10B981" strokeWidth={3} dot={false} />
              </LineChart>
            </ResponsiveContainer>
          </div>
        </div>

        {/* Embedding Scatter Plot */}
        <div className="bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-800 rounded-[2.5rem] p-8 shadow-sm">
          <div className="mb-6">
            <h3 className="text-lg font-bold text-slate-900 dark:text-white mb-1">Embedding Visualization</h3>
            <p className="text-xs text-slate-400 font-medium">2D PCA projection of vector space</p>
          </div>
          <div className="h-[250px]">
            <ResponsiveContainer width="100%" height="100%">
              <ScatterChart margin={{ top: 10, right: 10, left: 0, bottom: 0 }}>
                <CartesianGrid strokeDasharray="3 3" stroke={isDarkMode ? "#1E293B" : "#F1F5F9"} />
                <XAxis type="number" dataKey="x" name="PCA1" axisLine={false} tickLine={false} tick={{ fontSize: 10, fill: isDarkMode ? '#64748B' : '#94A3B8' }} />
                <YAxis type="number" dataKey="y" name="PCA2" axisLine={false} tickLine={false} tick={{ fontSize: 10, fill: isDarkMode ? '#64748B' : '#94A3B8' }} />
                <ZAxis type="number" dataKey="z" range={[50, 200]} />
                <Tooltip 
                  cursor={{ strokeDasharray: '3 3' }} 
                  contentStyle={{ borderRadius: '16px', border: 'none', backgroundColor: isDarkMode ? '#0F172A' : '#FFFFFF', boxShadow: '0 10px 25px rgba(0,0,0,0.3)' }}
                />
                <Scatter name="Algebra" data={EMBEDDING_DATA.filter(d => d.cluster === 'Algebra')} fill="#534AB7" />
                <Scatter name="Calculus" data={EMBEDDING_DATA.filter(d => d.cluster === 'Calculus')} fill="#7C3AED" />
                <Scatter name="Statistics" data={EMBEDDING_DATA.filter(d => d.cluster === 'Statistics')} fill="#10B981" />
              </ScatterChart>
            </ResponsiveContainer>
          </div>
        </div>
      </div>
    </div>
  );
}