Skip to content

Commit def0a16

Browse files
committed
komprimerte funksjoner til å bare bli et steg
1 parent ee277c4 commit def0a16

File tree

10 files changed

+57
-282
lines changed

10 files changed

+57
-282
lines changed

Kruskal/js/Controller.js

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,42 +19,24 @@ var Controller = /** @class */ (function () {
1919
Controller.prototype.resetGraph = function () {
2020
viewer.resetMyAll();
2121
};
22-
Controller.prototype.highlightMyEdge = function (edgeId) {
23-
viewer.setHighlightEdge(edgeId);
22+
Controller.prototype.highlightMyEdge = function (edgeId, weight) {
23+
viewer.setHighlightEdge(edgeId, weight);
2424
};
2525
Controller.prototype.dehighlightMyEdge = function (edgeId) {
2626
viewer.setDehighlightEdge(edgeId);
2727
};
2828
Controller.prototype.removeMyEdge = function (edgeId) {
2929
viewer.removeEdge(edgeId);
3030
};
31-
Controller.prototype.transparentMyEdge = function (edgeId) {
32-
viewer.transparentEdge(edgeId);
33-
};
34-
Controller.prototype.detransparentMyEdge = function (edgeId) {
35-
viewer.transparentEdge(edgeId);
36-
};
3731
Controller.prototype.selectTwoNodes = function (node1, node2) {
3832
viewer.selectTheseNodes(node1, node2);
3933
};
4034
Controller.prototype.deselectTwoNodes = function (node1, node2) {
4135
viewer.deselectTheseNodes(node1, node2);
4236
};
43-
Controller.prototype.disableStartButton = function () {
44-
viewer.disableThisButton();
45-
};
46-
Controller.prototype.enableStartButtion = function () {
47-
viewer.enableThisButton();
48-
};
4937
Controller.prototype.excludeEdgeText = function (index) {
5038
viewer.excludeText(index);
5139
};
52-
Controller.prototype.highlightEdgeText = function (index) {
53-
viewer.highlighText(index);
54-
};
55-
Controller.prototype.addWeightToSum = function (weight) {
56-
viewer.addWeightToSum(weight);
57-
};
5840
Controller.prototype.excludeEdges = function (edgeList) {
5941
viewer.excludeEdges(edgeList);
6042
};

Kruskal/js/Controller.ts

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class Controller {
2222
viewer.resetMyAll();
2323
}
2424

25-
highlightMyEdge(edgeId: number) {
26-
viewer.setHighlightEdge(edgeId);
25+
highlightMyEdge(edgeId: number, weight: number) {
26+
viewer.setHighlightEdge(edgeId, weight);
2727
}
2828

2929
dehighlightMyEdge(edgeId: number) {
@@ -34,14 +34,6 @@ class Controller {
3434
viewer.removeEdge(edgeId);
3535
}
3636

37-
transparentMyEdge(edgeId: number) {
38-
viewer.transparentEdge(edgeId);
39-
}
40-
41-
detransparentMyEdge(edgeId: number) {
42-
viewer.transparentEdge(edgeId);
43-
}
44-
4537
selectTwoNodes(node1: number, node2: number) {
4638
viewer.selectTheseNodes(node1, node2);
4739
}
@@ -50,26 +42,10 @@ class Controller {
5042
viewer.deselectTheseNodes(node1, node2);
5143
}
5244

53-
disableStartButton() {
54-
viewer.disableThisButton();
55-
}
56-
57-
enableStartButtion() {
58-
viewer.enableThisButton();
59-
}
60-
6145
excludeEdgeText(index: number) {
6246
viewer.excludeText(index);
6347
}
6448

65-
highlightEdgeText(index :number) {
66-
viewer.highlighText(index);
67-
}
68-
69-
addWeightToSum(weight: number) {
70-
viewer.addWeightToSum(weight);
71-
}
72-
7349
excludeEdges(edgeList : any) {
7450
viewer.excludeEdges(edgeList);
7551
}

Kruskal/js/EventManager.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
*
44
*/
55

6-
declare var $: any;
7-
86
/** Manager for events stored in queue. Manager is also responsible for executing events automatically */
97
class EventManager {
108
delayTime: number = 1000; // Original value
@@ -100,4 +98,4 @@ class FrontendEvent {
10098
}
10199
}
102100

103-
var manager: EventManager = new EventManager();
101+
let manager: EventManager = new EventManager();

Kruskal/js/KruskalAlgorithm.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,12 @@ function startKruskal() {
2828
currentEdge = getEdgeId(node1, node2);
2929
if (connected(node1, node2) == false) {
3030
controller.selectTwoNodes(node1, node2);
31-
controller.highlightEdgeText(currentEdge);
32-
controller.highlightMyEdge(currentEdge);
31+
controller.highlightMyEdge(currentEdge, weight);
3332
union(node1, node2);
34-
controller.addWeightToSum(weight);
3533
j++;
3634
}
3735
else {
3836
controller.dehighlightMyEdge(currentEdge);
39-
controller.transparentMyEdge(currentEdge);
4037
controller.excludeEdgeText(currentEdge);
4138
}
4239
controller.deselectTwoNodes(node1, node2);

Kruskal/js/KruskalAlgorithm.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,12 @@ function startKruskal() {
3737

3838
if (connected(node1, node2) == false) {
3939
controller.selectTwoNodes(node1, node2);
40-
controller.highlightEdgeText(currentEdge);
41-
controller.highlightMyEdge(currentEdge);
40+
controller.highlightMyEdge(currentEdge, weight);
4241

4342
union(node1, node2);
44-
controller.addWeightToSum(weight);
45-
4643
j++;
4744
} else {
4845
controller.dehighlightMyEdge(currentEdge);
49-
controller.transparentMyEdge(currentEdge);
5046
controller.excludeEdgeText(currentEdge);
5147
}
5248
controller.deselectTwoNodes(node1, node2);
@@ -87,8 +83,8 @@ function sortEdges() {
8783
let temp = 0;
8884
let sorted = triplets;
8985
if (sorted.length > 0) {
90-
for (var i = 0; i < sorted.length; i++) {
91-
for (var j = 0; j < sorted.length; j++) {
86+
for (let i = 0; i < sorted.length; i++) {
87+
for (let j = 0; j < sorted.length; j++) {
9288
let [a, b, c] = sorted[i];
9389
let [d, e, f] = sorted[j];
9490
if (c > f) {

Kruskal/js/Methods.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,6 @@ function connectNodes(node1, node2) {
5252
function removeConnectedNodes() {
5353
removeWeightedEdge(--edges);
5454
}
55-
function disableButton() {
56-
$("#start").attr({ disabled: "true" });
57-
$("#start").css({ "opacity": 0.15 });
58-
}
59-
function enableButton() {
60-
$("#start").removeAttr('disabled');
61-
$("#start").css({ "opacity": 1 });
62-
}
6355
function numberOfNodes(value) {
6456
viewer.resetMyAll();
6557
drawGraph(value);

Kruskal/js/Methods.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,6 @@ function removeConnectedNodes() {
6565
removeWeightedEdge(--edges);
6666
}
6767

68-
function disableButton() {
69-
$("#start").attr({ disabled: "true" });
70-
$("#start").css({ "opacity": 0.15 });
71-
}
72-
73-
function enableButton() {
74-
$("#start").removeAttr('disabled');
75-
$("#start").css({ "opacity": 1 });
76-
}
77-
7868
function numberOfNodes(value: number) {
7969
viewer.resetMyAll();
8070
drawGraph(value);

Kruskal/js/View.js

Lines changed: 15 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,33 @@ var View = /** @class */ (function () {
1111
this.highlightEventDuration = 1000;
1212
this.paused = false;
1313
}
14-
View.prototype.setHighlightEdge = function (edgeId) {
15-
var forward = function (edgeId) {
14+
View.prototype.setHighlightEdge = function (edgeId, weight) {
15+
var forward = function (edgeId, weight) {
1616
return function () {
17+
higlightEdgeText(edgeId);
1718
highlightThisEdge(edgeId);
19+
writeTotalWeight(weight);
1820
};
19-
}(edgeId);
20-
var backward = function (edgeId) {
21+
}(edgeId, weight);
22+
var backward = function (edgeId, weight) {
2123
return function () {
2224
dehighlightThisEdge(edgeId);
25+
deHighlightEdgeText(edgeId);
26+
writeTotalWeight(-weight);
2327
};
24-
}(edgeId);
28+
}(edgeId, weight);
2529
manager.addEvent(new FrontendEvent(forward, backward, this.highlightEventDuration));
2630
};
2731
View.prototype.setDehighlightEdge = function (edgeId) {
2832
var forward = function (edgeId) {
2933
return function () {
34+
transparentEdge(edgeId);
3035
dehighlightThisEdge(edgeId);
3136
};
3237
}(edgeId);
3338
var backward = function (edgeId) {
3439
return function () {
40+
transparentEdge(edgeId);
3541
highlightThisEdge(edgeId);
3642
};
3743
}(edgeId);
@@ -51,32 +57,6 @@ var View = /** @class */ (function () {
5157
}(edgeId);
5258
manager.addEvent(new FrontendEvent(forward, backward, this.highlightEventDuration));
5359
};
54-
View.prototype.transparentEdge = function (edgeId) {
55-
var forward = function (edgeId) {
56-
return function () {
57-
transparentEdge(edgeId);
58-
};
59-
}(edgeId);
60-
var backward = function (edgeId) {
61-
return function () {
62-
deTransparentEdge(edgeId);
63-
};
64-
}(edgeId);
65-
manager.addEvent(new FrontendEvent(forward, backward, this.highlightEventDuration));
66-
};
67-
View.prototype.deTransparentEdge = function (edgeId) {
68-
var forward = function (edgeId) {
69-
return function () {
70-
deTransparentEdge(edgeId);
71-
};
72-
}(edgeId);
73-
var backward = function (edgeId) {
74-
return function () {
75-
transparentEdge(edgeId);
76-
};
77-
}(edgeId);
78-
manager.addEvent(new FrontendEvent(forward, backward, this.highlightEventDuration));
79-
};
8060
View.prototype.addNodeToGraph = function (x, y) {
8161
var forward = function (x, y) {
8262
return function () {
@@ -129,32 +109,6 @@ var View = /** @class */ (function () {
129109
}(node1, node2);
130110
manager.addEvent(new FrontendEvent(forward, backward, this.highlightEventDuration));
131111
};
132-
View.prototype.disableThisButton = function () {
133-
var forward = function () {
134-
return function () {
135-
disableButton();
136-
};
137-
}();
138-
var backward = function () {
139-
return function () {
140-
enableButton();
141-
};
142-
}();
143-
manager.addEvent(new FrontendEvent(forward, backward, 10));
144-
};
145-
View.prototype.enableThisButton = function () {
146-
var forward = function () {
147-
return function () {
148-
enableButton();
149-
};
150-
}();
151-
var backward = function () {
152-
return function () {
153-
disableButton();
154-
};
155-
}();
156-
manager.addEvent(new FrontendEvent(forward, backward, 10));
157-
};
158112
View.prototype.excludeText = function (i) {
159113
var forward = function (i) {
160114
return function () {
@@ -168,32 +122,6 @@ var View = /** @class */ (function () {
168122
}(i);
169123
manager.addEvent(new FrontendEvent(forward, backward, this.highlightEventDuration));
170124
};
171-
View.prototype.highlighText = function (i) {
172-
var forward = function (i) {
173-
return function () {
174-
higlightEdgeText(i);
175-
};
176-
}(i);
177-
var backward = function (i) {
178-
return function () {
179-
deHighlightEdgeText(i);
180-
};
181-
}(i);
182-
manager.addEvent(new FrontendEvent(forward, backward, this.highlightEventDuration));
183-
};
184-
View.prototype.addWeightToSum = function (weight) {
185-
var forward = function (weight) {
186-
return function () {
187-
writeTotalWeight(weight);
188-
};
189-
}(weight);
190-
var backward = function (weight) {
191-
return function () {
192-
writeTotalWeight(-weight);
193-
};
194-
}(weight);
195-
manager.addEvent(new FrontendEvent(forward, backward, this.highlightEventDuration));
196-
};
197125
View.prototype.resetMyAll = function () {
198126
resetGraphUI();
199127
manager.clear();
@@ -223,9 +151,13 @@ var View = /** @class */ (function () {
223151
$('#forward').removeAttr('disabled');
224152
};
225153
View.prototype.forward = function () {
154+
this.paused = false;
155+
this.pause();
226156
manager.next();
227157
};
228158
View.prototype.backward = function () {
159+
this.paused = false;
160+
this.pause();
229161
manager.previous();
230162
};
231163
View.prototype.slow = function () {

0 commit comments

Comments
 (0)