From: gmungoc Date: Tue, 19 Jul 2016 17:30:24 +0000 (+0100) Subject: JAL-2068 update rather than recreate AlignmentAnnotation on run() X-Git-Tag: Release_2_10_0~125^2~15 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=f5be72936a417898b982510adf7e23d2f313c59a;p=jalview.git JAL-2068 update rather than recreate AlignmentAnnotation on run() --- diff --git a/src/jalview/workers/ColumnCounterWorker.java b/src/jalview/workers/ColumnCounterWorker.java index 5f61525..4e1a336 100644 --- a/src/jalview/workers/ColumnCounterWorker.java +++ b/src/jalview/workers/ColumnCounterWorker.java @@ -89,7 +89,6 @@ class ColumnCounterWorker extends AlignCalcWorker return; } - removeAnnotation(); if (alignViewport.getAlignment() != null) { try @@ -159,21 +158,58 @@ class ColumnCounterWorker extends AlignCalcWorker { Color color = ColorUtils.getGraduatedColour(count, 0, Color.cyan, max, Color.blue); - anns[i] = new Annotation(String.valueOf(count), - String.valueOf(count), '0', count, color); + String str = String.valueOf(count); + anns[i] = new Annotation(str, str, '0', count, color); } } /* - * construct the annotation, save it and add it to the displayed alignment + * construct or update the annotation */ - AlignmentAnnotation ann = new AlignmentAnnotation(counter.getName(), - counter.getDescription(), anns); + AlignmentAnnotation ann = alignViewport.getAlignment() + .findOrCreateAnnotation(counter.getName(), + counter.getDescription(), false, null, + null); + ann.description = counter.getDescription(); ann.showAllColLabels = true; ann.scaleColLabel = true; ann.graph = AlignmentAnnotation.BAR_GRAPH; - ourAnnots.add(ann); - alignViewport.getAlignment().addAnnotation(ann); + ann.annotations = anns; + setGraphMinMax(ann, anns); + ann.validateRangeAndDisplay(); + if (!ourAnnots.contains(ann)) + { + ourAnnots.add(ann); + } + } + + /** + * Calculate min and max values of annotations and set as graphMin, graphMax + * on the AlignmentAnnotation. This is needed because otherwise, well, bad + * things happen. + * + * @param ann + * @param anns + */ + private void setGraphMinMax(AlignmentAnnotation ann, Annotation[] anns) + { + // TODO feels like this belongs inside AlignmentAnnotation! + float max = Float.MIN_VALUE; + float min = Float.MAX_VALUE; + boolean set = false; + for (Annotation a : anns) { + if (a != null) { + set = true; + float val = a.value; + max = Math.max(max, val); + min = Math.min(min, val); + } + } + if (set) + { + ann.graphMin = min; + ann.graphMax = max; + } } /**