11import { assert } from '@cutting/assert' ;
2- import { Box } from '@cutting/component-library' ;
2+ import { Box , RadioGroup } from '@cutting/component-library' ;
33import { ResponsiveSVG } from '@cutting/svg' ;
44import { useParentSize } from '@cutting/use-get-parent-size' ;
55import { MathJax } from '@cutting/use-mathjax' ;
@@ -9,11 +9,12 @@ import { scaleLinear } from '@visx/scale';
99import { LinePath } from '@visx/shape' ;
1010import { extent } from 'd3-array' ;
1111import { parse } from 'mathjs' ;
12- import { useLayoutEffect , useMemo , useReducer , useRef } from 'react' ;
12+ import { useLayoutEffect , useMemo , useReducer , useRef , useState } from 'react' ;
1313
1414import { ApplicationLayout } from '~/layouts/ApplicationLayout' ;
1515
1616import * as styles from './Polar.css' ;
17+ import type { PolarEffect } from './reducer' ;
1718import { initialState , reducer } from './reducer' ;
1819
1920export function Polar ( ) : JSX . Element {
@@ -23,6 +24,7 @@ export function Polar(): JSX.Element {
2324 initialValues : { width : 0 , height : 0 } ,
2425 } ) ;
2526 const tickFrame = useRef < number > ( undefined ) ;
27+ const [ polarEffect , setPolarEffect ] = useState < PolarEffect > ( 'butterfly' ) ;
2628
2729 const [ state , dispatch ] = useReducer ( reducer , initialState ) ;
2830
@@ -49,8 +51,9 @@ export function Polar(): JSX.Element {
4951 } , [ state . bucket , width , height ] ) ;
5052
5153 useLayoutEffect ( ( ) => {
52- dispatch ( { type : 'SET_EXPRESSION' , payload : { expression : state . expression } } ) ;
53- } , [ state . expression ] ) ;
54+ dispatch ( { type : 'SET_POLAR_EFFECT' , payload : { polarEffect } } ) ;
55+ } , [ polarEffect , state . expression ] ) ;
56+
5457 useLayoutEffect ( ( ) => {
5558 if ( state . time === 0 ) {
5659 return ;
@@ -75,9 +78,31 @@ export function Polar(): JSX.Element {
7578 }
7679
7780 return (
78- < ApplicationLayout heading = "The Polar Express! " showFooter = { false } >
81+ < ApplicationLayout heading = "The Polar Express" showFooter = { false } >
7982 < section ref = { containerRef } className = { styles . container } >
80- < Box display = "flex" justifyContent = "center" >
83+ < Box display = "flex" justifyContent = { { mobile : 'flexStart' , tablet : 'spaceBetween' } } >
84+ < RadioGroup < PolarEffect >
85+ legend = "Trigonometric Function"
86+ legendMode = "screen-reader-only"
87+ name = "theme"
88+ checkableLayout = "inline"
89+ checkableSize = { 'large' }
90+ onChange = { ( o ) => {
91+ setPolarEffect ( o . target . value as PolarEffect ) ;
92+ } }
93+ options = { [
94+ {
95+ value : 'butterfly' ,
96+ content : 'Butterfly' ,
97+ checked : polarEffect === 'butterfly' ,
98+ } ,
99+ {
100+ value : 'rose' ,
101+ content : 'Rose' ,
102+ checked : polarEffect === 'rose' ,
103+ } ,
104+ ] }
105+ />
81106 < MathJax className = { styles . expression } > { `$ r = ${ parse ( state . expression ) . toTex ( ) } $` } </ MathJax >
82107 </ Box >
83108 < ResponsiveSVG width = { width } height = { height } overflow = "hidden" className = "polar-svg" >
0 commit comments