· 4 min read

A lighter results page: hand-drawn charts and a faster export

How Typestrix builds its result chart from SVG geometry and exports a clean PNG with a lazily loaded capture library and a separate branding canvas.

Shivank Pandey

The results view does two different jobs: explain a typing run and turn it into a shareable image. Typestrix keeps the result chart specific to its data and loads the screenshot machinery only when someone asks for a download. Both changes were measured when they landed; the numbers are below.

What changed, measured at the time

ChangeBeforeAfter
Result chart: recharts replaced by WpmChart99 KB for the results chunk19.2 KB
Export: html2canvas-pro replaced by snapdom208 KB lazy chunk (82 KB gzip)156 KB (53 KB gzip)
Export: three repeat captures219, 180, 179 ms231, 148, 54 ms

Each was measured on the build where the change shipped. Dependencies have moved since, so treat them as the size of each change, not as current bundle sizes. The exported image stayed effectively identical (a 0.15% pixel difference, in the banner strip).

The export pipeline

Pick a step, or use the arrows, to walk through the diagram.

Step through it. Nothing here runs until someone asks for an image.

Draw the chart the result needs

The result chart receives time, net WPM, and raw WPM samples. It measures its container with ResizeObserver and recalculates geometry when that size or the data changes.

Its SVG contains grid lines, axis labels, two paths, an average marker, and an optional hover indicator. It does not need a general-purpose chart component for these particular elements. The profile's separate performance chart still uses a charting library, so this is a result-screen choice rather than removal of every chart dependency.

Smooth without inventing wild peaks

The path builder computes segment slopes and tangent estimates, handles flat segments, and limits tangent magnitude before constructing cubic Bézier segments. It is intended to keep smoothing from introducing overshoot around changing values.

Empty, single-point, and two-point input have explicit paths. The y-domain includes both net and raw values with padding, so a raw-speed peak does not vanish outside a net-only domain. Tick spacing uses readable powers-of-ten steps rather than labeling arbitrary decimal intervals.

X positions are currently based on sample index, while labels show the supplied timestamps. That is appropriate for roughly regular samples but does not produce a true proportional time axis if sample intervals are irregular. Chart smoothing and axis semantics are separate concerns.

The average line is not final WPM

The chart's average marker is the rounded arithmetic mean of its sampled WPM values. Final headline WPM comes from correct characters divided by the completion duration.

Those numbers can differ because each progression point is itself a cumulative measurement from the beginning of the run. Averaging those cumulative snapshots is not the same operation as calculating the final rate.

This is worth explaining when a player sees an average marker below or above the result headline. The chart presents a visual summary of samples, not another authoritative score.

Keep hover work local

A transparent plot rectangle handles mouse movement. The chart finds the nearest x-position, stores the hover index, and displays a crosshair and two point markers. The tooltip shows that sample's time, net WPM, and raw WPM.

The current interaction is mouse-oriented. It is not a complete keyboard or touch data-exploration interface. The SVG has a title and label, but richer accessible sample inspection would require an additional control or textual representation.

Export is an on-demand capability

The download handler dynamically imports snapdom. Simply opening results does not invoke a capture. The handler captures the result container with embedded fonts and a fixed dark background, excluding action controls and the sign-in/practice banner.

That gives the shared image the information it needs without including buttons that only make sense in the live app. The capture library is an implementation tool, not a reason for a player to understand DOM serialization.

Compose a clean final canvas

After capture, a second canvas adds margins and a dedicated branding area. It draws the captured result, then a timestamp and site name, and encodes the output as a PNG blob.

The handler creates a temporary object URL, triggers a download, and revokes the URL afterward. A missing canvas context or failed capture stops the export path without changing the result itself. Errors are logged, though the current flow does not give every export failure a visible toast.

The chosen scale controls image density and memory use. Browser limits and long-lived capture behavior still deserve testing when layouts change; a successful build is not a capture-speed benchmark.

Saving and exporting are separate

Authenticated, saveable results automatically attempt the Server Action save. A local ref suppresses repeated attempts during that component's lifetime. It is not a server-side idempotency key and does not guarantee a retry after a failed save.

Downloading the PNG does not establish that the result was saved or accepted for ranking. It renders what is on the result screen. Keeping that boundary explicit prevents a share image from being mistaken for server verification.

The implementation avoids loading capture work into the normal review path and avoids asking a broad chart abstraction to do a narrow drawing job.

Keep reading