Skip to content

Commit

Permalink
Fix bug in zoom calculation.
Browse files Browse the repository at this point in the history
Fixing a rounding error  in calculateZoom.  Instead of rounding to the closest integer zoom level I believe
we should be rounding up to the nearest zoom level which can contain the given window.

This fixes a display issue with the ZoomSliderPanel.  I'm not 100% sure I understand the potential consequences
of changing thhis for other code that relies on it, so it would be good to have a second pair of eyes on it.
It seems intuitively to be correct now but it's possible the use case of "zoom level which is closest to the width of the given window"
was really what was wanted.  I haven't found any obvious issues with some manual testing of this change.
  • Loading branch information
lbergelson committed Oct 31, 2023
1 parent 11b0971 commit 6085ad0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/main/java/org/broad/igv/ui/panel/ReferenceFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
*/
package org.broad.igv.ui.panel;

import org.broad.igv.logging.*;
import org.broad.igv.Globals;
import org.broad.igv.event.IGVEventBus;
import org.broad.igv.event.ViewChange;
Expand All @@ -38,10 +37,11 @@
import org.broad.igv.feature.Range;
import org.broad.igv.feature.genome.Genome;
import org.broad.igv.feature.genome.GenomeManager;
import org.broad.igv.logging.LogManager;
import org.broad.igv.logging.Logger;
import org.broad.igv.prefs.Constants;
import org.broad.igv.prefs.IGVPreferences;
import org.broad.igv.prefs.PreferencesManager;
import org.broad.igv.sam.InsertionManager;
import org.broad.igv.sam.InsertionMarker;
import org.broad.igv.ui.IGV;
import org.broad.igv.ui.util.MessageUtils;
Expand All @@ -54,7 +54,7 @@
*/
public class ReferenceFrame {

private static Logger log = LogManager.getLogger(ReferenceFrame.class);
private static final Logger log = LogManager.getLogger(ReferenceFrame.class);

IGVEventBus eventBus;

Expand Down Expand Up @@ -714,7 +714,7 @@ private void beforeScaleZoom(Locus locus) {
}

/**
* Calculate the zoom level given start/end in bp.
* Calculate the minimum zoom level which can completely contain the given start/end in bp.
* Doesn't change anything
*
* @param start
Expand All @@ -723,10 +723,14 @@ private void beforeScaleZoom(Locus locus) {
*/
public int calculateZoom(double start, double end) {
final double windowLength = Math.min(end - start, getChromosomeLength());
return (int) Math.round(Globals.log2((getChromosomeLength() / windowLength) * (((double) widthInPixels) / binsPerTile)));
final double exactZoom = Globals.log2((getChromosomeLength() / windowLength) * (((double) widthInPixels) / binsPerTile));
//round up so that you get a zoom level which contains the given window
return (int) Math.ceil(exactZoom);
}




private static int getChromosomeLength(String chrName) {
Genome genome = getGenome();

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/broad/igv/ui/panel/ZoomSliderPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private void paintVisibilityThresholds(final Graphics2D transGraphics) {
.sorted()
.distinct()
.map(threshold -> this.getReferenceFrame().calculateZoom(0, threshold))
.collect(Collectors.toList());
.toList();

transGraphics.setColor(TRANSPARENT_BLUE);
Rectangle maxZoom = zoomLevelRects[zoomLevelRects.length - 1];
Expand Down

0 comments on commit 6085ad0

Please sign in to comment.