How it works
A textbook figure of y = a₁ sin x + a₂ sin 2x + a₃ sin 3x over one period. Each harmonic is a thin line in its own chart colour, named in the legend; the sum is the strong ink line. The axes are fixed at ±2.5, so changing an amplitude always shows as a change of shape. A playhead stops every π/12, its position rides the x axis as a pill, and the row under the plot reads the sum there. One slider per harmonic sets its amplitude from −1 to +1, with zero in the middle. On a card under 440px wide the legend gives way to the slider rows, which carry the same swatches and names; under 400px each slider moves below its name.
Use it for
- Teach Fourier series or superposition: let learners build a sawtooth or a square wave from its first terms and see each term's share.
- Explain why two waves can cancel or reinforce at a point, by moving the playhead to where the coloured dots meet or oppose.
Look elsewhere when
- For measured data over time, use a line chart: this figure draws functions, not samples.
Usage
import React, { useState } from 'react'
import { HarmonicSumSheet } from './HarmonicSumSheet.jsx'
const sawtooth = [1, -0.5, 0.33]
export function FourierLesson() {
const [mix, setMix] = useState(sawtooth)
return (
<HarmonicSumSheet
value={mix}
defaultValue={sawtooth}
onChange={(next) => setMix(next)}
labels={{ title: 'Toward a sawtooth wave' }}
/>
)
}Props
| Prop | Type | Default | What it does |
|---|---|---|---|
value | [number, number, number] | — | Controlled amplitudes of the fundamental, 2nd and 3rd harmonic, each from −1 to +1 (rounded to two decimals). |
defaultValue | [number, number, number] | [1, -0.5, 0.33] | Starting amplitudes when uncontrolled, and what Reset returns to in both modes. |
onChange | (mix, details) => void | — | Called with the new amplitudes and { harmonic (1–3, or null on reset), reason ('press', 'drag', 'tap', 'key', 'cancel' or 'reset'), position, sum }. |
position | number | — | Controlled playhead position in multiples of π, from 0 to 2; it snaps to steps of π/12. |
defaultPosition | number | 0.75 | Starting playhead position in multiples of π (0.75 is 3π/4). |
onPositionChange | (position, { reason, sum }) => void | — | Called when the playhead moves, with its position in multiples of π and the sum there. |
step | number | 0.05 | Amplitude step for dragging and arrow keys. Shift with an arrow, or Page Up and Page Down, move five steps. |
labels | object | — | Replaces any built-in text: title, formula, names (three), sum, readout ('{x}' is the position), position, positionText ('{x}', '{sum}'), amplitudes, amplitudeText ('{value}') and reset. |
locale | string | 'en' | Language tag for the decimal readouts. |
className | string | — | Extra class on the card, for example to set its width (30rem by default, never wider than its container). |
Accessibility
- The plot is a slider for the playhead: Left and Right arrows move it by π/12, Shift with an arrow or Page Up and Page Down by π/4, Home and End go to 0 and 2π. Its value text reads the position and the sum there.
- Each amplitude is a slider labelled with its harmonic's name: arrows move one step, Shift with an arrow or Page Up and Page Down five steps, Home and End go to −1 and +1. Its value text reads the amplitude.
- The sum at the playhead is a polite live region. Reset is a button; it is marked unavailable while nothing has changed.
- Dragging uses pointer capture. On touch, a press on a slider's track or on the plot changes nothing until the finger moves sideways or lifts, so vertical scrolling is not caught; a cancelled gesture restores the value it started from.
- Colour is not the only key: the legend names each line, the sum is thicker, and the slider rows repeat the names with the same swatches.
Motion
After a key press, a tap or Reset, the curves, dots, playhead and thumbs glide for --ds-duration-fast. While a slider is dragged they follow the pointer directly. With reduced motion every change lands at once.
Add it to your project
Pro members copy a prompt and their coding agent installs the source, the same way as the free components.
HarmonicSumSheet.jsxharmonic-sum-sheet.csstokens.cssREADME.md
Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.



