Skip to content

Commit fbbb830

Browse files
CopilotBoshen
andauthored
Improve bundle size chart to show differences between versions (#37)
* Initial plan * Implement bundle size difference chart to show changes between versions Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
1 parent b9e619f commit fbbb830

1 file changed

Lines changed: 59 additions & 14 deletions

File tree

apps/dashboard/src/App.tsx

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useState } from 'react'
2-
import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts'
2+
import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer, Cell } from 'recharts'
33
import { BarChart3, Clock, Package, FileText } from 'lucide-react'
44
import './App.css'
55
import rolldownStats from '../../../rolldown-version-stats.json'
@@ -15,10 +15,31 @@ const buildTimeData = rolldownStats.map(stat => ({
1515
value: stat.buildTime
1616
}))
1717

18-
const bundleSizeData = rolldownStats.map(stat => ({
19-
name: `v${stat.version}`,
20-
value: stat.totalSize // Use actual bytes instead of KB
21-
}))
18+
// Calculate bundle size differences between consecutive versions
19+
const bundleSizeDiffData = rolldownStats.map((stat, index) => {
20+
if (index === 0) {
21+
// For the first version, show 0 difference or could show absolute value
22+
return {
23+
name: `v${stat.version}`,
24+
value: 0,
25+
previousSize: null,
26+
currentSize: stat.totalSize,
27+
isBaseline: true
28+
}
29+
}
30+
31+
const prevSize = rolldownStats[index - 1].totalSize
32+
const currentSize = stat.totalSize
33+
const diff = currentSize - prevSize
34+
35+
return {
36+
name: `v${stat.version}`,
37+
value: diff,
38+
previousSize: prevSize,
39+
currentSize: currentSize,
40+
isBaseline: false
41+
}
42+
})
2243

2344
// Calculate file type breakdown from all versions
2445
const fileTypeStats = rolldownStats.reduce((acc, stat) => {
@@ -42,17 +63,25 @@ const fileTypeData = Object.entries(fileTypeStats).map(([type, size]) => ({
4263
function App() {
4364
const [selectedMetric, setSelectedMetric] = useState('buildTime')
4465

45-
// Custom tooltip formatter for bundle size
46-
const customTooltipFormatter = (value: any, name: string) => {
47-
if (selectedMetric === 'bundleSize') {
48-
return [formatNumberWithCommas(value), name]
66+
// Custom tooltip formatter for bundle size differences
67+
const bundleSizeDiffTooltipFormatter = (value: any, name: string, props: any) => {
68+
const data = props.payload
69+
if (!data) return [value, name]
70+
71+
if (data.isBaseline) {
72+
return [`${formatNumberWithCommas(data.currentSize)} bytes (baseline)`, 'Bundle Size']
4973
}
50-
return [value, name]
74+
75+
const sign = value >= 0 ? '+' : ''
76+
const changeText = `${sign}${formatNumberWithCommas(value)} bytes`
77+
const fromTo = `(${formatNumberWithCommas(data.previousSize)}${formatNumberWithCommas(data.currentSize)})`
78+
79+
return [`${changeText} ${fromTo}`, 'Size Change']
5180
}
5281

5382
const metrics = [
5483
{ id: 'buildTime', name: 'Build Time', icon: Clock, data: buildTimeData, color: '#8884d8' },
55-
{ id: 'bundleSize', name: 'Bundle Size', icon: Package, data: bundleSizeData, color: '#82ca9d' },
84+
{ id: 'bundleSize', name: 'Bundle Size', icon: Package, data: bundleSizeDiffData, color: '#82ca9d' },
5685
{ id: 'fileTypes', name: 'File Types', icon: FileText, data: fileTypeData, color: '#ffc658' },
5786
]
5887

@@ -102,17 +131,33 @@ function App() {
102131
<Bar dataKey="html" fill="#e34c26" name="HTML (KB)" />
103132
<Bar dataKey="other" fill="#6b7280" name="Other (KB)" />
104133
</BarChart>
134+
) : selectedMetric === 'bundleSize' ? (
135+
<BarChart data={currentMetric.data}>
136+
<CartesianGrid strokeDasharray="3 3" />
137+
<XAxis dataKey="name" />
138+
<YAxis />
139+
<Tooltip formatter={bundleSizeDiffTooltipFormatter} />
140+
<Legend />
141+
<Bar dataKey="value" name="Bundle Size Change (bytes)">
142+
{currentMetric.data.map((entry: any, index: number) => (
143+
<Cell
144+
key={`cell-${index}`}
145+
fill={entry.isBaseline ? '#94a3b8' : (entry.value >= 0 ? '#ef4444' : '#22c55e')}
146+
/>
147+
))}
148+
</Bar>
149+
</BarChart>
105150
) : (
106151
<BarChart data={currentMetric.data}>
107152
<CartesianGrid strokeDasharray="3 3" />
108153
<XAxis dataKey="name" />
109154
<YAxis />
110-
<Tooltip formatter={selectedMetric === 'bundleSize' ? customTooltipFormatter : undefined} />
155+
<Tooltip />
111156
<Legend />
112157
<Bar
113158
dataKey="value"
114159
fill={currentMetric.color}
115-
name={selectedMetric === 'buildTime' ? 'Build Time (ms)' : 'Bundle Size (bytes)'}
160+
name="Build Time (ms)"
116161
/>
117162
</BarChart>
118163
)}
@@ -127,7 +172,7 @@ function App() {
127172
</div>
128173
<div className="stat-card">
129174
<h3>Latest Bundle Size</h3>
130-
<p className="stat-value">{formatNumberWithCommas(bundleSizeData[bundleSizeData.length - 1]?.value || 0)} bytes</p>
175+
<p className="stat-value">{formatNumberWithCommas(rolldownStats[rolldownStats.length - 1]?.totalSize || 0)} bytes</p>
131176
<span className="stat-change positive">v{rolldownStats[rolldownStats.length - 1]?.version}</span>
132177
</div>
133178
<div className="stat-card">

0 commit comments

Comments
 (0)