From d8d5b6caf643b6b9abb05e643a4229b7d74a66df Mon Sep 17 00:00:00 2001 From: hppeng Date: Thu, 23 Jun 2022 07:29:25 -0700 Subject: [PATCH 1/4] Minor code cleanup combine code in corners case combine cases in horiz. drawing --- js/display_atree.js | 41 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/js/display_atree.js b/js/display_atree.js index 0758189..551a233 100644 --- a/js/display_atree.js +++ b/js/display_atree.js @@ -54,18 +54,10 @@ function construct_AT(elem, tree) { document.getElementById("atree-row-" + i).children[node.display.col].appendChild(connector); resolve_connector(document.getElementById("atree-row-" + i).children[node.display.col]); } - // connect left - for (let i = parent_node.display.col + 1; i < node.display.col; i++) { - let connector = connect_elem.cloneNode() - connector.style.backgroundImage = "url('../media/atree/connect_line.png')"; - connector.classList.add("rotate-90"); - connector.id = "r" + parent_node.display.row + "-c" + i + "-line" - document.getElementById("atree-row-" + parent_node.display.row).children[i].appendChild(connector); - resolve_connector(document.getElementById("atree-row-" + parent_node.display.row).children[i]); - } - - // connect right - for (let i = parent_node.display.col - 1; i > node.display.col; i--) { + // connect horizontally + let left = Math.min(parent_node.display.col, node.display.col); + let max = Math.max(parent_node.display.col, node.display.col); + for (let i = min + 1; i < max; i++) { let connector = connect_elem.cloneNode() connector.style.backgroundImage = "url('../media/atree/connect_line.png')"; connector.classList.add("rotate-90"); @@ -75,23 +67,18 @@ function construct_AT(elem, tree) { } // connect corners - if (parent_node.display.col > node.display.col && (parent_node.display.row != node.display.row)) { - let connector = connect_elem.cloneNode() - connector.style.backgroundImage = "url('../media/atree/connect_angle.png')"; - connector.classList.add("rotate-180"); - connector.id = "r" + parent_node.display.row + "-c" + node.display.col + "-angle" - document.getElementById("atree-row-" + parent_node.display.row).children[node.display.col].appendChild(connector); - resolve_connector(document.getElementById("atree-row-" + parent_node.display.row).children[node.display.col]); - } - if (parent_node.display.col < node.display.col && (parent_node.display.row != node.display.row)) { - let connector = connect_elem.cloneNode() - connector.style.backgroundImage = "url('../media/atree/connect_angle.png')"; - connector.classList.add("rotate-270"); - connector.id = "r" + parent_node.display.row + "-c" + node.display.col + "-angle" - document.getElementById("atree-row-" + parent_node.display.row).children[node.display.col].appendChild(connector); - resolve_connector(document.getElementById("atree-row-" + parent_node.display.row).children[node.display.col]); + let connector = connect_elem.cloneNode() + connector.style.backgroundImage = "url('../media/atree/connect_angle.png')"; + connector.id = "r" + parent_node.display.row + "-c" + node.display.col + "-angle" + document.getElementById("atree-row-" + parent_node.display.row).children[node.display.col].appendChild(connector); + if (parent_node.display.col > node.display.col && (parent_node.display.row != node.display.row)) { + connector.classList.add("rotate-180"); } + else {//if (parent_node.display.col < node.display.col && (parent_node.display.row != node.display.row)) { + connector.classList.add("rotate-270"); + } + resolve_connector(document.getElementById("atree-row-" + parent_node.display.row).children[node.display.col]); } // create node From e0f2dde9535d896016bcb79ee8c10912f91b2977 Mon Sep 17 00:00:00 2001 From: hppeng Date: Thu, 23 Jun 2022 07:42:58 -0700 Subject: [PATCH 2/4] Fix typo --- js/display_atree.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/display_atree.js b/js/display_atree.js index 551a233..162488e 100644 --- a/js/display_atree.js +++ b/js/display_atree.js @@ -55,7 +55,7 @@ function construct_AT(elem, tree) { resolve_connector(document.getElementById("atree-row-" + i).children[node.display.col]); } // connect horizontally - let left = Math.min(parent_node.display.col, node.display.col); + let min = Math.min(parent_node.display.col, node.display.col); let max = Math.max(parent_node.display.col, node.display.col); for (let i = min + 1; i < max; i++) { let connector = connect_elem.cloneNode() From b5f05cb1e6b23ff6187e0a8134d346c415c67db5 Mon Sep 17 00:00:00 2001 From: hppeng Date: Thu, 23 Jun 2022 07:43:32 -0700 Subject: [PATCH 3/4] Whoops -- missing case --- js/display_atree.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/display_atree.js b/js/display_atree.js index 162488e..85c2872 100644 --- a/js/display_atree.js +++ b/js/display_atree.js @@ -75,7 +75,7 @@ function construct_AT(elem, tree) { if (parent_node.display.col > node.display.col && (parent_node.display.row != node.display.row)) { connector.classList.add("rotate-180"); } - else {//if (parent_node.display.col < node.display.col && (parent_node.display.row != node.display.row)) { + else if (parent_node.display.col < node.display.col && (parent_node.display.row != node.display.row)) { connector.classList.add("rotate-270"); } resolve_connector(document.getElementById("atree-row-" + parent_node.display.row).children[node.display.col]); From c42e96d3607f62165330c5828e3807fa1a1e59a9 Mon Sep 17 00:00:00 2001 From: hppeng Date: Thu, 23 Jun 2022 07:53:55 -0700 Subject: [PATCH 4/4] Finally fixed bugs -- please test your code before pushing bad hpp --- js/display_atree.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/js/display_atree.js b/js/display_atree.js index 85c2872..8d2cf7a 100644 --- a/js/display_atree.js +++ b/js/display_atree.js @@ -68,17 +68,19 @@ function construct_AT(elem, tree) { // connect corners - let connector = connect_elem.cloneNode() - connector.style.backgroundImage = "url('../media/atree/connect_angle.png')"; - connector.id = "r" + parent_node.display.row + "-c" + node.display.col + "-angle" - document.getElementById("atree-row-" + parent_node.display.row).children[node.display.col].appendChild(connector); - if (parent_node.display.col > node.display.col && (parent_node.display.row != node.display.row)) { - connector.classList.add("rotate-180"); + if (parent_node.display.row != node.display.row && parent_node.display.col != node.display.col) { + let connector = connect_elem.cloneNode() + connector.style.backgroundImage = "url('../media/atree/connect_angle.png')"; + connector.id = "r" + parent_node.display.row + "-c" + node.display.col + "-angle" + document.getElementById("atree-row-" + parent_node.display.row).children[node.display.col].appendChild(connector); + if (parent_node.display.col > node.display.col) { + connector.classList.add("rotate-180"); + } + else {// if (parent_node.display.col < node.display.col && (parent_node.display.row != node.display.row)) { + connector.classList.add("rotate-270"); + } + resolve_connector(document.getElementById("atree-row-" + parent_node.display.row).children[node.display.col]); } - else if (parent_node.display.col < node.display.col && (parent_node.display.row != node.display.row)) { - connector.classList.add("rotate-270"); - } - resolve_connector(document.getElementById("atree-row-" + parent_node.display.row).children[node.display.col]); } // create node