Skip to content

Commit c8fbd13

Browse files
Merge branch 'master' of https://github.com/kennidenni/INF219
2 parents 2472c19 + b3c1638 commit c8fbd13

File tree

8 files changed

+145
-206
lines changed

8 files changed

+145
-206
lines changed

Kruskal/js/Controller.js

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,15 @@
1010
var Controller = /** @class */ (function () {
1111
function Controller() {
1212
}
13-
Controller.prototype.addNode = function (x, y) {
14-
viewer.addNodeToGraph(x, y);
13+
Controller.prototype.highlightEdge = function (node1, node2, edgeId, weight) {
14+
viewer.setHighlightEdge(node1, node2, edgeId, weight);
1515
};
16-
Controller.prototype.connectTwoNodes = function (node1, node2) {
17-
viewer.connectTheseNodes(node1, node2);
18-
};
19-
Controller.prototype.resetGraph = function () {
20-
viewer.resetMyAll();
21-
};
22-
Controller.prototype.highlightMyEdge = function (edgeId, weight) {
23-
viewer.setHighlightEdge(edgeId, weight);
24-
};
25-
Controller.prototype.dehighlightMyEdge = function (edgeId) {
26-
viewer.setDehighlightEdge(edgeId);
27-
};
28-
Controller.prototype.removeMyEdge = function (edgeId) {
29-
viewer.removeEdge(edgeId);
16+
Controller.prototype.dehighlightEdge = function (node1, node2, edgeId) {
17+
viewer.dehighlightEdge(node1, node2, edgeId);
3018
};
3119
Controller.prototype.selectTwoNodes = function (node1, node2) {
3220
viewer.selectTheseNodes(node1, node2);
3321
};
34-
Controller.prototype.deselectTwoNodes = function (node1, node2) {
35-
viewer.deselectTheseNodes(node1, node2);
36-
};
37-
Controller.prototype.excludeEdgeText = function (index) {
38-
viewer.excludeText(index);
39-
};
4022
Controller.prototype.excludeEdges = function (edgeList) {
4123
viewer.excludeEdges(edgeList);
4224
};

Kruskal/js/Controller.ts

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,18 @@
1010
///<reference path="Methods.ts"/>
1111

1212
class Controller {
13-
addNode(x: number, y: number) {
14-
viewer.addNodeToGraph(x, y);
13+
highlightEdge(node1: number, node2: number, edgeId: number, weight: number) {
14+
viewer.setHighlightEdge(node1, node2, edgeId, weight);
1515
}
1616

17-
connectTwoNodes(node1: number, node2: number) {
18-
viewer.connectTheseNodes(node1, node2);
19-
}
20-
21-
resetGraph() {
22-
viewer.resetMyAll();
23-
}
24-
25-
highlightMyEdge(edgeId: number, weight: number) {
26-
viewer.setHighlightEdge(edgeId, weight);
27-
}
28-
29-
dehighlightMyEdge(edgeId: number) {
30-
viewer.setDehighlightEdge(edgeId);
31-
}
32-
33-
removeMyEdge(edgeId: number) {
34-
viewer.removeEdge(edgeId);
17+
dehighlightEdge(node1: number, node2: number, edgeId: number) {
18+
viewer.dehighlightEdge(node1, node2, edgeId);
3519
}
3620

3721
selectTwoNodes(node1: number, node2: number) {
3822
viewer.selectTheseNodes(node1, node2);
3923
}
4024

41-
deselectTwoNodes(node1: number, node2: number){
42-
viewer.deselectTheseNodes(node1, node2);
43-
}
44-
45-
excludeEdgeText(index: number) {
46-
viewer.excludeText(index);
47-
}
48-
4925
excludeEdges(edgeList : any) {
5026
viewer.excludeEdges(edgeList);
5127
}

Kruskal/js/KruskalAlgorithm.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,15 @@ function startKruskal() {
2626
}
2727
var _b = edgeList.pop(), node1 = _b[0], node2 = _b[1], weight = _b[2];
2828
currentEdge = getEdgeId(node1, node2);
29+
controller.selectTwoNodes(node1, node2);
2930
if (connected(node1, node2) == false) {
30-
controller.selectTwoNodes(node1, node2);
31-
controller.highlightMyEdge(currentEdge, weight);
31+
controller.highlightEdge(node1, node2, currentEdge, weight);
3232
union(node1, node2);
3333
j++;
3434
}
3535
else {
36-
controller.dehighlightMyEdge(currentEdge);
37-
controller.excludeEdgeText(currentEdge);
36+
controller.dehighlightEdge(node1, node2, currentEdge);
3837
}
39-
controller.deselectTwoNodes(node1, node2);
4038
}
4139
arr = [];
4240
queue = [];

Kruskal/js/KruskalAlgorithm.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,18 @@ function startKruskal() {
3434

3535
let [node1, node2, weight] = edgeList.pop();
3636
currentEdge = getEdgeId(node1, node2);
37+
controller.selectTwoNodes(node1, node2);
3738

3839
if (connected(node1, node2) == false) {
39-
controller.selectTwoNodes(node1, node2);
40-
controller.highlightMyEdge(currentEdge, weight);
41-
40+
controller.highlightEdge(node1, node2, currentEdge, weight);
4241
union(node1, node2);
4342
j++;
43+
4444
} else {
45-
controller.dehighlightMyEdge(currentEdge);
46-
controller.excludeEdgeText(currentEdge);
45+
controller.dehighlightEdge(node1, node2, currentEdge);
4746
}
48-
controller.deselectTwoNodes(node1, node2);
4947
}
48+
5049
arr = [];
5150
queue = [];
5251
currentEdge = 0;

Kruskal/js/Methods.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ var MAX_NODES = 10;
99
var edges = 0;
1010
var totalWeight = 0;
1111
function highlightThisEdge(index) {
12+
//Blue
1213
$("#edge" + index).css({ "stroke": "rgb(16, 130, 219)", "stroke-width": "6" });
1314
}
15+
function selectThisEdge(index) {
16+
//Orange
17+
$("#edge" + index).css({ "stroke": "rgb(255, 165, 0)", "stroke-width": "6" });
18+
}
1419
function dehighlightThisEdge(index) {
1520
$("#edge" + index).css({ "stroke": "rgb(0, 0, 0)", "stroke-width": "2" });
1621
}
@@ -22,7 +27,7 @@ function transparentEdge(index) {
2227
$("#edge" + index).css({ "opacity": 0.15 });
2328
$("#edgeWeight" + index).css({ "opacity": 0.15 });
2429
}
25-
function deTransparentEdge(index) {
30+
function detransparentEdge(index) {
2631
$("#edge" + index).css({ "opacity": 1 });
2732
$("#edgeWeight" + index).css({ "opacity": 1 });
2833
}
@@ -36,7 +41,7 @@ function removeThisNode() {
3641
removeNode(--nodes);
3742
}
3843
function selectNodes(n1, n2, select) {
39-
if (select == true) {
44+
if (select) {
4045
$("#node" + n1).addClass("selected");
4146
$("#node" + n2).addClass("selected");
4247
}
@@ -114,11 +119,14 @@ function excludeEdgeText(i) {
114119
}
115120
function includeEdgeText(i) {
116121
$("#edgeContent" + i).css({ "opacity": 1 });
117-
$("#edgeContent" + i).css({ "color": "black" });
122+
dehighlightEdgeText(i);
118123
}
119124
function higlightEdgeText(i) {
120125
$("#edgeContent" + i).css({ "color": "blue" });
121126
}
122-
function deHighlightEdgeText(i) {
127+
function dehighlightEdgeText(i) {
123128
$("#edgeContent" + i).css({ "color": "black" });
124129
}
130+
function selectEdgeText(i) {
131+
$("#edgeContent" + i).css({ "color": "orange" });
132+
}

Kruskal/js/Methods.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,22 @@
44
///<reference path="KruskalAlgorithm".ts"/>
55
///<reference path="exampleGraphs".ts"/>
66

7-
87
let randomWeight = 0;
98
let nodes: number = 0;
109
let MAX_NODES: number = 10;
1110
let edges: number = 0;
1211
let totalWeight: number = 0;
1312

1413
function highlightThisEdge(index: number) {
14+
//Blue
1515
$("#edge" + index).css({ "stroke": "rgb(16, 130, 219)", "stroke-width": "6" });
1616
}
1717

18+
function selectThisEdge(index: number) {
19+
//Orange
20+
$("#edge" + index).css({ "stroke": "rgb(255, 165, 0)", "stroke-width": "6" });
21+
}
22+
1823
function dehighlightThisEdge(index: number) {
1924
$("#edge" + index).css({ "stroke": "rgb(0, 0, 0)", "stroke-width": "2" });
2025
}
@@ -29,7 +34,7 @@ function transparentEdge(index: number) {
2934
$("#edgeWeight" + index).css({ "opacity": 0.15 });
3035
}
3136

32-
function deTransparentEdge(index: number) {
37+
function detransparentEdge(index: number) {
3338
$("#edge" + index).css({ "opacity": 1 });
3439
$("#edgeWeight" + index).css({ "opacity": 1 });
3540
}
@@ -46,7 +51,7 @@ function removeThisNode() {
4651
}
4752

4853
function selectNodes(n1: number, n2: number, select: boolean) {
49-
if (select == true) {
54+
if (select) {
5055
$("#node" + n1).addClass("selected");
5156
$("#node" + n2).addClass("selected");
5257
}
@@ -135,13 +140,17 @@ function excludeEdgeText(i: number) {
135140

136141
function includeEdgeText(i: number) {
137142
$("#edgeContent" + i).css({ "opacity": 1 });
138-
$("#edgeContent" + i).css({ "color": "black" });
143+
dehighlightEdgeText(i);
139144
}
140145

141146
function higlightEdgeText(i: number) {
142147
$("#edgeContent" + i).css({ "color": "blue" });
143148
}
144149

145-
function deHighlightEdgeText(i: number) {
150+
function dehighlightEdgeText(i: number) {
146151
$("#edgeContent" + i).css({ "color": "black" });
147-
}
152+
}
153+
154+
function selectEdgeText(i: number) {
155+
$("#edgeContent" + i).css({ "color": "orange"});
156+
}

0 commit comments

Comments
 (0)