Skip to content

Commit cc54e29

Browse files
committed
options implemented
1 parent 02bf2d9 commit cc54e29

9 files changed

Lines changed: 449 additions & 26 deletions

File tree

‎package-lock.json‎

Lines changed: 333 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"react-dom": "^18.2.0",
1111
"react-router": "^6.3.0",
1212
"react-router-dom": "^6.3.0",
13+
"rsuite": "^5.16.0",
1314
"web-vitals": "^2.1.4"
1415
},
1516
"devDependencies": {

‎src/App.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class App extends Component {
3131

3232
render() {
3333

34-
3534
return (
3635
<>
3736
<Router>

‎src/components/Canvas/MainCanvas.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class MainCanvas extends Component {
1616
generatedArray: InputHandler.getGeneratedArray,
1717
inputArrayLength: InputHandler.getGeneratedArray.length,
1818
options: {
19-
showAdvancedOptions: false,
19+
delay: 4,
20+
skipJ: false,
2021
processingColor: CONSTANTS.PROCESSING[0],
2122
defaultBarColor: CONSTANTS.DEFAULT[0],
2223
sortedBarColor: CONSTANTS.SORTED[0],
@@ -31,7 +32,7 @@ class MainCanvas extends Component {
3132

3233
render() {
3334
const {options} = this.state;
34-
35+
console.log(options);
3536
return (
3637
<>
3738
<InputField name = {['generic-input', 'instructions']} InputHandler = {this}/>

‎src/components/Canvas/options/Options.js‎

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,41 @@
11
import SlideBar from './SlideBar';
2+
import './style.css'
23
import React, { Component } from 'react'
34
import { ReactComponent as ArrowDown } from '../../../img/arrowDown.svg'
45
import { ReactComponent as CPU } from '../../../img/cpu.svg'
56
import { ReactComponent as UnsortedBars } from '../../../img/unsortedBars.svg'
67
import { ReactComponent as SortedBars } from '../../../img/sortedBars.svg'
8+
import { ReactComponent as Runner } from '../../../img/running.svg'
9+
import { ReactComponent as Speed } from '../../../img/Speed.svg'
710
import { ReactComponent as Key } from '../../../img/key.svg'
811
import { CONSTANTS } from '../../../config'
12+
13+
14+
915
class Options extends Component {
1016
constructor(props) {
1117
super(props);
1218
this.state = {
13-
showAdvanvedOptions: false,
1419
showProcessingColor: false,
1520
showDefaultBarColor: false,
1621
showSortedBarColor: false,
1722
showMinBarColor: false,
23+
showDelay: false,
1824
}
1925

2026
}
2127
render() {
22-
const {showAdvancedOptions, showProcessingColor, showDefaultBarColor, showSortedBarColor, showMinBarColor} = this.state;
23-
28+
const {showProcessingColor, showDefaultBarColor, showSortedBarColor, showMinBarColor, showDelay } = this.state;
29+
const style = {
30+
height: 400
31+
};
2432
return (
2533
<div className="rounded-md">
2634

2735
<div className="w-fit flex space-x-5">
2836

2937
<div className="flex flex-col items-center relative space-y-2">
30-
<div className="p-2 hover:bg-gray-200 rounded-md" onClick={() => this.setState({showDefaultBarColor: !showDefaultBarColor})}>
38+
<div className="p-2 hover:bg-gray-200 rounded-md peer" onClick={() => this.setState({showDefaultBarColor: !showDefaultBarColor})}>
3139
<UnsortedBars className="scale-[1.2]"/>
3240
</div>
3341
<div className={`h-3 w-3 rounded-full`} style={{backgroundColor: this.props.options.state.options.defaultBarColor}}/>
@@ -44,10 +52,11 @@ class Options extends Component {
4452
}/>
4553
))}
4654
</div>
55+
<p className={`bg-white z-10 inline absolute top-[100%] border-2 p-1 rounded-md hidden peer-hover:block tool-tip-options`}><p className="font-bold">Unsorted</p> bars color</p>
4756
</div>
4857

4958
<div className="flex flex-col items-center relative space-y-2">
50-
<div className="p-2 hover:bg-gray-200 rounded-md" onClick={() => this.setState({showSortedBarColor: !showSortedBarColor})}>
59+
<div className="p-2 hover:bg-gray-200 peer rounded-md" onClick={() => this.setState({showSortedBarColor: !showSortedBarColor})}>
5160
<SortedBars className="scale-[1.2]"/>
5261
</div>
5362
<div className={`h-3 w-3 rounded-full`} style={{backgroundColor: this.props.options.state.options.sortedBarColor}}/>
@@ -64,11 +73,12 @@ class Options extends Component {
6473
}/>
6574
))}
6675
</div>
76+
<p className={`bg-white inline z-10 absolute top-[100%] border-2 p-1 rounded-md hidden peer-hover:block tool-tip-options`}><p className="font-bold">Sorted</p> bars color</p>
6777
</div>
6878

6979

7080
<div className="flex flex-col items-center relative space-y-2">
71-
<div className="p-2 hover:bg-gray-200 rounded-md" onClick={() => this.setState({showProcessingColor: !showProcessingColor})}>
81+
<div className="p-2 hover:bg-gray-200 peer rounded-md" onClick={() => this.setState({showProcessingColor: !showProcessingColor})}>
7282
<CPU className="scale-[1.2]"/>
7383
</div>
7484
<div className={`h-3 w-3 rounded-full`} style={{backgroundColor: this.props.options.state.options.processingColor}}/>
@@ -85,11 +95,12 @@ class Options extends Component {
8595
}/>
8696
))}
8797
</div>
98+
<p className={`bg-white inline z-10 absolute top-[100%] border-2 p-1 rounded-md hidden peer-hover:block tool-tip-options`}><p className="font-bold">Processing</p> bars color</p>
8899
</div>
89100

90101

91102
<div className="flex flex-col items-center relative space-y-2">
92-
<div className="p-2 hover:bg-gray-200 rounded-md" onClick={() => this.setState({showMinBarColor: !showMinBarColor})}>
103+
<div className="p-2 hover:bg-gray-200 peer rounded-md" onClick={() => this.setState({showMinBarColor: !showMinBarColor})}>
93104
<Key className="scale-[1.2]"/>
94105
</div>
95106
<div className={`h-3 w-3 rounded-full`} style={{backgroundColor: this.props.options.state.options.currentMinBarColor}}/>
@@ -106,15 +117,42 @@ class Options extends Component {
106117
}/>
107118
))}
108119
</div>
120+
<p className={`bg-white inline z-10 absolute top-[100%] border-2 p-1 rounded-md hidden peer-hover:block tool-tip-options`}><p className="font-bold">Minimum</p> bar color</p>
109121
</div>
110122

111-
112123

113-
124+
<div className="flex flex-col items-center relative space-y-2">
125+
<div className="p-2 hover:bg-gray-200 peer rounded-md" onClick={() => this.setState({showDelay: !showDelay})}>
126+
<Speed className="scale-[1.2]"/>
127+
</div>
128+
<p className="font-semibold text-gray-500">{this.props.options.state.options?.delay}ms</p>
129+
<div className={`absolute bg-white p-2 rounded-md border-2 top-[100%] space-y-1 ${showDelay ? "block" : "hidden"}`}>
130+
<div className="flex flex-col items-center justify-center">
131+
<SlideBar mainCanvas={this.props.options}/>
132+
<p className="">{this.props.options.state.options?.delay}</p>
133+
</div>
134+
</div>
135+
<p className={`bg-white inline z-10 absolute top-[100%] border-2 p-1 rounded-md hidden peer-hover:block tool-tip-options`}>Animation Speed</p>
136+
</div>
137+
114138

115-
116139

140+
<div className="flex flex-col items-center relative space-y-2">
141+
<div className={`p-2 hover:bg-gray-200 peer rounded-md`} onClick={() => {
142+
this.props.options.setState(prev => ({options: {...prev.options, skipJ: !this.props.options.state.options.skipJ}}))
143+
144+
}}>
145+
<Runner className="scale-[1.2]"/>
146+
</div>
147+
<p className="font-semibold text-gray-500">{this.props.options.state.options.skipJ ? "ON" : "OFF"}</p>
148+
<p className={`bg-white inline z-10 absolute top-[100%] border-2 p-1 rounded-md hidden peer-hover:block tool-tip-options`}>Faster Animation</p>
149+
</div>
150+
151+
152+
117153

154+
155+
118156

119157

120158
{/* <p>Default bar color</p>

‎src/components/Canvas/options/SlideBar.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useState } from 'react'
22

33
function SlideBar(props) {
44
const [value, setValue] = useState(0);
5-
const MAX = 30;
5+
const MAX = 51;
66
const getBackgroundSize = () => {
77
return {
88
backgroundSize: `${(value * 100) / MAX}% 100%`,
@@ -17,7 +17,7 @@ function SlideBar(props) {
1717
max={MAX}
1818
onChange={(e) => {
1919
setValue(e.target.value)
20-
props.mainCanvas.setState({options: {delay: value}})
20+
props.mainCanvas.setState(prev => ({options: {...prev.options, delay: value, }}))
2121
}}
2222
style={getBackgroundSize()}
2323
value={value}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
.tool-tip-options::after {
2+
content: "";
3+
position: absolute;
4+
top: -20px;
5+
left: 50%;
6+
transform: translate(-50%, 0);
7+
width: 10px;
8+
height: 10px;
9+
border-style: solid;
10+
border-width: 10px;
11+
border-color: transparent transparent #E5E7EB transparent;
12+
}
13+
14+
15+
.horizontal-slider {
16+
17+
}
18+
.example-thumb {
19+
cursor: pointer;
20+
position: absolute;
21+
z-index: 100;
22+
background: #ffffff;
23+
border: 5px solid #3774ff;
24+
border-radius: 100%;
25+
display: block;
26+
box-shadow: 0 0 2px 0 rgb(0 0 0 / 44%);
27+
}
28+
.example-thumb.active {
29+
background-color: grey;
30+
}
31+
.example-track {
32+
position: relative;
33+
background: #ddd;
34+
}
35+
.example-track.example-track-0 {
36+
background: #83a9ff;
37+
}
38+
.horizontal-slider .example-track {
39+
top: 20px;
40+
height: 4px;
41+
}
42+
.horizontal-slider .example-thumb {
43+
top: 12px;
44+
width: 10px;
45+
outline: none;
46+
height: 10px;
47+
line-height: 38px;
48+
}

‎src/components/Strategy/Algorithms/SelectionSort.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ export default class SelectionSort {
4040
}
4141

4242
// SG 07/08/2022 15:01 animation for j iteration - can be removed for faster animation
43-
await Animation.getAnimation(this._delay);
43+
if(!options.skipJ) {
44+
await Animation.getAnimation(this._delay);
45+
}
4446

4547
var currentMinBar = parseInt(unSortedBars[minBarIndex].id);
4648
var currentNum = parseInt(unSortedBars[j].id);
4749

48-
50+
4951
// SG 07/07/2022 21:19 fins min value in the rest of the array
5052
if (currentNum < currentMinBar) {
5153
if (minBarIndex !== i) {

‎src/img/Speed.svg‎

Lines changed: 10 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)