Skip to content

Commit 2818ff3

Browse files
CopilotBoshen
andauthored
Display bundle size numbers with commas in absolute bytes (#25)
* Initial plan * Implement bundle size formatting with commas and absolute numbers Co-authored-by: Boshen <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: Boshen <[email protected]>
1 parent 4eb8bdb commit 2818ff3

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

apps/dashboard/src/App.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import { BarChart3, Clock, Package, FileText } from 'lucide-react'
44
import './App.css'
55
import rolldownStats from '../../../rolldown-version-stats.json'
66

7+
// Utility function to format numbers with commas
8+
const formatNumberWithCommas = (num: number): string => {
9+
return num.toLocaleString()
10+
}
11+
712
// Transform rolldown stats data for charts
813
const buildTimeData = rolldownStats.map(stat => ({
914
name: `v${stat.version}`,
@@ -12,7 +17,7 @@ const buildTimeData = rolldownStats.map(stat => ({
1217

1318
const bundleSizeData = rolldownStats.map(stat => ({
1419
name: `v${stat.version}`,
15-
value: Math.round(stat.totalSize / 1024) // Convert to KB
20+
value: stat.totalSize // Use actual bytes instead of KB
1621
}))
1722

1823
// Calculate file type breakdown from all versions
@@ -37,6 +42,14 @@ const fileTypeData = Object.entries(fileTypeStats).map(([type, size]) => ({
3742
function App() {
3843
const [selectedMetric, setSelectedMetric] = useState('buildTime')
3944

45+
// Custom tooltip formatter for bundle size
46+
const customTooltipFormatter = (value: any, name: string) => {
47+
if (selectedMetric === 'bundleSize') {
48+
return [formatNumberWithCommas(value), name]
49+
}
50+
return [value, name]
51+
}
52+
4053
const metrics = [
4154
{ id: 'buildTime', name: 'Build Time', icon: Clock, data: buildTimeData, color: '#8884d8' },
4255
{ id: 'bundleSize', name: 'Bundle Size', icon: Package, data: bundleSizeData, color: '#82ca9d' },
@@ -94,12 +107,12 @@ function App() {
94107
<CartesianGrid strokeDasharray="3 3" />
95108
<XAxis dataKey="name" />
96109
<YAxis />
97-
<Tooltip />
110+
<Tooltip formatter={selectedMetric === 'bundleSize' ? customTooltipFormatter : undefined} />
98111
<Legend />
99112
<Bar
100113
dataKey="value"
101114
fill={currentMetric.color}
102-
name={selectedMetric === 'buildTime' ? 'Build Time (ms)' : 'Bundle Size (KB)'}
115+
name={selectedMetric === 'buildTime' ? 'Build Time (ms)' : 'Bundle Size (bytes)'}
103116
/>
104117
</BarChart>
105118
)}
@@ -114,7 +127,7 @@ function App() {
114127
</div>
115128
<div className="stat-card">
116129
<h3>Latest Bundle Size</h3>
117-
<p className="stat-value">{bundleSizeData[bundleSizeData.length - 1]?.value}KB</p>
130+
<p className="stat-value">{formatNumberWithCommas(bundleSizeData[bundleSizeData.length - 1]?.value || 0)} bytes</p>
118131
<span className="stat-change positive">v{rolldownStats[rolldownStats.length - 1]?.version}</span>
119132
</div>
120133
<div className="stat-card">

0 commit comments

Comments
 (0)