From 5c41e4193f3bebb1c8e11c124a4928d1419b052c Mon Sep 17 00:00:00 2001 From: gmungoc Date: Wed, 5 Jul 2017 11:34:50 +0100 Subject: [PATCH] JAL-147 prevent overview box move up over hidden first sequence --- src/jalview/datamodel/HiddenSequences.java | 3 ++- .../viewmodel/OverviewDimensionsShowHidden.java | 3 ++- test/jalview/datamodel/HiddenSequencesTest.java | 16 ++++++++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/jalview/datamodel/HiddenSequences.java b/src/jalview/datamodel/HiddenSequences.java index a98b10e..a57dc9c 100755 --- a/src/jalview/datamodel/HiddenSequences.java +++ b/src/jalview/datamodel/HiddenSequences.java @@ -253,7 +253,8 @@ public class HiddenSequences } /** - * Convert absolute alignment index to visible alignment index + * Convert absolute alignment index to visible alignment index (or -1 if + * before the first visible sequence) * * @param alignmentIndex * @return diff --git a/src/jalview/viewmodel/OverviewDimensionsShowHidden.java b/src/jalview/viewmodel/OverviewDimensionsShowHidden.java index 4b396a6..2216f33 100644 --- a/src/jalview/viewmodel/OverviewDimensionsShowHidden.java +++ b/src/jalview/viewmodel/OverviewDimensionsShowHidden.java @@ -135,10 +135,12 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions // so convert back after getting visible region position yAsSeq = hiddenSeqs.adjustForHiddenSeqs(hiddenSeqs .findIndexWithoutHiddenSeqs(yAsSeq)); + yAsSeq = Math.max(yAsSeq, 0); // -1 if before first visible sequence // check in case we went off the edge of the alignment int visAlignHeight = hiddenSeqs.findIndexWithoutHiddenSeqs(alheight); int visYAsSeq = hiddenSeqs.findIndexWithoutHiddenSeqs(yAsSeq); + visYAsSeq = Math.max(visYAsSeq, 0); // -1 if before first visible sequence if (visYAsSeq + vpheight - 1 > visAlignHeight) { // went past the end of the alignment, adjust backwards @@ -156,7 +158,6 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions // update viewport ranges.setStartRes(visXAsRes); ranges.setStartSeq(visYAsSeq); - } /** diff --git a/test/jalview/datamodel/HiddenSequencesTest.java b/test/jalview/datamodel/HiddenSequencesTest.java index 7795988..5b2bbd4 100644 --- a/test/jalview/datamodel/HiddenSequencesTest.java +++ b/test/jalview/datamodel/HiddenSequencesTest.java @@ -181,7 +181,8 @@ public class HiddenSequencesTest { AlignmentI al = new Alignment(seqs); HiddenSequences hs = al.getHiddenSequences(); - for (int i = 0; i < SEQ_COUNT; i++) + int height = al.getHeight(); + for (int i = 0; i < height; i++) { assertEquals(i, hs.findIndexWithoutHiddenSeqs(i)); } @@ -194,7 +195,7 @@ public class HiddenSequencesTest /* * alignment is now seq0/2/3/4/7/8/9 */ - assertEquals(SEQ_COUNT - 3, al.getHeight()); + assertEquals(height - 3, al.getHeight()); assertEquals(0, hs.findIndexWithoutHiddenSeqs(0)); assertEquals(0, hs.findIndexWithoutHiddenSeqs(1)); assertEquals(1, hs.findIndexWithoutHiddenSeqs(2)); @@ -205,6 +206,17 @@ public class HiddenSequencesTest assertEquals(4, hs.findIndexWithoutHiddenSeqs(7)); assertEquals(5, hs.findIndexWithoutHiddenSeqs(8)); assertEquals(6, hs.findIndexWithoutHiddenSeqs(9)); + + /* + * hide first sequence only + */ + hs.showAll(null); + hs.hideSequence(seqs[0]); + for (int i = 1; i < height; i++) + { + assertEquals(i - 1, hs.findIndexWithoutHiddenSeqs(i)); + } + assertEquals(-1, hs.findIndexWithoutHiddenSeqs(0)); } /** -- 1.7.10.2