From 13bfc88442693ed1dd227c79d0f4f627fc6dbbba Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Thu, 7 Nov 2024 12:57:02 +0000 Subject: [PATCH] JAL-4386 Demonstration of the ColorUtils HSB methods in the normal tree --- src/jalview/datamodel/BinaryNode.java | 32 ++++++++++++++++++++++++++++++++ src/jalview/gui/TreeCanvas.java | 24 ++++++++++-------------- 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/src/jalview/datamodel/BinaryNode.java b/src/jalview/datamodel/BinaryNode.java index 624c2b9..23a3fed 100755 --- a/src/jalview/datamodel/BinaryNode.java +++ b/src/jalview/datamodel/BinaryNode.java @@ -380,4 +380,36 @@ public class BinaryNode return c; } + + /** + * get a concatenation of all node names under this node + */ + public String getNodeName() + { + return getNodeName(0); + } + + public String getNodeName(int depth) + { + StringBuilder sb = new StringBuilder(); + if (getName() != null) + { + sb.append(getName()); + } + if (left() != null) + { + sb.append("::L"); + sb.append(depth); + sb.append("::"); + sb.append(left().getNodeName(depth + 1)); + } + if (right() != null) + { + sb.append("::R"); + sb.append(depth); + sb.append("::"); + sb.append(right.getNodeName(depth + 1)); + } + return sb.toString(); + } } diff --git a/src/jalview/gui/TreeCanvas.java b/src/jalview/gui/TreeCanvas.java index 9180d52..092baf7 100755 --- a/src/jalview/gui/TreeCanvas.java +++ b/src/jalview/gui/TreeCanvas.java @@ -55,7 +55,6 @@ import jalview.analysis.TreeModel; import jalview.api.AlignViewportI; import jalview.bin.Console; import jalview.datamodel.AlignmentAnnotation; -import jalview.datamodel.Annotation; import jalview.datamodel.BinaryNode; import jalview.datamodel.ColumnSelection; import jalview.datamodel.ContactMatrixI; @@ -385,10 +384,8 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, } else { - drawNode(g, (BinaryNode) node.left(), chunk, wscale, width, offx, - offy); - drawNode(g, (BinaryNode) node.right(), chunk, wscale, width, offx, - offy); + drawNode(g, node.left(), chunk, wscale, width, offx, offy); + drawNode(g, node.right(), chunk, wscale, width, offx, offy); double height = node.height; double dist = node.dist; @@ -499,8 +496,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, if (top.count == 0) { - top.count = ((BinaryNode) top.left()).count - + ((BinaryNode) top.right()).count; + top.count = top.left().count + top.right().count; } float chunk = (float) (height - (offy)) / top.count; @@ -559,10 +555,8 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, } else { - pickNode(pickBox, (BinaryNode) node.left(), chunk, wscale, width, - offx, offy); - pickNode(pickBox, (BinaryNode) node.right(), chunk, wscale, width, - offx, offy); + pickNode(pickBox, node.left(), chunk, wscale, width, offx, offy); + pickNode(pickBox, node.right(), chunk, wscale, width, offx, offy); } } @@ -594,8 +588,8 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, } } } - setColor((BinaryNode) node.left(), c); - setColor((BinaryNode) node.right(), c); + setColor(node.left(), c); + setColor(node.right(), c); } /** @@ -1061,7 +1055,9 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, Map colors = new HashMap(); for (int i = 0; i < groups.size(); i++) { - Color col = ColorUtils.getARandomColor(); + String colId = groups.get(i).getNodeName(); + Color col = ColorUtils.getColourFromNameAndScheme(colId, + "AVOID_GREEN"); setColor(groups.get(i), col.brighter()); -- 1.7.10.2