Skip to content

Commit 651d663

Browse files
author
Kenneth Apeland
committed
Merge branch 'master' of https://github.com/kennidenni/INF219
2 parents 4fc5b24 + d0451d9 commit 651d663

File tree

12 files changed

+100
-22
lines changed

12 files changed

+100
-22
lines changed

Heap/js/Controller.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ var Controller = /** @class */ (function () {
3838
Controller.prototype.getAlgorithm = function () {
3939
return this.algorithm;
4040
};
41+
Controller.prototype.lockScreen = function (b) {
42+
viewer.screenLockThis(b);
43+
};
4144
/**
4245
* Remove the maximum/minimum element
4346
*/

Heap/js/Controller.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ class Controller {
4949
return this.algorithm;
5050
}
5151

52+
lockScreen(b: boolean) {
53+
viewer.screenLockThis(b);
54+
}
55+
5256
/**
5357
* Remove the maximum/minimum element
5458
*/

Heap/js/HeapSort.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ var HeapSort = /** @class */ (function (_super) {
3030
HeapSort.prototype.remove = function () {
3131
// Remove root element, set last element to root and start frontendevents
3232
this.currIndex--;
33+
control.setSelectedIndex(0, true);
34+
control.highlightNode(0, "orange");
3335
control.highlightSortElem(this.sortIndex, "orange");
3436
control.setValueAtSortIndex(this.sortIndex, this.array[0]);
37+
control.setSelectedIndex(0, false);
3538
this.exch(0, this.currIndex);
3639
control.swapNode(this.currIndex, 0);
3740
control.removeElem(this.currIndex, false);

Heap/js/HeapSort.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ class HeapSort extends MaxHeap {
2323

2424
remove(): void {
2525
// Remove root element, set last element to root and start frontendevents
26-
this.currIndex--;
26+
this.currIndex--
27+
control.setSelectedIndex(0, true);
28+
control.highlightNode(0, "orange");
2729
control.highlightSortElem(this.sortIndex, "orange");
2830
control.setValueAtSortIndex(this.sortIndex, this.array[0]);
31+
control.setSelectedIndex(0, false);
2932
this.exch(0, this.currIndex);
3033
control.swapNode(this.currIndex, 0);
3134
control.removeElem(this.currIndex, false);

Heap/js/MaxHeap.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,25 @@ var MaxHeap = /** @class */ (function () {
9494
};
9595
MaxHeap.prototype.add = function (a) {
9696
// Add to array and start frontendevents
97+
control.lockScreen(true);
9798
this.array.push(a);
9899
insertNewElem(this.array.length - 1, a); // Create element in frontendarray
99100
insertNewElemConnect(this.array.length - 1, Math.floor((this.array.length - 2) / 2));
100101
control.saveState(this.array); // Save the new state
101102
// Swim to te correct index and start frontendevents
102103
this.swim(this.array.length - 1);
104+
control.lockScreen(false);
103105
};
104106
MaxHeap.prototype.remove = function () {
107+
control.lockScreen(true);
105108
// Remove root element, set last element to root and start frontendevents
106109
this.exch(0, this.array.length - 1);
107110
control.swapNode(this.array.length - 1, 0);
108111
control.removeElem(this.array.length - 1, true);
109112
this.array.pop();
110113
control.saveState(this.array);
111114
this.sink(0, this.array.length - 1);
115+
control.lockScreen(false);
112116
};
113117
MaxHeap.prototype.sink = function (index, length) {
114118
var left = index * 2 + 1;

Heap/js/MaxHeap.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,23 +114,27 @@ class MaxHeap implements IAlgorithm {
114114

115115
add(a: number): void {
116116
// Add to array and start frontendevents
117+
control.lockScreen(true)
117118
this.array.push(a);
118119
insertNewElem(this.array.length - 1, a); // Create element in frontendarray
119120
insertNewElemConnect(this.array.length - 1, Math.floor((this.array.length - 2) / 2));
120121
control.saveState(this.array); // Save the new state
121122

122123
// Swim to te correct index and start frontendevents
123124
this.swim(this.array.length - 1);
125+
control.lockScreen(false);
124126
}
125127

126128
remove(): void {
129+
control.lockScreen(true);
127130
// Remove root element, set last element to root and start frontendevents
128131
this.exch(0, this.array.length - 1);
129132
control.swapNode(this.array.length - 1, 0);
130133
control.removeElem(this.array.length - 1, true);
131134
this.array.pop();
132135
control.saveState(this.array);
133136
this.sink(0, this.array.length - 1);
137+
control.lockScreen(false);
134138
}
135139

136140
protected sink(index: number, length: number): void {

Heap/js/View.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ var View = /** @class */ (function () {
149149
};
150150
View.prototype.resetAll = function () {
151151
this.paused = false;
152+
manager.pause();
153+
manager.nextEvents = new Array;
154+
manager.previousEvents = new Array;
155+
screenLock(false);
152156
var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
153157
stepper = new StateController(control, this);
154158
this.resetArray(arr);
@@ -174,12 +178,22 @@ var View = /** @class */ (function () {
174178
};
175179
View.prototype.setSlow = function () {
176180
this.animSpeed = 250;
181+
manager.delayTime = 900;
182+
this.restartManager();
177183
};
178184
View.prototype.setMedium = function () {
179-
this.animSpeed = 500;
185+
this.animSpeed = 600;
186+
manager.delayTime = 600;
187+
this.restartManager();
180188
};
181189
View.prototype.setFast = function () {
182-
this.animSpeed = 750;
190+
this.animSpeed = 300;
191+
manager.delayTime = 300;
192+
this.restartManager();
193+
};
194+
View.prototype.restartManager = function () {
195+
manager.pause();
196+
manager.start();
183197
};
184198
View.prototype.switchAlgorithm = function (algo) {
185199
$("#sortArray").hide();
@@ -198,12 +212,14 @@ var View = /** @class */ (function () {
198212
case "BuildHeap": {
199213
this.resetAll();
200214
control.initController(new BuildHeap(10));
215+
screenLock(true);
201216
break;
202217
}
203218
case "HeapSort": {
204219
this.resetAll();
205220
$("#sortArray").show();
206221
control.initController(new HeapSort(10));
222+
screenLock(true);
207223
break;
208224
}
209225
default: {

Heap/js/View.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ class View implements IView {
187187

188188
resetAll() {
189189
this.paused = false;
190+
manager.pause();
191+
manager.nextEvents = new Array;
192+
manager.previousEvents = new Array;
193+
screenLock(false);
190194
let arr: number[] = [1, 2, 3, 4, 5, 6, 7, 8, 9];
191195
stepper = new StateController(control, this);
192196
this.resetArray(arr);
@@ -215,14 +219,25 @@ class View implements IView {
215219

216220
setSlow() {
217221
this.animSpeed = 250;
222+
manager.delayTime = 900;
223+
this.restartManager();
218224
}
219225

220226
setMedium() {
221-
this.animSpeed = 500;
227+
this.animSpeed = 600;
228+
manager.delayTime = 600;
229+
this.restartManager();
222230
}
223231

224232
setFast() {
225-
this.animSpeed = 750;
233+
this.animSpeed = 300;
234+
manager.delayTime = 300;
235+
this.restartManager();
236+
}
237+
238+
restartManager() {
239+
manager.pause();
240+
manager.start();
226241
}
227242

228243
switchAlgorithm(algo: string) {
@@ -242,12 +257,14 @@ class View implements IView {
242257
case "BuildHeap": {
243258
this.resetAll();
244259
control.initController(new BuildHeap(10));
260+
screenLock(true);
245261
break;
246262
}
247263
case "HeapSort": {
248264
this.resetAll();
249265
$("#sortArray").show();
250266
control.initController(new HeapSort(10));
267+
screenLock(true);
251268
break;
252269
}
253270
default: {

Heap/js/drawHeap.js

Whitespace-only changes.

Heap/js/drawHeap.ts

Whitespace-only changes.

0 commit comments

Comments
 (0)