11import { useState } from 'react'
22import { BarChart , Bar , XAxis , YAxis , CartesianGrid , Tooltip , Legend , ResponsiveContainer } from 'recharts'
3- import { BarChart3 , TrendingUp , Users , DollarSign } from 'lucide-react'
3+ import { BarChart3 , Clock , Package , FileText } from 'lucide-react'
44import './App.css'
5+ import rolldownStats from '../../../rolldown-version-stats.json'
56
6- // Sample data for different metrics
7- const salesData = [
8- { name : 'Jan' , value : 4000 } ,
9- { name : 'Feb' , value : 3000 } ,
10- { name : 'Mar' , value : 5000 } ,
11- { name : 'Apr' , value : 4500 } ,
12- { name : 'May' , value : 6000 } ,
13- { name : 'Jun' , value : 5500 } ,
14- ]
7+ // Transform rolldown stats data for charts
8+ const buildTimeData = rolldownStats . map ( stat => ( {
9+ name : `v${ stat . version } ` ,
10+ value : stat . buildTime
11+ } ) )
1512
16- const userActivityData = [
17- { name : 'Mon' , active : 120 , inactive : 80 } ,
18- { name : 'Tue' , active : 150 , inactive : 60 } ,
19- { name : 'Wed' , active : 180 , inactive : 40 } ,
20- { name : 'Thu' , active : 200 , inactive : 30 } ,
21- { name : 'Fri' , active : 170 , inactive : 50 } ,
22- { name : 'Sat' , active : 90 , inactive : 110 } ,
23- { name : 'Sun' , active : 80 , inactive : 120 } ,
24- ]
13+ const bundleSizeData = rolldownStats . map ( stat => ( {
14+ name : `v${ stat . version } ` ,
15+ value : Math . round ( stat . totalSize / 1024 ) // Convert to KB
16+ } ) )
2517
26- const revenueData = [
27- { name : 'Q1' , revenue : 25000 } ,
28- { name : 'Q2' , revenue : 32000 } ,
29- { name : 'Q3' , revenue : 28000 } ,
30- { name : 'Q4' , revenue : 35000 } ,
31- ]
18+ // Calculate file type breakdown from all versions
19+ const fileTypeStats = rolldownStats . reduce ( ( acc , stat ) => {
20+ stat . files . forEach ( file => {
21+ if ( ! acc [ file . type ] ) {
22+ acc [ file . type ] = 0
23+ }
24+ acc [ file . type ] += file . size
25+ } )
26+ return acc
27+ } , { } as Record < string , number > )
28+
29+ const fileTypeData = Object . entries ( fileTypeStats ) . map ( ( [ type , size ] ) => ( {
30+ name : type . toUpperCase ( ) ,
31+ js : type === 'js' ? Math . round ( size / 1024 ) : 0 ,
32+ css : type === 'css' ? Math . round ( size / 1024 ) : 0 ,
33+ html : type === 'html' ? Math . round ( size / 1024 ) : 0 ,
34+ other : type === 'other' ? Math . round ( size / 1024 ) : 0 ,
35+ } ) ) . filter ( item => item . js > 0 || item . css > 0 || item . html > 0 || item . other > 0 )
3236
3337function App ( ) {
34- const [ selectedMetric , setSelectedMetric ] = useState ( 'sales ' )
38+ const [ selectedMetric , setSelectedMetric ] = useState ( 'buildTime ' )
3539
3640 const metrics = [
37- { id : 'sales ' , name : 'Sales ' , icon : TrendingUp , data : salesData , color : '#8884d8' } ,
38- { id : 'users ' , name : 'User Activity ' , icon : Users , data : userActivityData , color : '#82ca9d' } ,
39- { id : 'revenue ' , name : 'Revenue ' , icon : DollarSign , data : revenueData , color : '#ffc658' } ,
41+ { id : 'buildTime ' , name : 'Build Time ' , icon : Clock , data : buildTimeData , color : '#8884d8' } ,
42+ { id : 'bundleSize ' , name : 'Bundle Size ' , icon : Package , data : bundleSizeData , color : '#82ca9d' } ,
43+ { id : 'fileTypes ' , name : 'File Types ' , icon : FileText , data : fileTypeData , color : '#ffc658' } ,
4044 ]
4145
4246 const currentMetric = metrics . find ( m => m . id === selectedMetric ) || metrics [ 0 ]
@@ -73,15 +77,17 @@ function App() {
7377 < div className = "chart-container" >
7478 < h2 > { currentMetric . name } </ h2 >
7579 < ResponsiveContainer width = "100%" height = { 400 } >
76- { selectedMetric === 'users ' ? (
80+ { selectedMetric === 'fileTypes ' ? (
7781 < BarChart data = { currentMetric . data } >
7882 < CartesianGrid strokeDasharray = "3 3" />
7983 < XAxis dataKey = "name" />
8084 < YAxis />
8185 < Tooltip />
8286 < Legend />
83- < Bar dataKey = "active" fill = "#82ca9d" name = "Active Users" />
84- < Bar dataKey = "inactive" fill = "#8884d8" name = "Inactive Users" />
87+ < Bar dataKey = "js" fill = "#f7df1e" name = "JavaScript (KB)" />
88+ < Bar dataKey = "css" fill = "#1572b6" name = "CSS (KB)" />
89+ < Bar dataKey = "html" fill = "#e34c26" name = "HTML (KB)" />
90+ < Bar dataKey = "other" fill = "#6b7280" name = "Other (KB)" />
8591 </ BarChart >
8692 ) : (
8793 < BarChart data = { currentMetric . data } >
@@ -91,9 +97,9 @@ function App() {
9197 < Tooltip />
9298 < Legend />
9399 < Bar
94- dataKey = { selectedMetric === 'revenue' ? 'revenue' : ' value' }
100+ dataKey = " value"
95101 fill = { currentMetric . color }
96- name = { currentMetric . name }
102+ name = { selectedMetric === 'buildTime' ? 'Build Time (ms)' : 'Bundle Size (KB)' }
97103 />
98104 </ BarChart >
99105 ) }
@@ -102,24 +108,24 @@ function App() {
102108
103109 < div className = "stats-grid" >
104110 < div className = "stat-card" >
105- < h3 > Total Sales </ h3 >
106- < p className = "stat-value" > $124,500 </ p >
107- < span className = "stat-change positive" > +12.5% </ span >
111+ < h3 > Average Build Time </ h3 >
112+ < p className = "stat-value" > { Math . round ( buildTimeData . reduce ( ( sum , item ) => sum + item . value , 0 ) / buildTimeData . length ) } ms </ p >
113+ < span className = "stat-change positive" > Across { buildTimeData . length } versions </ span >
108114 </ div >
109115 < div className = "stat-card" >
110- < h3 > Active Users </ h3 >
111- < p className = "stat-value" > 1,245 </ p >
112- < span className = "stat-change positive" > +8.2% </ span >
116+ < h3 > Latest Bundle Size </ h3 >
117+ < p className = "stat-value" > { bundleSizeData [ bundleSizeData . length - 1 ] ?. value } KB </ p >
118+ < span className = "stat-change positive" > v { rolldownStats [ rolldownStats . length - 1 ] ?. version } </ span >
113119 </ div >
114120 < div className = "stat-card" >
115- < h3 > Revenue </ h3 >
116- < p className = "stat-value" > $98,750 </ p >
117- < span className = "stat-change negative" > -3.1% </ span >
121+ < h3 > Total File Types </ h3 >
122+ < p className = "stat-value" > { fileTypeData . length } </ p >
123+ < span className = "stat-change positive" > JS, CSS, HTML, Other </ span >
118124 </ div >
119125 < div className = "stat-card" >
120- < h3 > Conversion Rate </ h3 >
121- < p className = "stat-value" > 3.2% </ p >
122- < span className = "stat-change positive" > +0.8% </ span >
126+ < h3 > Versions Tested </ h3 >
127+ < p className = "stat-value" > { rolldownStats . length } </ p >
128+ < span className = "stat-change positive" > { rolldownStats [ 0 ] ?. version } - { rolldownStats [ rolldownStats . length - 1 ] ?. version } </ span >
123129 </ div >
124130 </ div >
125131 </ main >
0 commit comments