From e30f734d5ac9eaa10a9531c5a5f282e274187f8e Mon Sep 17 00:00:00 2001 From: Juhan Oskar Hennoste Date: Wed, 25 Oct 2023 19:24:42 +0300 Subject: [PATCH] Tweak tree layout. Add example of visualizing array-based heap. --- .../ee/ut/dendroloj/GenericTreeLayout.java | 2 +- src/test/java/KuhjaKatsed.java | 20 +++++++++++++++++++ src/test/java/TippKatsed.java | 6 +++--- 3 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 src/test/java/KuhjaKatsed.java diff --git a/src/main/java/ee/ut/dendroloj/GenericTreeLayout.java b/src/main/java/ee/ut/dendroloj/GenericTreeLayout.java index 6f26ff2..70e92d6 100644 --- a/src/main/java/ee/ut/dendroloj/GenericTreeLayout.java +++ b/src/main/java/ee/ut/dendroloj/GenericTreeLayout.java @@ -52,7 +52,7 @@ private static LayoutResult addToGraph(Graph graph, T node, Node parent, dou int i = 0; for (T child : children) { - LayoutResult result = addToGraph(graph, child, current, x + width, y - 2.0, getLabel, getChildren); + LayoutResult result = addToGraph(graph, child, current, x + width, y - 1.25, getLabel, getChildren); if (i == leftReferenceNode) { firstChildOffset = width + result.offset; } diff --git a/src/test/java/KuhjaKatsed.java b/src/test/java/KuhjaKatsed.java new file mode 100644 index 0000000..288f84c --- /dev/null +++ b/src/test/java/KuhjaKatsed.java @@ -0,0 +1,20 @@ +import ee.ut.dendroloj.Dendrologist; + +import java.util.List; + +public class KuhjaKatsed { + + public static void main(String[] args) { + Dendrologist.setUIScale(1.5); + + List kuhi = List.of(10, 6, 7, 3, 5, 2, 3, 9, 4, 12, 5, -7, 5, 3, 6, 6, 5, 16); + Dendrologist.drawBinaryTree( + 0, + i -> String.valueOf(kuhi.get(i)), + i -> 2 * i + 1 < kuhi.size() ? 2 * i + 1 : null, + i -> 2 * i + 2 < kuhi.size() ? 2 * i + 2 : null + ); + + } + +} diff --git a/src/test/java/TippKatsed.java b/src/test/java/TippKatsed.java index c2e7c01..0f8812e 100644 --- a/src/test/java/TippKatsed.java +++ b/src/test/java/TippKatsed.java @@ -13,9 +13,9 @@ public static void main(String[] args) { new Tipp("E", new Tipp("F"), new Tipp("G")))), null ); - tipp.v.v.p.p = tipp.v.p.v; - tipp.v.v.v = tipp.v.v.p; - tipp.v.p.p.v.p = tipp.v; + //tipp.v.v.p.p = tipp.v.p.v; + //tipp.v.v.v = tipp.v.v.p; + //tipp.v.p.v.p = tipp.v; Dendrologist.drawBinaryTree(tipp, t -> t.info, t -> t.v, t -> t.p); // Dendrologist.drawBinaryTree(tipp, t -> t.info + " x=" + t.x, t -> t.v, t -> t.p); }