Skip to content

Commit 494ff47

Browse files
committed
Fikset highligthing av noder
1 parent fcf6dba commit 494ff47

File tree

2 files changed

+77
-2
lines changed

2 files changed

+77
-2
lines changed

PortJob/Heap/js/methods.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,23 @@ function hideArrayValues() {
6464
// Selects an element. If method==find call method, else wait for second element before union or connected
6565
function selectElement(index) {
6666
// Set new class for selected index
67-
selectIndex(index, true);
67+
deselectNodeSelections();
68+
deselectArrayElemSelections();
69+
var $selected = $("#arrayElem" + index);
70+
if ($selected.hasClass("selected")) {
71+
$selected.removeClass("selected");
72+
}
73+
else {
74+
selectIndex(index, true);
75+
//Children to the highlighted node
76+
var highlightChildren = allNodes[index].children;
77+
console.log(highlightChildren);
78+
if (highlightChildren.length > 0) {
79+
for (var i = 0; i < highlightChildren.length; i++) {
80+
highlightNode(highlightChildren[i].id, "green");
81+
}
82+
}
83+
}
6884
var $method = $('input[name=method]:checked', '#method');
6985
if ($method.val() == 'Find') {
7086
$method.next().text(" find( " + index + " )");
@@ -238,6 +254,15 @@ function selectIndex(index, select) {
238254
}
239255
});
240256
}
257+
function deselectNodeIndex(index) {
258+
$("#node" + index).each(function () {
259+
$(this).removeClass("selected");
260+
$(this).removeClass("green");
261+
});
262+
}
263+
function deselectArrayElement(index) {
264+
$("#arrayElem" + index).removeClass("selected");
265+
}
241266
function highlightNode(index, color) {
242267
if (color.toLowerCase() == "green" || color.toLowerCase() == "orange") {
243268
$("#arrayElem" + index + ", #node" + index).each(function () {
@@ -273,6 +298,16 @@ function resetElementSelections() {
273298
selectIndex(i, false);
274299
}
275300
}
301+
function deselectNodeSelections() {
302+
for (var i = 0; i < 10; i++) {
303+
deselectNodeIndex(i);
304+
}
305+
}
306+
function deselectArrayElemSelections() {
307+
for (var i = 0; i < 10; i++) {
308+
deselectArrayElement(i);
309+
}
310+
}
276311
function saveState(backendArray) {
277312
viewer.saveState(getGraphState(), backendArray);
278313
}

PortJob/Heap/js/methods.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,24 @@ function hideArrayValues() {
8080
function selectElement(index: number) {
8181

8282
// Set new class for selected index
83-
selectIndex(index, true);
83+
deselectNodeSelections();
84+
deselectArrayElemSelections();
85+
86+
let $selected = $("#arrayElem" + index);
87+
if ($selected.hasClass("selected")) {
88+
$selected.removeClass("selected");
89+
}
90+
else {
91+
selectIndex(index, true);
92+
//Children to the highlighted node
93+
let highlightChildren : GraphNode[] = allNodes[index].children;
94+
console.log(highlightChildren);
95+
if (highlightChildren.length > 0) {
96+
for (var i = 0; i < highlightChildren.length; i++) {
97+
highlightNode(highlightChildren[i].id, "green");
98+
}
99+
}
100+
}
84101

85102
var $method = $('input[name=method]:checked', '#method');
86103
if ($method.val() == 'Find') {
@@ -280,6 +297,17 @@ function selectIndex(index: number, select: boolean) {
280297
});
281298
}
282299

300+
function deselectNodeIndex(index: number) {
301+
$("#node" + index).each(function () {
302+
$(this).removeClass("selected");
303+
$(this).removeClass("green");
304+
});
305+
}
306+
307+
function deselectArrayElement(index: number) {
308+
$("#arrayElem" + index).removeClass("selected");
309+
}
310+
283311
function highlightNode(index: number, color: String) {
284312
if (color.toLowerCase() == "green" || color.toLowerCase() == "orange") {
285313
$("#arrayElem" + index + ", #node" + index).each(function () {
@@ -318,6 +346,18 @@ function resetElementSelections() {
318346
}
319347
}
320348

349+
function deselectNodeSelections() {
350+
for (var i: number = 0; i < 10; i++) {
351+
deselectNodeIndex(i);
352+
}
353+
}
354+
355+
function deselectArrayElemSelections() {
356+
for (var i: number = 0; i < 10; i++) {
357+
deselectArrayElement(i);
358+
}
359+
}
360+
321361
function saveState(backendArray: string) {
322362
viewer.saveState(getGraphState(), backendArray);
323363
}

0 commit comments

Comments
 (0)