Skip to content

Commit 74ffca5

Browse files
CopilotBoshen
andauthored
Add npm publication dates to chart tooltips (#50)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: Boshen <[email protected]>
1 parent 07436f8 commit 74ffca5

File tree

5 files changed

+889
-1245
lines changed

5 files changed

+889
-1245
lines changed

apps/dashboard/src/RolldownStats.tsx

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,21 @@ const formatNumberWithCommas = (num: number): string => {
1818
return num.toLocaleString();
1919
};
2020

21+
// Utility function to format dates
22+
const formatDate = (dateString: string): string => {
23+
return new Date(dateString).toLocaleDateString('en-US', {
24+
year: 'numeric',
25+
month: 'short',
26+
day: 'numeric',
27+
});
28+
};
29+
2130
// Transform rolldown stats data for charts
2231
const buildTimeData = rolldownStats.map(stat => ({
2332
name: `v${stat.version}`,
2433
value: stat.buildTime,
34+
version: stat.version,
35+
publicationDate: (stat as any).publicationDate,
2536
})).sort((a, b) => a.value - b.value); // Sort from smallest to largest
2637

2738
// Calculate bundle size differences between consecutive versions
@@ -34,6 +45,8 @@ const bundleSizeDiffData = rolldownStats.map((stat, index) => {
3445
previousSize: null,
3546
currentSize: stat.totalSize,
3647
isBaseline: true,
48+
version: stat.version,
49+
publicationDate: (stat as any).publicationDate,
3750
};
3851
}
3952

@@ -47,6 +60,8 @@ const bundleSizeDiffData = rolldownStats.map((stat, index) => {
4760
previousSize: prevSize,
4861
currentSize: currentSize,
4962
isBaseline: false,
63+
version: stat.version,
64+
publicationDate: (stat as any).publicationDate,
5065
};
5166
}).sort((a, b) => a.value - b.value); // Sort from smallest to largest
5267

@@ -61,15 +76,33 @@ function RolldownStats({ selectedMetric, setSelectedMetric }: RolldownStatsProps
6176
const data = props.payload;
6277
if (!data) return [value, name];
6378

79+
// Format publication date if available
80+
const publicationDateText = data.publicationDate
81+
? ` | Published: ${formatDate(data.publicationDate)}`
82+
: ' | Publication date unavailable';
83+
6484
if (data.isBaseline) {
65-
return [`${formatNumberWithCommas(data.currentSize)} bytes (baseline)`, 'Bundle Size'];
85+
return [`${formatNumberWithCommas(data.currentSize)} bytes (baseline)${publicationDateText}`, 'Bundle Size'];
6686
}
6787

6888
const sign = value >= 0 ? '+' : '';
6989
const changeText = `${sign}${formatNumberWithCommas(value)} bytes`;
7090
const fromTo = `(${formatNumberWithCommas(data.previousSize)}${formatNumberWithCommas(data.currentSize)})`;
7191

72-
return [`${changeText} ${fromTo}`, 'Size Change'];
92+
return [`${changeText} ${fromTo}${publicationDateText}`, 'Size Change'];
93+
};
94+
95+
// Custom tooltip formatter for build time
96+
const buildTimeTooltipFormatter = (value: any, name: string, props: any) => {
97+
const data = props.payload;
98+
if (!data) return [value, name];
99+
100+
// Format publication date if available
101+
const publicationDateText = data.publicationDate
102+
? ` | Published: ${formatDate(data.publicationDate)}`
103+
: ' | Publication date unavailable';
104+
105+
return [`${value}ms${publicationDateText}`, 'Build Time'];
73106
};
74107

75108
const rolldownMetrics = [
@@ -166,6 +199,7 @@ function RolldownStats({ selectedMetric, setSelectedMetric }: RolldownStatsProps
166199
tickLine={{ stroke: '#d1d5db' }}
167200
/>
168201
<Tooltip
202+
formatter={buildTimeTooltipFormatter}
169203
contentStyle={{
170204
backgroundColor: 'white',
171205
border: '1px solid #d1d5db',

dprint.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
},
1010
"toml": {
1111
},
12-
"excludes": [],
12+
"excludes": [
13+
"pnpm-lock.yaml"
14+
],
1315
"plugins": [
1416
"https://plugins.dprint.dev/typescript-0.94.0.wasm",
1517
"https://plugins.dprint.dev/json-0.20.0.wasm",

0 commit comments

Comments
 (0)