From c3443e896f364ac09927f3faaf1401db12209ba0 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 ef543db..a842ddf 100755 --- a/src/jalview/datamodel/BinaryNode.java +++ b/src/jalview/datamodel/BinaryNode.java @@ -416,4 +416,36 @@ public class BinaryNode } return hasLabel() ? label : ""; } + + /** + * 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 494360f..fbb0a7d 100755 --- a/src/jalview/gui/TreeCanvas.java +++ b/src/jalview/gui/TreeCanvas.java @@ -61,7 +61,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; @@ -424,10 +423,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; @@ -683,8 +680,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; @@ -743,10 +739,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); } } @@ -778,8 +772,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); } /** @@ -1271,7 +1265,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