fix zoom level calculation

This commit is contained in:
Eyck Jentzsch 2021-11-16 11:28:32 +01:00
parent efa6544623
commit 92662c546a
1 changed files with 10 additions and 9 deletions

View File

@ -190,7 +190,6 @@ public class WaveformCanvas extends Canvas {
if(level<0) level = 0; if(level<0) level = 0;
} }
//FIXME: keep center if zoom-out and cursor is not in view //FIXME: keep center if zoom-out and cursor is not in view
long xc=centerTime/this.scaleFactor; // cursor total x-offset
if(level<Constants.UNIT_MULTIPLIER.length*Constants.UNIT_STRING.length){ if(level<Constants.UNIT_MULTIPLIER.length*Constants.UNIT_STRING.length){
this.scaleFactor = (long) Math.pow(10, level>>1); this.scaleFactor = (long) Math.pow(10, level>>1);
if(level%2==1) this.scaleFactor*=3; if(level%2==1) this.scaleFactor*=3;
@ -202,7 +201,9 @@ public class WaveformCanvas extends Canvas {
* xcn = tc/newScaleFactor * xcn = tc/newScaleFactor
* t0n = (xcn-xoffs)*scaleFactor * t0n = (xcn-xoffs)*scaleFactor
*/ */
long xoffs=xc+origin.x; // cursor offset relative to left border Rectangle clientArea = getClientArea();
long clientAreaWidth = clientArea.width;
long xoffs = clientAreaWidth/2;
long xcn=centerTime/scaleFactor; // new total x-offset long xcn=centerTime/scaleFactor; // new total x-offset
long originX=xcn-xoffs; long originX=xcn-xoffs;
if(originX>0) { if(originX>0) {
@ -217,20 +218,20 @@ public class WaveformCanvas extends Canvas {
} }
} }
private int findFitZoomLevel(long timeRange) { private int findFitZoomLevel(long duration) {
//get area actually capable of displaying data, i.e. area of the receiver which is capable of displaying data //get area actually capable of displaying data, i.e. area of the receiver which is capable of displaying data
Rectangle clientArea = getClientArea(); Rectangle clientArea = getClientArea();
long clientAreaWidth = clientArea.width; long clientAreaWidth = clientArea.width;
//try to find existing zoomlevel where scaleFactor*clientAreaWidth >= maxTime, if one is found set it as new zoomlevel //try to find existing zoomlevel where scaleFactor*clientAreaWidth >= maxTime, if one is found set it as new zoomlevel
int magnitude_factor=1; final long[] UNIT_STRING_MULT={1, 1000, 1000*1000, 1000*1000*1000, 1000*1000*1000*1000, 1000*1000*1000*1000*1000 };
for(int magnitude=0; magnitude<Constants.UNIT_STRING.length; magnitude++) { for(int magnitude=0; magnitude<Constants.UNIT_STRING.length; magnitude++) {
long magnitudeMultiplier = UNIT_STRING_MULT[magnitude];
for (int multiplier=0; multiplier<Constants.UNIT_MULTIPLIER.length; multiplier++){ for (int multiplier=0; multiplier<Constants.UNIT_MULTIPLIER.length; multiplier++){
int tempLevel = magnitude*Constants.UNIT_MULTIPLIER.length+multiplier; long scaleFactor = magnitudeMultiplier * Constants.UNIT_MULTIPLIER[multiplier];
long scaleFactor = Constants.UNIT_MULTIPLIER[multiplier]*magnitude_factor; long range = scaleFactor*clientAreaWidth;
if(scaleFactor*clientAreaWidth >= timeRange) if( range >= duration)
return tempLevel; return magnitude*Constants.UNIT_MULTIPLIER.length+multiplier;
} }
magnitude_factor*=1000;
} }
return -1; return -1;
} }