Skip to content

Commit 45feeb6

Browse files
Merge pull request #8 from danilhendrasr/refine-ui
Refined UI
2 parents 3d63fee + 90bdd07 commit 45feeb6

24 files changed

+340
-276
lines changed

algorithms-helper/bubble-sort.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ACTIVE_BAR_COLOR, INACTIVE_BAR_COLOR, SORTING_SPEED } from "../constants"
1+
import { ACTIVE_BAR_COLOR, INACTIVE_BAR_COLOR } from "../constants"
22
import {
33
changeBarsColor,
44
getAllBars,
@@ -42,7 +42,11 @@ const bubbleSort = (array: number[]): [number, number][] => {
4242
return animaSeq
4343
}
4444

45-
export const animateBubbleSort = (barHeights: number[], callback?: () => void): void => {
45+
export const animateBubbleSort = (
46+
barHeights: number[],
47+
sortingSpeed: number,
48+
callback?: () => void
49+
): void => {
4650
const animationSequence = bubbleSort(barHeights)
4751
const bars = getAllBars()
4852

@@ -74,6 +78,6 @@ export const animateBubbleSort = (barHeights: number[], callback?: () => void):
7478
postSortAnimation(bars, ACTIVE_BAR_COLOR)
7579
callback()
7680
}
77-
}, iteration * SORTING_SPEED)
81+
}, iteration * sortingSpeed)
7882
})
7983
}

algorithms-helper/insertion-sort.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { INACTIVE_BAR_COLOR, SORTING_SPEED, ACTIVE_BAR_COLOR } from "../constants"
1+
import { INACTIVE_BAR_COLOR, ACTIVE_BAR_COLOR } from "../constants"
22
import { getAllBars, changeBarsColor, makeBarsActive, postSortAnimation } from "../utils"
33

44
interface InsertionAnimationSequence {
@@ -54,6 +54,7 @@ const insertionSort = (arrayToSort: number[]): InsertionAnimationSequence[] => {
5454

5555
export const animateInsertionSort = (
5656
barHeights: number[],
57+
sortingSpeed: number,
5758
callback?: () => void
5859
): void => {
5960
const animationSequence = insertionSort(barHeights)
@@ -77,7 +78,7 @@ export const animateInsertionSort = (
7778

7879
prevIdxBarHeights.push(bars[idxToInsertTo].style.height)
7980
makeBarsActive([{ element: bars[idxToInsertTo], height: barHeights[barToMove] }])
80-
}, i * SORTING_SPEED)
81+
}, i * sortingSpeed)
8182

8283
for (let x = 1; x <= rightShift; x++) {
8384
setTimeout(() => {
@@ -90,7 +91,7 @@ export const animateInsertionSort = (
9091
postSortAnimation(bars, ACTIVE_BAR_COLOR)
9192
if (callback) callback()
9293
}
93-
}, i * SORTING_SPEED)
94+
}, i * sortingSpeed)
9495
}
9596
}
9697
}

algorithms-helper/selection-sort.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const selectionSort = (inputArray: number[]): [number[][], [number, number][]] =
4646

4747
export const animateSelectionSort = (
4848
barHeights: number[],
49+
sortingSpeed: number,
4950
callback?: () => void
5051
): void => {
5152
const [arrayStates, animationSequence] = selectionSort(barHeights)
@@ -98,8 +99,8 @@ export const animateSelectionSort = (
9899
// to get executed.
99100
postSortAnimation(bars, ACTIVE_BAR_COLOR)
100101
if (callback) callback()
101-
}, SORTING_SPEED)
102+
}, sortingSpeed)
102103
}
103-
}, i * SORTING_SPEED)
104+
}, i * sortingSpeed)
104105
}
105106
}

components/AlgorithmSelector.tsx

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
import { Select } from "@geist-ui/react"
1+
import { Select, Text, Spacer } from "@geist-ui/react"
22
import { SortingAlgorithms } from "../types"
33

4+
// @ts-ignore
5+
import styles from "../styles/Home.module.scss"
6+
47
const algorithms: SortingAlgorithms[] = ["Selection", "Insertion", "Bubble"]
58

6-
export const AlgorithmSelector: React.FC<{
9+
interface Props {
710
disabled: boolean
811
selectedAlgorithm: string | string[]
912
onChangeHandler: (algorithm: string | string[]) => void
10-
}> = (props) => {
13+
}
14+
15+
export const AlgorithmSelector: React.FC<Props> = (props) => {
1116
let { disabled, selectedAlgorithm, onChangeHandler } = props
1217

1318
const selectOptions = algorithms.map((algorithm, idx) => (
@@ -17,11 +22,16 @@ export const AlgorithmSelector: React.FC<{
1722
))
1823

1924
return (
20-
<Select
21-
disabled={disabled}
22-
onChange={(algorithm) => onChangeHandler(algorithm)}
23-
initialValue={selectedAlgorithm}>
24-
{selectOptions}
25-
</Select>
25+
<div className={styles.sideBarInputContainer}>
26+
<Text>Select Algorithm</Text>
27+
<Spacer y={-0.4} />
28+
<Select
29+
disabled={disabled}
30+
value={selectedAlgorithm}
31+
onChange={(algorithm) => onChangeHandler(algorithm)}
32+
size="large">
33+
{selectOptions}
34+
</Select>
35+
</div>
2636
)
2737
}

components/AppTitle.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Text } from "@geist-ui/react"
2+
3+
// @ts-ignore
4+
import styles from "../styles/Home.module.scss"
5+
6+
export const AppTitle: React.FC = () => {
7+
return (
8+
<Text h1 size="2em" className={styles.textCenter}>
9+
Sorting Algorithms Visualizer
10+
</Text>
11+
)
12+
}

components/ArrayLengthModifier.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Text, Slider } from "@geist-ui/react"
2+
3+
// @ts-ignore
4+
import styles from "../styles/Home.module.scss"
5+
6+
interface Props {
7+
disabled: boolean
8+
value: number
9+
onChange: (value: number) => void
10+
}
11+
12+
export const ArrayLengthModifier: React.FC<Props> = (props): JSX.Element => {
13+
const { disabled, value, onChange } = props
14+
15+
return (
16+
<div className={styles.sideBarInputContainer}>
17+
<Text>Length of array</Text>
18+
<Slider
19+
disabled={disabled}
20+
max={100}
21+
min={10}
22+
onChange={onChange}
23+
showMarkers
24+
step={10}
25+
value={value}
26+
/>
27+
</div>
28+
)
29+
}

components/Bar.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@ import { useTheme } from "@geist-ui/react"
22

33
export const Bar: React.FC<{
44
height: number
5-
elRef: (element: HTMLDivElement) => void
5+
width: number
66
}> = (props) => {
7-
const { height, elRef } = props
7+
const { height, width } = props
88

99
const { palette } = useTheme()
1010

1111
const barStylings: React.CSSProperties = {
1212
height: `${height}%`,
1313
backgroundColor: palette.errorLight,
14-
width: "5px",
15-
marginRight: 5,
14+
width: width,
15+
borderTopLeftRadius: 5,
16+
borderTopRightRadius: 5,
1617
}
1718

18-
return <div className="bar" style={barStylings} ref={elRef}></div>
19+
return <div className="bar" style={barStylings}></div>
1920
}

components/ChartWrapper.tsx

Lines changed: 0 additions & 15 deletions
This file was deleted.

components/Footer.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Text } from "@geist-ui/react"
2+
3+
export const Footer: React.FC = () => {
4+
return (
5+
<Text size=".7em">&copy; {new Date().getFullYear()} - Danil Hendra Suryawan</Text>
6+
)
7+
}

components/LinkToRepo.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Github } from "@geist-ui/react-icons"
2+
3+
// @ts-ignore
4+
import styles from "../styles/Home.module.scss"
5+
6+
export const LinkToRepo: React.FC = (props) => {
7+
return (
8+
<a
9+
className={styles.githubIconWrapper}
10+
href="https://github.com/danilhendrasr/sorting-visualizer"
11+
target="_blank">
12+
<Github size={20} color="#000" />
13+
</a>
14+
)
15+
}

0 commit comments

Comments
 (0)