From: gmungoc Date: Wed, 1 Jul 2015 14:53:27 +0000 (+0100) Subject: JAL-1681 more condensed tooltip where codons share same percentage X-Git-Tag: Release_2_10_0~585^2~5 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=e5c9a94fcd7765b981e73640626989217276a46a;p=jalview.git JAL-1681 more condensed tooltip where codons share same percentage --- diff --git a/src/jalview/analysis/AAFrequency.java b/src/jalview/analysis/AAFrequency.java index 69c39df..50045dc 100755 --- a/src/jalview/analysis/AAFrequency.java +++ b/src/jalview/analysis/AAFrequency.java @@ -596,7 +596,6 @@ public class AAFrequency // array holds #seqs, #ungapped, then codon counts indexed by codon final int[] codonCounts = (int[]) hci.get(PROFILE); int totalCount = 0; - StringBuilder mouseOver = new StringBuilder(32); /* * First pass - get total count and find the highest @@ -636,26 +635,56 @@ public class AAFrequency */ /* - * Scan sorted array backwards for most frequent values first. + * Scan sorted array backwards for most frequent values first. Show + * repeated values compactly. */ + StringBuilder mouseOver = new StringBuilder(32); + StringBuilder samePercent = new StringBuilder(); + String percent = null; + String lastPercent = null; + Format fmt = getPercentageFormat(nseqs); + for (int j = codons.length - 1; j >= 0; j--) { int codonCount = sortedCodonCounts[j]; if (codonCount == 0) { + /* + * remaining codons are 0% - ignore, but finish off the last one if + * necessary + */ + if (samePercent.length() > 0) + { + mouseOver.append(samePercent).append(": ").append(percent) + .append("% "); + } break; } int codonEncoded = codons[j]; final int pct = codonCount * 100 / totalCount; String codon = String .valueOf(CodingUtils.decodeCodon(codonEncoded)); - Format fmt = getPercentageFormat(nseqs); - String formatted = fmt == null ? Integer.toString(pct) : fmt + percent = fmt == null ? Integer.toString(pct) : fmt .form(pct); if (showProfileLogo || codonCount == modalCodonCount) { - mouseOver.append(codon).append(": ").append(formatted) - .append("% "); + if (percent.equals(lastPercent) && j > 0) + { + samePercent.append(samePercent.length() == 0 ? "" : ", "); + samePercent.append(codon); + } + else + { + if (samePercent.length() > 0) + { + mouseOver.append(samePercent).append(": ") + .append(lastPercent) + .append("% "); + } + samePercent.setLength(0); + samePercent.append(codon); + } + lastPercent = percent; } }