Skip to content

Commit 3c78141

Browse files
author
Kenneth Apeland
committed
Merge branch 'master' of https://github.com/kennidenni/INF219
2 parents ae51d4a + 383e607 commit 3c78141

22 files changed

+453
-412
lines changed

Heap/js/Controller.js

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
/**
2-
* File created by Kenneth Apeland 03.02.18.
2+
* File created by Øyvind Liland on 22.02.18.
33
*/
44
///<reference path="View.ts"/>
55
///<reference path="IAlgorithm.ts"/>
66
///<reference path="EventManager.ts"/>
77
///<reference path="IView.ts"/>
88
///<reference path="methods.ts"/>
99
///<reference path="MaxHeapFree.ts"/>
10-
var iColor = 2;
11-
var jColor = 0;
1210
var Controller = /** @class */ (function () {
1311
function Controller() {
14-
this.methodToUse = "Union";
1512
}
1613
Controller.prototype.initController = function (algo) {
1714
this.algorithm = algo;
@@ -29,31 +26,12 @@ var Controller = /** @class */ (function () {
2926
this.algorithm.connectNodes();
3027
}
3128
};
32-
Controller.prototype.changeSpeed = function (newSpeed) {
33-
this.speed = newSpeed;
34-
};
35-
Controller.prototype.getSpeed = function () {
36-
return this.speed;
37-
};
3829
Controller.prototype.getAlgorithm = function () {
3930
return this.algorithm;
4031
};
4132
Controller.prototype.lockScreen = function (b) {
4233
viewer.screenLockThis(b);
4334
};
44-
/**
45-
* Remove the maximum/minimum element
46-
*/
47-
Controller.prototype.remove = function () {
48-
viewer.screenLockThis(true);
49-
//this.algorithm.remove();
50-
viewer.screenLockThis(false);
51-
};
52-
Controller.prototype.union = function (firstIndex, secondIndex) {
53-
viewer.screenLockThis(true);
54-
//this.algorithm.union(firstIndex, secondIndex);
55-
viewer.screenLockThis(false);
56-
};
5735
Controller.prototype.setArrow = function (index) {
5836
viewer.setThisArrow(index);
5937
};
@@ -75,15 +53,9 @@ var Controller = /** @class */ (function () {
7553
Controller.prototype.highlightSortElem = function (index, color) {
7654
viewer.highlightThisSortElem(index, color);
7755
};
78-
Controller.prototype.setAlgorithm = function (algo) {
79-
this.algorithm = algo;
80-
};
8156
Controller.prototype.removeHighlight = function (node) {
8257
viewer.removeThisHighlight(node);
8358
};
84-
Controller.prototype.setMethodToUse = function (methodToUse) {
85-
this.methodToUse = methodToUse;
86-
};
8759
Controller.prototype.getNameOfCurrentAlgorithm = function () {
8860
return this.algorithm.getName();
8961
};
@@ -93,24 +65,21 @@ var Controller = /** @class */ (function () {
9365
Controller.prototype.setArray = function (array) {
9466
this.algorithm.setArray(array);
9567
};
96-
Controller.prototype.checkMark = function (aIndex, bIndex, set) {
97-
viewer.checkMark(aIndex, bIndex, set);
98-
};
99-
Controller.prototype.redCross = function (aIndex, bIndex, set) {
100-
viewer.redCross(aIndex, bIndex, set);
101-
};
10268
Controller.prototype.displaySize = function (root, size) {
10369
viewer.displayNodeSize(root, size);
10470
};
10571
Controller.prototype.saveState = function (arr) {
106-
viewer.executeSaveMethodInJavaScript(this.getArrayClone());
72+
viewer.executeSaveMethodInJavaScript(arr);
10773
};
10874
Controller.prototype.addNode = function (i) {
10975
this.algorithm.add(i);
11076
};
11177
Controller.prototype.swapNode = function (child, parent) {
11278
viewer.swapNode(child, parent);
11379
};
80+
/**
81+
* Remove the maximum/minimum element
82+
*/
11483
Controller.prototype.removeNode = function () {
11584
this.algorithm.remove();
11685
};

Heap/js/Controller.ts

Lines changed: 6 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* File created by Kenneth Apeland 03.02.18.
2+
* File created by Øyvind Liland on 22.02.18.
33
*/
44
///<reference path="View.ts"/>
55
///<reference path="IAlgorithm.ts"/>
@@ -8,18 +8,10 @@
88
///<reference path="methods.ts"/>
99
///<reference path="MaxHeapFree.ts"/>
1010

11-
12-
let iColor = 2;
13-
let jColor = 0;
14-
1511
class Controller {
1612

17-
//algorithm og methodToUse skal ikke være string, men dei e det for nå
18-
//programmet vil ikje fungere
1913
private algorithm: IAlgorithm;
20-
private methodToUse: string = "Union";
2114
private speed: number;
22-
private GUI: IView; // Mulig forskjellig View for ulike algoritmer?
2315

2416
initController(algo: IAlgorithm) {
2517
this.algorithm = algo;
@@ -37,14 +29,6 @@ class Controller {
3729
}
3830
}
3931

40-
changeSpeed(newSpeed: number) {
41-
this.speed = newSpeed;
42-
}
43-
44-
getSpeed() {
45-
return this.speed;
46-
}
47-
4832
getAlgorithm() {
4933
return this.algorithm;
5034
}
@@ -53,21 +37,6 @@ class Controller {
5337
viewer.screenLockThis(b);
5438
}
5539

56-
/**
57-
* Remove the maximum/minimum element
58-
*/
59-
remove() {
60-
viewer.screenLockThis(true);
61-
//this.algorithm.remove();
62-
viewer.screenLockThis(false);
63-
}
64-
65-
union(firstIndex: number, secondIndex: number) {
66-
viewer.screenLockThis(true);
67-
//this.algorithm.union(firstIndex, secondIndex);
68-
viewer.screenLockThis(false);
69-
}
70-
7140
setArrow(index: number) {
7241
viewer.setThisArrow(index);
7342
}
@@ -95,19 +64,11 @@ class Controller {
9564
highlightSortElem(index: number, color: string) {
9665
viewer.highlightThisSortElem(index, color);
9766
}
98-
99-
setAlgorithm(algo: IAlgorithm) {
100-
this.algorithm = algo;
101-
}
102-
67+
10368
removeHighlight(node: number) {
10469
viewer.removeThisHighlight(node);
10570
}
10671

107-
setMethodToUse(methodToUse: string) {
108-
this.methodToUse = methodToUse;
109-
}
110-
11172
getNameOfCurrentAlgorithm() {
11273
return this.algorithm.getName();
11374
}
@@ -120,20 +81,12 @@ class Controller {
12081
this.algorithm.setArray(array);
12182
}
12283

123-
checkMark(aIndex: number, bIndex: number, set: boolean) {
124-
viewer.checkMark(aIndex, bIndex, set);
125-
}
126-
127-
redCross(aIndex: number, bIndex: number, set: boolean) {
128-
viewer.redCross(aIndex, bIndex, set);
129-
}
130-
13184
displaySize(root: number, size: number) {
13285
viewer.displayNodeSize(root, size);
13386
}
13487

13588
saveState(arr: number[]) {
136-
viewer.executeSaveMethodInJavaScript(this.getArrayClone());
89+
viewer.executeSaveMethodInJavaScript(arr);
13790
}
13891

13992
addNode(i: number) {
@@ -144,6 +97,9 @@ class Controller {
14497
viewer.swapNode(child, parent);
14598
}
14699

100+
/**
101+
* Remove the maximum/minimum element
102+
*/
147103
removeNode() {
148104
this.algorithm.remove();
149105
}

Heap/js/IView.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ interface IView {
2222

2323
removeThisHighlight(node: number): void;
2424

25-
checkMark(aIndex: number, bIndex: number, set: boolean): void;
26-
27-
redCross(aIndex: number, bIndex: number, set: boolean): void;
28-
2925
displayNodeSize(root: number, size: number): void;
3026

3127
setThisState(arrayObject: JSON, array: JSON): void;

Heap/js/View.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@
1111
var View = /** @class */ (function () {
1212
function View() {
1313
this.colors = ["#7FFF00", "not used", "#FFB366"];
14-
this.arrayIsReset = false;
1514
this.k = 0;
16-
this.currentAlgorithmName = "MaxHeap";
1715
this.paused = false;
16+
this.playing = false;
1817
this.animSpeed = 500;
1918
}
2019
View.prototype.displayThisArray = function (array) {
@@ -115,22 +114,6 @@ var View = /** @class */ (function () {
115114
}(index);
116115
manager.addEvent(new FrontendEvent(forward, forward, this.animSpeed));
117116
};
118-
View.prototype.checkMark = function (aIndex, bIndex, set) {
119-
var forward = function (aIndex, bIndex, set) {
120-
return function () {
121-
setCheckMark(set, aIndex, bIndex);
122-
};
123-
}(aIndex, bIndex, set);
124-
manager.addEvent(new FrontendEvent(forward, forward, this.animSpeed));
125-
};
126-
View.prototype.redCross = function (aIndex, bIndex, set) {
127-
var forward = function (aIndex, bIndex, set) {
128-
return function () {
129-
setWrongMark(set, aIndex, bIndex);
130-
};
131-
}(aIndex, bIndex, set);
132-
manager.addEvent(new FrontendEvent(forward, forward, this.animSpeed));
133-
};
134117
View.prototype.setThisState = function (relationships, backendArray) {
135118
setState(JSON.stringify(backendArray).toString(), JSON.stringify(relationships).toString());
136119
};
@@ -150,6 +133,8 @@ var View = /** @class */ (function () {
150133
};
151134
View.prototype.resetAll = function () {
152135
this.paused = false;
136+
this.playing = false;
137+
$("#play").text("Play");
153138
manager.pause();
154139
manager.nextEvents = new Array;
155140
manager.previousEvents = new Array;
@@ -199,6 +184,7 @@ var View = /** @class */ (function () {
199184
View.prototype.switchAlgorithm = function (algo) {
200185
$("#sortArray").hide();
201186
$("#sortArrayUL").children("li").remove();
187+
lockPlay(true);
202188
switch (algo) {
203189
case "MaxHeap": {
204190
this.resetAll();
@@ -212,12 +198,14 @@ var View = /** @class */ (function () {
212198
}
213199
case "BuildHeap": {
214200
this.resetAll();
201+
lockPlay(false);
215202
control.initController(new BuildHeap(10));
216203
screenLock(true);
217204
break;
218205
}
219206
case "HeapSort": {
220207
this.resetAll();
208+
lockPlay(false);
221209
$("#sortArray").show();
222210
control.initController(new HeapSort(10));
223211
screenLock(true);
@@ -277,16 +265,29 @@ var View = /** @class */ (function () {
277265
};
278266
View.prototype.play = function () {
279267
var algo = control.getAlgorithm().getName();
280-
if (algo === "BuildHeap" && !this.paused) {
268+
if (algo === "BuildHeap" && !this.paused && !this.playing) {
281269
control.getAlgorithm().build();
282270
this.paused = true;
271+
this.playing = true;
272+
$("#play").text("Pause");
283273
}
284-
else if (algo === "HeapSort" && !this.paused) {
274+
else if (algo === "HeapSort" && !this.paused && !this.playing) {
285275
control.getAlgorithm().sort();
286276
this.paused = true;
277+
this.playing = true;
278+
$("#play").text("Pause");
287279
}
288280
else {
289-
return;
281+
if (this.playing) {
282+
manager.pause();
283+
$("#play").text("Resume");
284+
this.playing = false;
285+
}
286+
else {
287+
this.playing = true;
288+
manager.start();
289+
$("#play").text("Pause");
290+
}
290291
}
291292
};
292293
View.prototype.insertNewElemThis = function (child, value, parent) {

0 commit comments

Comments
 (0)