Skip to content

Commit 4ca31f5

Browse files
Fikset trykking på elementer etter man har lagt til nytt - Fikset highlighting bug
1 parent 97d5246 commit 4ca31f5

File tree

7 files changed

+12
-16
lines changed

7 files changed

+12
-16
lines changed

Heap/css/heap_style.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ ul#graphUL li.wrong {
103103
}
104104

105105
/** WARNING: Do not change the name of "green" or "orange" class. Js uses strings sent from java to set class **/
106-
ul#graphUL li.green, ul#sortArrayUL li.green div.content, ul#arrayUL li.child div.content {
106+
ul#graphUL li.green, ul#sortArrayUL li.green div.content, ul#arrayUL li.child div.content, ul#arrayUL li.green div.content {
107107
border: 3px solid rgb(0, 204, 0);
108108
}
109109

110-
ul#graphUL li.orange {
110+
ul#graphUL li.orange, ul#arrayUL li.orange div.content {
111111
border: 3px solid rgb(255, 117, 26);
112112
}
113113

Heap/js/MaxHeap.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ var MaxHeap = /** @class */ (function () {
157157
var other = Math.floor((index - 1) / 2);
158158
while (other >= 0 && this.array[index] > this.array[other]) {
159159
this.exch(index, other);
160+
control.highlightTwoNodes(index, other, "green");
161+
control.removeHighlightTwoNodes(index, other, "green");
160162
index = Math.floor((index - 1) / 2);
161163
other = Math.floor((index - 1) / 2);
162164
}

Heap/js/MaxHeap.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ class MaxHeap implements IAlgorithm {
181181
let other: number = Math.floor((index - 1) / 2);
182182
while (other >= 0 && this.array[index] > this.array[other]) {
183183
this.exch(index, other);
184+
control.highlightTwoNodes(index, other, "green");
185+
control.removeHighlightTwoNodes(index, other, "green");
184186
index = Math.floor((index - 1) / 2);
185187
other = Math.floor((index - 1) / 2);
186188
}

Heap/js/View.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ var View = /** @class */ (function () {
165165
};
166166
View.prototype.addNode = function (val) {
167167
control.addNode(val);
168-
setOnClickListener();
169168
setupRadio();
170169
};
171170
View.prototype.removeNode = function () {
@@ -210,6 +209,7 @@ var View = /** @class */ (function () {
210209
setValueAtIndex(index, value);
211210
insertNewNode(index, value);
212211
insertNewElemConnect(index, parent);
212+
setOnClickListener();
213213
// If first node -> Position with a nice animation
214214
if (control.getAlgorithm().getArrayLength() == 1)
215215
positioningNodes(1500);

Heap/js/View.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ class View {
190190

191191
addNode(val: number) {
192192
control.addNode(val);
193-
setOnClickListener();
194193
setupRadio();
195194
}
196195

@@ -244,6 +243,7 @@ class View {
244243
setValueAtIndex(index, value);
245244
insertNewNode(index, value);
246245
insertNewElemConnect(index, parent);
246+
setOnClickListener();
247247

248248
// If first node -> Position with a nice animation
249249
if (control.getAlgorithm().getArrayLength() == 1)

Heap/js/methods.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ function setOnClickListener() {
3333
for (var i = 0; i < id.length; i++)
3434
if (!isNaN(parseInt(id[i])))
3535
idInt += id[i];
36-
if (isHighlighted(parseInt(idInt))) {
37-
deselectArrayElemSelections();
38-
deselectNodeSelections();
39-
return;
40-
}
4136
selectElement(parseInt(idInt));
4237
});
4338
});
@@ -225,10 +220,11 @@ function deselectArrayElement(index) {
225220
}
226221
function highlightNode(index, color) {
227222
if (color.toLowerCase() == "green" || color.toLowerCase() == "orange") {
228-
$("#arrayElem" + index + ", #node" + index).each(function () {
223+
$("#node" + index).each(function () {
229224
removeHighlight(index);
230225
$(this).addClass(color);
231226
});
227+
$("#arrayElem" + index).addClass(color);
232228
}
233229
else {
234230
console.log("*** WARNING: Unknown color, " + color + " *** ");

Heap/js/methods.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ function setOnClickListener() {
3636
for (let i = 0; i < id.length; i++)
3737
if (!isNaN(parseInt(id[i])))
3838
idInt += id[i];
39-
if (isHighlighted(parseInt(idInt))) {
40-
deselectArrayElemSelections();
41-
deselectNodeSelections();
42-
return;
43-
}
4439
selectElement(parseInt(idInt));
4540
});
4641
});
@@ -262,10 +257,11 @@ function deselectArrayElement(index: number) {
262257

263258
function highlightNode(index: number, color: String) {
264259
if (color.toLowerCase() == "green" || color.toLowerCase() == "orange") {
265-
$("#arrayElem" + index + ", #node" + index).each(function () {
260+
$("#node" + index).each(function () {
266261
removeHighlight(index);
267262
$(this).addClass(color);
268263
});
264+
$("#arrayElem" + index).addClass(color);
269265
} else {
270266
console.log("*** WARNING: Unknown color, " + color + " *** ");
271267
}

0 commit comments

Comments
 (0)