Skip to content

Commit 23d48cd

Browse files
Initial load charts and docs (#737)
* Bar Charts in Run Time * Added Stacked Area Charts to the Details Page * Added Links To Table * Removed unnecessary description * Fprmat
1 parent d9c6dba commit 23d48cd

20 files changed

Lines changed: 651 additions & 23 deletions

‎packages/docs/src/components/InteractionHistoryChart.astro‎

Lines changed: 83 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,30 @@ import InteractionChartCaption from './InteractionChartCaption.astro'
77
interface Props {
88
title: string
99
data: InteractionHistoryDatum[]
10+
series?: readonly {
11+
key: string
12+
label: string
13+
colorVar?: string
14+
color?: string
15+
}[]
16+
valueFormat?: 'ms' | 'kb'
17+
yAxisLabel?: string
1018
}
1119
12-
const { title, data } = Astro.props
13-
const chartPayload = JSON.stringify({ title, data })
20+
const {
21+
title,
22+
data,
23+
series = INTERACTION_PHASES as NonNullable<Props['series']>,
24+
valueFormat = 'ms',
25+
yAxisLabel = 'Interaction latency (ms)',
26+
} = Astro.props
27+
const chartPayload = JSON.stringify({
28+
title,
29+
data,
30+
series,
31+
valueFormat,
32+
yAxisLabel,
33+
})
1434
---
1535

1636
{
@@ -23,7 +43,14 @@ const chartPayload = JSON.stringify({ title, data })
2343
</figure>
2444
) : (
2545
<figure class="interaction-history">
26-
<InteractionChartCaption title={title} />
46+
{valueFormat === 'ms' ? (
47+
<InteractionChartCaption title={title} />
48+
) : (
49+
<figcaption>
50+
<p class="interaction-history-title">{title}</p>
51+
<p>{series.map(({ label }) => label).join(' · ')} (KB)</p>
52+
</figcaption>
53+
)}
2754
<div
2855
class="interaction-history-wrapper"
2956
data-interaction-history={chartPayload}
@@ -35,8 +62,8 @@ const chartPayload = JSON.stringify({ title, data })
3562
<thead>
3663
<tr>
3764
<th scope="col">Framework version</th>
38-
<th scope="col">Interaction latency</th>
39-
{INTERACTION_PHASES.map(({ label }) => (
65+
<th scope="col">Total</th>
66+
{series.map(({ label }) => (
4067
<th scope="col">{label}</th>
4168
))}
4269
</tr>
@@ -45,9 +72,16 @@ const chartPayload = JSON.stringify({ title, data })
4572
{data.map((datum) => (
4673
<tr>
4774
<th scope="row">{datum.name}</th>
48-
<td>{formatChartValue(datum.interactionLatencyMs, 'ms')}</td>
49-
{INTERACTION_PHASES.map(({ key }) => (
50-
<td>{formatChartValue(datum[key], 'ms')}</td>
75+
<td>
76+
{formatChartValue(datum.interactionLatencyMs, valueFormat)}
77+
</td>
78+
{series.map(({ key }) => (
79+
<td>
80+
{formatChartValue(
81+
Number(Reflect.get(datum, key)),
82+
valueFormat,
83+
)}
84+
</td>
5185
))}
5286
</tr>
5387
))}
@@ -114,6 +148,14 @@ const chartPayload = JSON.stringify({ title, data })
114148
interface Payload {
115149
title: string
116150
data: InteractionHistoryDatum[]
151+
series?: readonly {
152+
key: string
153+
label: string
154+
colorVar?: string
155+
color?: string
156+
}[]
157+
valueFormat?: 'ms' | 'kb'
158+
yAxisLabel?: string
117159
}
118160
interface PhaseRow {
119161
version: string
@@ -147,24 +189,34 @@ const chartPayload = JSON.stringify({ title, data })
147189
const payload = getPayload(wrapper)
148190
if (!payload) return
149191

150-
const { data } = payload
151-
const phaseLabels = INTERACTION_PHASES.map(({ label }) => label)
152-
const phaseColors = INTERACTION_PHASES.map(({ colorVar }, index) =>
153-
getCssVar(colorVar, PHASE_FALLBACKS[index]!),
192+
const {
193+
data,
194+
series = INTERACTION_PHASES as NonNullable<Payload['series']>,
195+
valueFormat = 'ms',
196+
yAxisLabel,
197+
} = payload
198+
const phaseLabels = series.map(({ label }) => label)
199+
const phaseColors = series.map(
200+
({ colorVar, color }, index) =>
201+
color ??
202+
getCssVar(
203+
colorVar ?? '--ft-muted',
204+
PHASE_FALLBACKS[index % PHASE_FALLBACKS.length]!,
205+
),
154206
)
155207
const rows: PhaseRow[] = data.flatMap((datum) =>
156-
INTERACTION_PHASES.map(({ key, label }) => ({
208+
series.map(({ key, label }) => ({
157209
version: datum.name,
158210
phase: label,
159-
ms: datum[key],
211+
ms: Number(Reflect.get(datum, key)),
160212
})),
161213
)
162214
const topEdges: PhaseRow[] = data.flatMap((datum) => {
163215
let total = 0
164-
return INTERACTION_PHASES.map(({ key, label }) => ({
216+
return series.map(({ key, label }) => ({
165217
version: datum.name,
166218
phase: label,
167-
ms: (total += datum[key]),
219+
ms: (total += Number(Reflect.get(datum, key))),
168220
}))
169221
})
170222
const byVersion = new Map(data.map((datum) => [datum.name, datum]))
@@ -204,7 +256,7 @@ const chartPayload = JSON.stringify({ title, data })
204256
y: {
205257
scale: scaleLinear,
206258
grid: true,
207-
axis: { label: 'Interaction latency (ms)' },
259+
axis: { label: yAxisLabel },
208260
},
209261
},
210262
color: { domain: phaseLabels, range: phaseColors },
@@ -221,14 +273,22 @@ const chartPayload = JSON.stringify({ title, data })
221273
return {
222274
title: datum.name,
223275
rows: [
224-
...INTERACTION_PHASES.map(({ key, label }, index) => ({
225-
label,
226-
value: formatChartValue(datum[key], 'ms'),
227-
color: phaseColors[index]!,
228-
})).reverse(),
276+
...series
277+
.map(({ key, label }, index) => ({
278+
label,
279+
value: formatChartValue(
280+
Number(Reflect.get(datum, key)),
281+
valueFormat,
282+
),
283+
color: phaseColors[index]!,
284+
}))
285+
.reverse(),
229286
{
230287
label: 'Total',
231-
value: formatChartValue(datum.interactionLatencyMs, 'ms'),
288+
value: formatChartValue(
289+
datum.interactionLatencyMs,
290+
valueFormat,
291+
),
232292
active: true,
233293
},
234294
],

0 commit comments

Comments
 (0)