11import {
22 BarChart ,
3- Brush ,
4- MusicNote ,
5- MusicOff ,
3+ Edit ,
4+ EditOff ,
65 PlayCircle ,
76 Refresh ,
87 StopCircle ,
8+ VolumeOff ,
9+ VolumeUp ,
910} from '@mui/icons-material' ;
1011import {
1112 Toolbar ,
@@ -30,6 +31,16 @@ type AppBarButtonProps = {
3031 icon : React . ReactElement ;
3132} & ButtonProps ;
3233
34+ const formatNumber = ( n : number ) => {
35+ if ( n > 10000 ) {
36+ return ( n / 1000 ) . toFixed ( 0 ) + 'k' ;
37+ }
38+ if ( n > 1000 ) {
39+ return ( n / 1000 ) . toFixed ( 1 ) + 'k' ;
40+ }
41+ return n ;
42+ } ;
43+
3344const AppBarButton = ( {
3445 isCompact,
3546 icon,
@@ -88,33 +99,34 @@ export function SortAppBar({
8899 return (
89100 < AppBar position = "relative" >
90101 < Toolbar variant = "dense" className = "toolbar" onClick = { onClick } >
91- < div >
102+ < Grid2
103+ container
104+ spacing = { isM ? 1 : 2 }
105+ sx = { { flexWrap : 'nowrap' , flexShrink : 0 } }
106+ >
92107 < AppBarButton
93108 isCompact = { isM }
94109 text = "Sort"
95110 icon = { sortIcon }
96111 onClick = { ( ) => startSorting ( arr ) }
97112 />
98- </ div >
99- < div >
100113 < AppBarButton
101114 isCompact = { isM }
102115 text = "Shuffle"
103116 icon = { < BarChart /> }
104117 onClick = { shuffleAndRedraw }
105118 />
106- </ div >
107- < div >
108119 < AppBarButton
109120 isCompact = { isM }
110121 text = "Reset"
111122 icon = { < Refresh /> }
112123 onClick = { resetAndDraw }
113124 />
114- </ div >
125+ </ Grid2 >
115126 < Grid2
116127 container
117128 direction = "row"
129+ spacing = { isSm ? 0 : 1 }
118130 sx = { { flexWrap : 'nowrap' , alignItems : 'center' , flexShrink : 0 } }
119131 >
120132 < FormControlLabel
@@ -124,11 +136,11 @@ export function SortAppBar({
124136 onChange = { toggleCanDraw }
125137 name = "canDraw"
126138 color = "secondary"
127- icon = { < Brush /> }
128- checkedIcon = { < Brush /> }
139+ icon = { < EditOff /> }
140+ checkedIcon = { < Edit /> }
129141 />
130142 }
131- sx = { { marginRight : isSm ? '0px' : undefined , marginLeft : '0px' } }
143+ sx = { { marginRight : '0px' , marginLeft : '0px' } }
132144 label = { ! isSm ? 'Draw Mode' : '' }
133145 slotProps = { { typography : { whiteSpace : 'nowrap' } } }
134146 />
@@ -139,20 +151,29 @@ export function SortAppBar({
139151 onChange = { togglePlaySound }
140152 name = "shouldPlaySound"
141153 color = "secondary"
142- icon = { < MusicOff /> }
143- checkedIcon = { < MusicNote /> }
154+ icon = { < VolumeOff /> }
155+ checkedIcon = { < VolumeUp /> }
144156 />
145157 }
146- sx = { { marginRight : isSm ? '0px' : undefined , marginLeft : '0px' } }
158+ sx = { { marginRight : '0px' , marginLeft : '0px' } }
147159 label = { ! isSm ? 'Play Sound' : '' }
148160 slotProps = { { typography : { whiteSpace : 'nowrap' } } }
149161 />
150162 </ Grid2 >
151- < div >
152- < Typography className = "counter" align = "left" color = "white" noWrap >
153- { ! isM ? 'Swaps:' : 'S:' } { ' ' }
163+ < Grid2
164+ container
165+ direction = "row"
166+ spacing = { isM ? 1 : 2 }
167+ sx = { { flexWrap : 'nowrap' } }
168+ >
169+ < Typography className = "counter" align = "left" noWrap >
170+ { ! isSm ? 'Swaps:' : 'S:' } { ' ' }
154171 { swapTime || ! isSorting ? (
155- nbrOfSwaps
172+ isM ? (
173+ formatNumber ( nbrOfSwaps )
174+ ) : (
175+ nbrOfSwaps
176+ )
156177 ) : (
157178 < CircularProgress
158179 className = "counter-spinner"
@@ -162,12 +183,14 @@ export function SortAppBar({
162183 />
163184 ) }
164185 </ Typography >
165- </ div >
166- < div >
167- < Typography className = "counter" align = "left" color = "white" noWrap >
168- { ! isM ? 'Comparisons:' : 'C:' } { ' ' }
186+ < Typography className = "counter" align = "left" noWrap >
187+ { ! isM ? 'Comparisons:' : ! isSm ? 'Comp:' : 'C:' } { ' ' }
169188 { compareTime || ! isSorting ? (
170- nbrOfComparisons
189+ isM ? (
190+ formatNumber ( nbrOfComparisons )
191+ ) : (
192+ nbrOfComparisons
193+ )
171194 ) : (
172195 < CircularProgress
173196 className = "counter-spinner"
@@ -177,12 +200,14 @@ export function SortAppBar({
177200 />
178201 ) }
179202 </ Typography >
180- </ div >
181- < div >
182- < Typography className = "counter" align = "left" color = "white" noWrap >
183- { ! isM ? 'Aux. writes:' : 'AW:' } { ' ' }
203+ < Typography className = "counter" align = "left" noWrap >
204+ { ! isM ? 'Aux. writes:' : ! isSm ? 'A. writes:' : 'AW:' } { ' ' }
184205 { auxWriteTime || ! isSorting ? (
185- nbrOfAuxWrites
206+ isM ? (
207+ formatNumber ( nbrOfAuxWrites )
208+ ) : (
209+ nbrOfAuxWrites
210+ )
186211 ) : (
187212 < CircularProgress
188213 className = "counter-spinner"
@@ -192,7 +217,7 @@ export function SortAppBar({
192217 />
193218 ) }
194219 </ Typography >
195- </ div >
220+ </ Grid2 >
196221 < IconButton
197222 color = "inherit"
198223 aria-label = "open drawer"
0 commit comments