Skip to content

Commit d5fd365

Browse files
committed
Modified ui and code refactored
1 parent 72ec1bb commit d5fd365

File tree

4 files changed

+40
-9
lines changed

4 files changed

+40
-9
lines changed

base.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ class sortData {
55
}
66
selectionSort() {}
77
bubbleSort() {}
8+
stopSort() {
9+
return false;
10+
}
811
}
912

1013
//get selected algorithm

function.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ var svg,
1212

1313
// generating random data
1414
var data = randomData(maxElement, dataRange);
15-
15+
function setSpeed() {
16+
time = document.getElementById("speed").value;
17+
}
1618
//a d3 function for scaling height for all the data this function
1719
var heightScale = d3
1820
.scaleLinear()
@@ -84,7 +86,8 @@ Sort.bubbleSort = function () {
8486
data[j] = data[j + 1];
8587
data[j + 1] = temp;
8688
changeBarColor(data[j + 1], smallestColor);
87-
89+
var swooshAudio = new Audio("./sound-effects/swoosh.mp3");
90+
swooshAudio.play();
8891
swapBar(data);
8992
await timer(time);
9093
} else {
@@ -112,6 +115,7 @@ document.getElementById("sort").addEventListener("click", function () {
112115

113116
document.getElementById("random-data").addEventListener("click", function () {
114117
var data = randomData(maxElement, dataRange);
118+
Sort.stopSort();
115119
svg.remove();
116120
createChart(data);
117121
});

index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ <h1>Sorting Visualizer</h1>
2727
checked
2828
/>Bubble Sort</label
2929
>
30+
<br />
31+
<br />
32+
<label>
33+
Speed:
34+
<input
35+
type="range"
36+
id="speed"
37+
name="speed"
38+
min="100"
39+
max="1000"
40+
onchange="setSpeed()"
41+
/>
42+
</label>
3043
</form>
3144
</div>
3245
<div class="container">

style.css

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,36 @@
44
.container {
55
display: flex;
66
justify-content: center;
7-
height: 90vh;
87
align-items: center;
98
}
9+
.bar-chart {
10+
margin-top: 40px;
11+
background-color: #eee;
12+
padding: 50px 20px 30px 20px;
13+
box-shadow: rgba(100, 100, 111, 0.2) 0px 7px 29px 0px;
14+
}
1015

1116
h1 {
1217
text-align: center;
1318
font-family: sans-serif;
19+
padding: 0;
20+
margin: 30px 0 0 0;
1421
}
1522
button {
1623
display: block;
1724
margin: auto;
18-
margin-top: 30px;
25+
1926
padding: 5px 20px;
2027
background: steelblue;
2128
color: rgb(218, 238, 105);
22-
font-size: 20px;
29+
font-size: 15px;
2330
cursor: pointer;
31+
font-weight: 600;
2432
}
2533
button {
2634
margin: auto;
27-
margin-top: 50px;
28-
padding: 7px 30px;
35+
margin-top: 20px;
36+
padding: 2px 30px;
2937
border: none;
3038
}
3139

@@ -38,7 +46,7 @@ button {
3846
);
3947
}
4048
button {
41-
padding: 15px 45px;
49+
padding: 10px 30px;
4250
text-align: center;
4351
text-transform: uppercase;
4452
transition: 0.5s;
@@ -55,13 +63,16 @@ button:hover {
5563
text-decoration: none;
5664
}
5765
form {
58-
margin-top: 30px;
66+
margin-top: 20px;
5967
text-align: center;
6068
}
6169
label {
6270
font-size: 20px;
6371
cursor: pointer;
6472
}
73+
input {
74+
cursor: pointer;
75+
}
6576
rect:hover {
6677
cursor: pointer;
6778
}

0 commit comments

Comments
 (0)