Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions web/next-app/components/visual/Controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Select as UiSelect, SelectContent, SelectItem, SelectTrigger, SelectVal
// fills its cell, because a fixed 64px box clipped a value like `-1.25`.

const numeral =
'h-8 rounded-none border-mathua-border bg-mathua-code px-2 text-center font-mono text-[11px] tabular-nums text-mathua-primary focus:border-mathua-blue'
'h-10 rounded-none border-mathua-border bg-mathua-code px-2 text-center font-mono text-xs tabular-nums text-mathua-primary focus:border-mathua-blue'

/** Hides the platform stepper in every engine; the buttons take over. */
const noSpinner =
Expand All @@ -39,7 +39,7 @@ function StepButton({
aria-label={label}
onClick={onClick}
disabled={disabled}
className="flex w-7 shrink-0 items-center justify-center border border-mathua-border bg-mathua-surface font-mono text-[12px] leading-none text-mathua-secondary transition-colors hover:border-mathua-blue hover:text-mathua-blue disabled:cursor-not-allowed disabled:opacity-40"
className="flex h-10 w-10 shrink-0 items-center justify-center border border-mathua-border bg-mathua-surface font-mono text-[13px] leading-none text-mathua-secondary transition-colors hover:border-mathua-blue hover:text-mathua-blue disabled:cursor-not-allowed disabled:opacity-40"
>
{children}
</button>
Expand Down Expand Up @@ -122,14 +122,14 @@ export function Slider({ label, value, min, max, step = 0.1, onChange, suffix }:
onChange(Math.min(max, Math.max(min, next)))
}
return (
// Below `sm` the label takes its own line and the range shares the next one
// with the stepper, because three items on one row wrap mid-control at 320px
// and the stepper lands under the label with nothing to align to.
<div className="space-y-1 sm:flex sm:items-center sm:gap-2 sm:space-y-0">
<label htmlFor={id} className="block shrink-0 font-mono text-[10px] text-mathua-muted sm:w-10">
// The label always owns its line, and the range wraps beside the stepper.
// A narrow figure-controls strip cannot hold all three on one row; doing so
// pushed the stepper's + button past the card edge.
<div className="space-y-1">
<label htmlFor={id} className="block font-mono text-[10px] text-mathua-muted">
{label}
</label>
<div className="flex items-center gap-2 sm:flex-1">
<div className="flex flex-wrap items-center gap-2">
<input
id={id}
type="range"
Expand All @@ -138,11 +138,13 @@ export function Slider({ label, value, min, max, step = 0.1, onChange, suffix }:
step={step}
value={value}
onChange={(e) => commit(Number(e.target.value))}
className="min-w-0 flex-1"
className="min-w-[8rem] flex-1"
style={{ accentColor: 'var(--accent-blue)' }}
/>
<Stepper label={label} value={value} min={min} max={max} step={step} onChange={onChange} />
{suffix && <span className="font-mono text-[10px] text-mathua-muted">{suffix}</span>}
<span className="flex shrink-0 items-center gap-2">
<Stepper label={label} value={value} min={min} max={max} step={step} onChange={onChange} />
{suffix && <span className="font-mono text-[10px] text-mathua-muted">{suffix}</span>}
</span>
</div>
</div>
)
Expand Down Expand Up @@ -205,8 +207,8 @@ interface ToggleProps {
export function Toggle({ label, checked, onChange }: ToggleProps) {
const id = useId()
return (
<div className="flex items-center justify-between gap-3">
<label htmlFor={id} className="font-mono text-[10px] text-mathua-secondary">
<div className="flex min-h-11 items-center justify-between gap-3">
<label htmlFor={id} className="font-mono text-xs text-mathua-secondary">
{label}
</label>
<Switch id={id} checked={checked} onCheckedChange={onChange} className="min-h-0" />
Expand Down
14 changes: 12 additions & 2 deletions web/next-app/components/visual/FigureFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ interface FigureFrameProps {
* text inside the drawing scales with it and collided with the plot. */
hint?: string
onReset?: () => void
/** Control row rendered outside the bordered figure, so the drawing box stays
* a drawing and the buttons can take a full touch target on a phone. */
controls?: ReactNode
children: ReactNode
}

Expand All @@ -24,9 +27,10 @@ interface FigureFrameProps {
* with the keyboard hears the new value. It is never the only place a value
* appears: every control carries its own visible output.
*/
export default function FigureFrame({ title, caption, readout, hint, onReset, children }: FigureFrameProps) {
export default function FigureFrame({ title, caption, readout, hint, onReset, controls, children }: FigureFrameProps) {
const predict = usePredict()
return (
<>
<figure className="mt-5 border border-mathua-border bg-mathua-bg">
<div className="flex items-center justify-between gap-3 border-b border-mathua-border px-3 py-2">
{/* No `uppercase` on a title or a label: CSS case folding rewrites the mathematics.
Expand All @@ -37,7 +41,7 @@ export default function FigureFrame({ title, caption, readout, hint, onReset, ch
<button
type="button"
onClick={onReset}
className="border border-mathua-border px-2 py-0.5 font-mono text-[10px] text-mathua-secondary hover:border-mathua-blue hover:text-mathua-blue"
className="inline-flex h-9 items-center border border-mathua-border px-3 font-mono text-xs text-mathua-secondary hover:border-mathua-blue hover:text-mathua-blue"
>
Reset
</button>
Expand Down Expand Up @@ -75,5 +79,11 @@ export default function FigureFrame({ title, caption, readout, hint, onReset, ch
</figcaption>
)}
</figure>
{controls && (
<div data-testid="figure-controls" className="mt-2 border border-mathua-border bg-mathua-surface p-3">
{controls}
</div>
)}
</>
)
}
45 changes: 23 additions & 22 deletions web/next-app/components/visual/templates/SolidRevolution.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,29 @@ export default function SolidRevolution({ params, title, caption }: TemplateProp
'The body is swept from the drawn profile. A disk slice is a thin cylinder, a washer slice is a thin annulus and a shell slice is a thin tube. Each readout is the integral of that slice over the interval. Disks and washers share one body about the horizontal axis; the shell body is a second solid about the vertical axis, so its volume is not meant to match theirs.'
}
onReset={reset}
controls={
<>
<div className="flex items-center gap-2">
<label htmlFor="solid-method" className="w-20 shrink-0 font-mono text-xs text-mathua-muted">
Method
</label>
<select
id="solid-method"
aria-label="Method"
value={mode}
onChange={(event) => setMode(event.target.value as SolidMode)}
className="h-10 min-w-0 flex-1 border border-mathua-border bg-transparent px-2 font-mono text-xs text-mathua-secondary"
>
{Object.entries(SOLID_LABELS).map(([value, label]) => (
<option key={value} value={value}>
{label}
</option>
))}
</select>
</div>
<Slider label="Slice position" value={slice} min={0.1} max={2} step={0.05} onChange={setSlice} />
</>
}
readout={[
{ label: 'method', value: SOLID_LABELS[mode] },
{ label: 'formula', value: SOLID_FORMULAS[mode] },
Expand Down Expand Up @@ -186,28 +209,6 @@ export default function SolidRevolution({ params, title, caption }: TemplateProp
slice at x = {fmt(slice, 2)}
</text>
</svg>

<div className="mt-3 grid grid-cols-1 gap-2">
<div className="flex items-center gap-2">
<label htmlFor="solid-method" className="w-20 shrink-0 font-mono text-[10px] text-mathua-muted">
Method
</label>
<select
id="solid-method"
aria-label="Method"
value={mode}
onChange={(event) => setMode(event.target.value as SolidMode)}
className="h-7 min-w-0 flex-1 border border-mathua-border bg-transparent px-1 font-mono text-[10px] text-mathua-secondary"
>
{Object.entries(SOLID_LABELS).map(([value, label]) => (
<option key={value} value={value}>
{label}
</option>
))}
</select>
</div>
<Slider label="Slice position" value={slice} min={0.1} max={2} step={0.05} onChange={setSlice} />
</div>
</FigureFrame>
)
}
58 changes: 30 additions & 28 deletions web/next-app/components/visual/templates/UnitCircle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,36 @@ export default function UnitCircle({ params, title, caption }: TemplateProps) {
'A point on the unit circle has coordinates (cos θ, sin θ). The angle turns counterclockwise from the positive x-axis, and the same angle marks the sine and cosine values on the graph below. Adding 360° returns to the same point.'
}
onReset={reset}
controls={
<div className="space-y-2">
<Slider label="Angle" value={angle} min={-360} max={360} step={1} onChange={setAngle} suffix="°" />
<div className="flex items-center gap-2">
<label htmlFor="unit-circle-common-angle" className="shrink-0 font-mono text-xs text-mathua-muted">
Common angle
</label>
<select
id="unit-circle-common-angle"
aria-label="Common angle"
value={selectedAngle === undefined ? '' : String(selectedAngle)}
onChange={(event) => {
if (event.target.value !== '') setAngle(Number(event.target.value))
}}
className="h-10 min-w-0 border border-mathua-border bg-transparent px-2 font-mono text-xs text-mathua-secondary"
>
{selectedAngle === undefined && <option value="">Custom</option>}
{COMMON_ANGLES.map((value) => (
<option key={value} value={value}>
{value}°
</option>
))}
</select>
</div>
<div className="grid grid-cols-2 gap-2">
<Toggle label="Show sine" checked={showSin} onChange={setShowSin} />
<Toggle label="Show cosine" checked={showCos} onChange={setShowCos} />
</div>
</div>
}
readout={[
{ label: 'angle', value: angleLabel(angle) },
{ label: 'angle on circle', value: angleLabel(normalizedDegrees) },
Expand Down Expand Up @@ -264,34 +294,6 @@ export default function UnitCircle({ params, title, caption }: TemplateProps) {
</text>
</svg>

<div className="mt-3 space-y-2">
<Slider label="Angle" value={angle} min={-360} max={360} step={1} onChange={setAngle} suffix="°" />
<div className="flex items-center gap-2">
<label htmlFor="unit-circle-common-angle" className="shrink-0 font-mono text-[10px] text-mathua-muted">
Common angle
</label>
<select
id="unit-circle-common-angle"
aria-label="Common angle"
value={selectedAngle === undefined ? '' : String(selectedAngle)}
onChange={(event) => {
if (event.target.value !== '') setAngle(Number(event.target.value))
}}
className="h-7 min-w-0 border border-mathua-border bg-transparent px-1 font-mono text-[10px] text-mathua-secondary"
>
{selectedAngle === undefined && <option value="">Custom</option>}
{COMMON_ANGLES.map((value) => (
<option key={value} value={value}>
{value}°
</option>
))}
</select>
</div>
<div className="grid grid-cols-2 gap-2">
<Toggle label="Show sine" checked={showSin} onChange={setShowSin} />
<Toggle label="Show cosine" checked={showCos} onChange={setShowCos} />
</div>
</div>
</FigureFrame>
)
}
47 changes: 24 additions & 23 deletions web/next-app/components/visual/templates/VectorFieldLab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,30 @@ export default function VectorFieldLab({ params, title, caption }: TemplateProps
'Each arrow is the vector at its base. The circulation is the line integral around the red loop and the flux is the flow through it. Green\'s theorem says the circulation equals the enclosed area times the curl, and the divergence theorem says the flux equals the area times the divergence.'
}
onReset={reset}
controls={
<div className="grid grid-cols-1 gap-2">
<div className="flex items-center gap-2">
<label htmlFor="vector-field" className="w-20 shrink-0 font-mono text-xs text-mathua-muted">
Field
</label>
<select
id="vector-field"
aria-label="Field"
value={preset}
onChange={(event) => setPreset(event.target.value as VectorFieldPreset)}
className="h-10 min-w-0 flex-1 border border-mathua-border bg-transparent px-2 font-mono text-xs text-mathua-secondary"
>
{Object.entries(VF_NAMES).map(([value, label]) => (
<option key={value} value={value}>
{label} — {VF_LABELS[value as VectorFieldPreset]}
</option>
))}
</select>
</div>
<Slider label="Loop radius" value={radius} min={0.4} max={2} step={0.1} onChange={setRadius} />
<Toggle label="Show streamlines" checked={showLines} onChange={setShowLines} />
</div>
}
readout={[
{ label: 'field', value: `${VF_NAMES[preset]} · ${VF_LABELS[preset]}` },
{ label: 'divergence', value: fmt(div, 2) },
Expand Down Expand Up @@ -163,29 +187,6 @@ export default function VectorFieldLab({ params, title, caption }: TemplateProps
div {fmt(div, 2)} · curl {fmt(curl, 2)}
</text>
</svg>

<div className="mt-3 grid grid-cols-1 gap-2">
<div className="flex items-center gap-2">
<label htmlFor="vector-field" className="w-20 shrink-0 font-mono text-[10px] text-mathua-muted">
Field
</label>
<select
id="vector-field"
aria-label="Field"
value={preset}
onChange={(event) => setPreset(event.target.value as VectorFieldPreset)}
className="h-7 min-w-0 flex-1 border border-mathua-border bg-transparent px-1 font-mono text-[10px] text-mathua-secondary"
>
{Object.entries(VF_NAMES).map(([value, label]) => (
<option key={value} value={value}>
{label} — {VF_LABELS[value as VectorFieldPreset]}
</option>
))}
</select>
</div>
<Slider label="Loop radius" value={radius} min={0.4} max={2} step={0.1} onChange={setRadius} />
<Toggle label="Show streamlines" checked={showLines} onChange={setShowLines} />
</div>
</FigureFrame>
)
}
Loading