Skip to content

Commit 7a7a8e4

Browse files
authored
Firefly-803, 797: Merge pull request #1103 from Caltech-IPAC/firefly-803-mouse-zoom
Firefly-803: fixes mouse wheel/trackpad zoom and Simbad name lookup bug
2 parents 46f4f27 + 388ac6f commit 7a7a8e4

File tree

5 files changed

+132
-47
lines changed

5 files changed

+132
-47
lines changed

src/firefly/java/edu/caltech/ipac/astro/net/SimbadNameResolver.java

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import edu.caltech.ipac.util.CollectionUtil;
99
import edu.caltech.ipac.util.download.FailedRequestException;
1010
import edu.caltech.ipac.util.download.URLDownload;
11+
import edu.caltech.ipac.visualize.net.URLParms;
1112
import edu.caltech.ipac.visualize.plot.ResolvedWorldPt;
1213

1314
import java.net.MalformedURLException;
@@ -26,25 +27,30 @@ public class SimbadNameResolver {
2627

2728
public static ResolveResult resolveName(String objName) throws FailedRequestException {
2829
Map<String,String> tapParams= CollectionUtil.stringMap( "request", "doQuery", "format", "json", "lang", "adql");
29-
Map<String,String> resolveData= CollectionUtil.stringMap(tapParams, "query", String.format(RESOLVE_ADQL,objName) );
30-
Map<String,String> magData= CollectionUtil.stringMap(tapParams, "query", String.format(MAG_ADQL,objName) );
30+
Map<String,String> resolveData= CollectionUtil.stringMap(tapParams, "query", String.format(RESOLVE_ADQL, URLParms.encode(objName)) );
31+
Map<String,String> magData= CollectionUtil.stringMap(tapParams, "query", String.format(MAG_ADQL,URLParms.encode(objName)) );
3132
try {
3233
URL url= new URL(SIMBAD_URL_STR);
3334
String resolveJsonStr= URLDownload.getDataFromURL(url,resolveData , null, null).getResultAsString();
3435
JsonHelper json= JsonHelper.parse(resolveJsonStr);
35-
double ra = getRow0Value(json, 0,Double.NaN);
36-
double dec = getRow0Value(json, 1, Double.NaN);
36+
double ra = getRow0DoubleValue(json, 0,Double.NaN);
37+
double dec = getRow0DoubleValue(json, 1, Double.NaN);
3738
if (checkNaN(ra,dec)) throw makeEx(objName,"ra or dec is not parsable",null);
3839
ResolveResult sa= new ResolveResult(Resolver.Simbad, objName, new ResolvedWorldPt(ra, dec,objName,Resolver.Simbad));
39-
sa.setFormalName(getRow0Value(json, 2, ""));
40-
sa.setType(getRow0Value(json, 3, ""));
41-
sa.setSpectralType(getRow0Value(json, 4, ""));
42-
sa.setParallax(getRow0Value(json, 5, Double.NaN));
40+
sa.setFormalName(getRow0StringValue(json, 2, ""));
41+
sa.setType(getRow0StringValue(json, 3, ""));
42+
sa.setSpectralType(getRow0StringValue(json, 4, ""));
43+
sa.setParallax(getRow0DoubleValue(json, 5, Double.NaN));
4344

44-
String magJsonStr= URLDownload.getDataFromURL(url,magData , null, null).getResultAsString();
45-
json= JsonHelper.parse(magJsonStr);
46-
sa.setBMagnitude(getRow0Value(json, 0, Double.NaN));
47-
sa.setVMagnitude(getRow0Value(json, 1, Double.NaN));
45+
try {
46+
String magJsonStr= URLDownload.getDataFromURL(url,magData , null, null).getResultAsString();
47+
json= JsonHelper.parse(magJsonStr);
48+
sa.setBMagnitude(getRow0DoubleValue(json, 0, Double.NaN));
49+
sa.setVMagnitude(getRow0DoubleValue(json, 1, Double.NaN));
50+
} catch (Exception e) { // we not not that concerned if this fails
51+
sa.setBMagnitude(Double.NaN);
52+
sa.setVMagnitude(Double.NaN);
53+
}
4854
return sa;
4955
} catch (MalformedURLException e) {
5056
throw makeEx(objName, "Could not build Simbad URL: " + SIMBAD_URL_STR,e);
@@ -58,7 +64,22 @@ public static ResolveResult resolveName(String objName) throws FailedRequestExce
5864
private static FailedRequestException makeEx(String objName, String detailStr, Exception e) {
5965
return new FailedRequestException("Simbad did not find the object: "+ objName,detailStr, e);
6066
}
67+
6168
private static boolean checkNaN(double ra,double dec) {return Double.isNaN(ra) || Double.isNaN(dec);}
62-
private static <T> T getRow0Value(JsonHelper h, int cIdx, T def) { return h.getValue(def, "data", "0", cIdx+""); }
69+
70+
private static double getRow0DoubleValue(JsonHelper h, int cIdx, double def) {
71+
Object vObj= h.getValue("", "data", "0", cIdx+"");
72+
String vStr= vObj.toString();
73+
if (vStr.equals("")) return def;
74+
try {
75+
return Double.parseDouble(vStr);
76+
} catch (NumberFormatException e) {
77+
return Double.NaN;
78+
}
79+
}
80+
81+
private static String getRow0StringValue(JsonHelper h, int cIdx, String def) {
82+
return h.getValue(def, "data", "0", cIdx+"");
83+
}
6384

6485
}

src/firefly/js/visualize/ImageViewerLayout.jsx

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -55,35 +55,6 @@ const zoomFromWheelOrTrackpad= (usingMouseWheel, params) => {
5555
zoomThrottle(params);
5656
};
5757

58-
function handleScrollWheelEvent(plotView, mouseState, screenPt, nativeEv) {
59-
const userZoomType= mouseState===MouseState.WHEEL_DOWN ? UserZoomTypes.UP : UserZoomTypes.DOWN;
60-
nativeEv.preventDefault();
61-
const plot= primePlot(plotView) ?? {};
62-
const {screenSize}= plot;
63-
const {viewDim}= plotView ?? {};
64-
const smallImage=
65-
isImage(plot) && screenSize?.width < viewDim?.width && screenSize?.height < viewDim?.height;
66-
let useDevPt= true;
67-
let devicePt= CCUtil.getDeviceCoords(primePlot(plotView),screenPt);
68-
if (userZoomType===UserZoomTypes.DOWN) {
69-
useDevPt= !smallImage;
70-
}
71-
else if (userZoomType===UserZoomTypes.UP) {
72-
if (smallImage) {
73-
const cc= CysConverter.make(plot);
74-
useDevPt= cc.pointInPlot(devicePt);
75-
}
76-
else {
77-
useDevPt= true;
78-
}
79-
}
80-
if (!useDevPt) devicePt= undefined;
81-
82-
const usingMouseWheel= Math.abs(nativeEv.wheelDeltaY)%120 === 0;
83-
zoomFromWheelOrTrackpad(usingMouseWheel,
84-
{plotId:plotView?.plotId, userZoomType, devicePt, upDownPercent:Math.abs(nativeEv.wheelDeltaY)%120===0?1:.7 } );
85-
86-
}
8758

8859

8960
/**
@@ -199,6 +170,42 @@ export class ImageViewerLayout extends PureComponent {
199170
}
200171
}
201172

173+
handleScrollWheelEvent(plotView, mouseState, screenPt, nativeEv) {
174+
175+
if (!this.mouseWheelDevicePt) {
176+
this.mouseWheelDevicePt= CCUtil.getDeviceCoords(primePlot(plotView),screenPt);
177+
this.mouseWheelTimeoutId= setTimeout(() => {
178+
this.mouseWheelDevicePt= undefined;
179+
}, 200);
180+
}
181+
else {
182+
clearTimeout(this.mouseWheelTimeoutId);
183+
this.mouseWheelTimeoutId= setTimeout(() => {
184+
this.mouseWheelDevicePt= undefined;
185+
}, 200);
186+
}
187+
188+
189+
const userZoomType= mouseState===MouseState.WHEEL_DOWN ? UserZoomTypes.UP : UserZoomTypes.DOWN;
190+
nativeEv.preventDefault();
191+
const plot= primePlot(plotView) ?? {};
192+
const {screenSize}= plot;
193+
const {viewDim}= plotView ?? {};
194+
const smallImage=
195+
isImage(plot) && screenSize?.width < viewDim?.width && screenSize?.height < viewDim?.height;
196+
let useDevPt= true;
197+
if (smallImage) {
198+
const cc= CysConverter.make(plot);
199+
useDevPt= cc.pointInPlot(this.mouseWheelDevicePt);
200+
}
201+
202+
const usingMouseWheel= Math.abs(nativeEv.wheelDeltaY)%120 === 0;
203+
204+
zoomFromWheelOrTrackpad(usingMouseWheel,
205+
{plotId:plotView?.plotId, userZoomType, devicePt: useDevPt ? this.mouseWheelDevicePt : undefined,
206+
upDownPercent:Math.abs(nativeEv.wheelDeltaY)%120===0?1: isHiPS(plot)? .2 : .5 } );
207+
208+
}
202209

203210
eventCB(plotId,mouseState,screenPt,screenX,screenY,nativeEv) {
204211
const {drawLayersAry,plotView}= this.props;
@@ -213,7 +220,7 @@ export class ImageViewerLayout extends PureComponent {
213220
}
214221
else if (isWheel(mouseState)) {
215222
if (!isActivePlotView(visRoot(),plotId) && getAppOptions()?.wheelScrollRequiresImageActive) return;
216-
handleScrollWheelEvent(plotView,mouseState,screenPt,nativeEv);
223+
this.handleScrollWheelEvent(plotView,mouseState,screenPt,nativeEv);
217224
return;
218225
}
219226
else {

src/firefly/js/visualize/VisUtil.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,24 @@ const computeSimpleSlopeAngle = function (fromPt, toPt) {
8686
};
8787

8888

89+
export function getLonDist(lon1,lon2) {
90+
if (lon1>lon2) {
91+
const diff= lon1-lon2;
92+
if (diff<=180) return -diff;
93+
else return ( (360-lon1) - lon2);
94+
}
95+
else {
96+
const diff= lon2-lon1;
97+
if (diff<=180) return diff;
98+
else return -1*( (360-lon2) - lon1);
99+
100+
}
101+
}
102+
103+
export function getLatDist(lat1,lat2) {
104+
return -1*(lat1-lat2);
105+
}
106+
89107
/**
90108
* Convert from one coordinate system to another.
91109
*

src/firefly/js/visualize/reducer/PlotView.js

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import Enum from 'enum';
77
import {PlotAttribute} from '../PlotAttribute';
88
import {isImage, isHiPS} from '../WebPlot.js';
99
import {WPConst} from '../WebPlotRequest';
10-
import {makeScreenPt, makeDevicePt, makeImagePt} from '../Point';
10+
import {makeScreenPt, makeDevicePt, makeImagePt, makeWorldPt} from '../Point';
1111
import {getActiveTarget} from '../../core/AppDataCntlr.js';
12-
import {getCenterPtOfPlot} from '../VisUtil.js';
12+
import { getCenterPtOfPlot, getLatDist, getLonDist } from '../VisUtil.js';
1313
import {getPlotViewById, matchPlotViewByPositionGroup, primePlot, findCurrentCenterPoint} from '../PlotViewUtil.js';
1414
import {changeProjectionCenter} from '../HiPSUtil.js';
1515
import {UserZoomTypes} from '../ZoomUtil.js';
@@ -539,3 +539,42 @@ export function findHipsCenProjToPlaceWptOnDevPt(pv, wpt, targetDevPtPos) {
539539
const tarAsDevPt= cc.getDeviceCoords(wpt);
540540
return cc.getWorldCoords(makeDevicePt(tarAsDevPt.x-offX, tarAsDevPt.y-offY));
541541
}
542+
export function findHipsCenProjToPlaceWptOnDevPtNEW(pv, wpt, targetDevPtPos) {
543+
const plot= primePlot(pv);
544+
const cc= CysConverter.make(plot);
545+
const {viewDim:{width,height}}= plot;
546+
const offX= targetDevPtPos.x-width/2;
547+
const offY= targetDevPtPos.y-height/2;
548+
// const tarAsDevPt= cc.getDeviceCoords(wpt);
549+
const centerDevPt= makeDevicePt(targetDevPtPos.x-offX, targetDevPtPos.y-offY);
550+
551+
const wp1= cc.getWorldCoords(targetDevPtPos);
552+
const wp2= cc.getWorldCoords(centerDevPt);
553+
if (!wp1 || !wp2) return undefined;
554+
const lonDist= getLonDist(wp1.x,wp2.x);
555+
const latDist= getLatDist(wp1.y,wp2.y);
556+
const newCenterWp= makeWorldPt(wpt.x+lonDist,wpt.y+latDist, wpt.cSys);
557+
// const newCenterWp= calculatePosition(wpt, lonDist, latDist);
558+
return newCenterWp;
559+
}
560+
561+
// export function findHipsCenProjToPlaceWptOnDevPtNEW2(pv, wpt, targetDevPtPos) {
562+
// const plot= primePlot(pv);
563+
// const cc= CysConverter.make(plot);
564+
// const {viewDim:{width,height}}= plot;
565+
// const offX= targetDevPtPos.x-width/2;
566+
// const offY= targetDevPtPos.y-height/2;
567+
// // const tarAsDevPt= cc.getDeviceCoords(wpt);
568+
// const centerDevPt= makeDevicePt(targetDevPtPos.x-offX, targetDevPtPos.y-offY);
569+
//
570+
// const wp1= cc.getWorldCoords(targetDevPtPos);
571+
// const wp2= cc.getWorldCoords(centerDevPt);
572+
// if (!wp1 || !wp2) return undefined;
573+
// // const lonDist= computeDistanceAngularDistance(wp1.x, wp1.y, wp2.x, wp1.y);
574+
// // const latDist= computeDistanceAngularDistance(wp1.x, wp1.y, wp1.x, wp2.y);
575+
// // const lonDist= getLonDist(wp1.x,wp2.x);
576+
// // const latDist= getLatDist(wp1.y,wp2.y);
577+
// const newCenterWp= makeWorldPt(wpt.x+lonDist,wpt.y+latDist, wpt.cSys);
578+
// // const newCenterWp= calculatePosition(wpt, lonDist, latDist);
579+
// return newCenterWp;
580+
// }

src/firefly/js/visualize/task/ZoomTask.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {doHiPSImageConversionIfNecessary} from './PlotHipsTask.js';
2222
import {matchImageToHips, matchHiPStoPlotView} from './WcsMatchTask';
2323
import PlotState from '../PlotState.js';
2424
import {changeLocalRawDataZoom} from '../rawData/RawDataOps.js';
25-
import {findHipsCenProjToPlaceWptOnDevPt} from '../reducer/PlotView.js';
25+
import { findHipsCenProjToPlaceWptOnDevPtNEW, } from '../reducer/PlotView.js';
2626
import {CCUtil} from '../CsysConverter.js';
2727

2828

@@ -251,7 +251,7 @@ function doZoom(dispatcher,plot,zoomLevel,isFullScreen, zoomLockingEnabled, user
251251
const postZoomVisRoot= getState()[IMAGE_PLOT_KEY];
252252
const postPv= getPlotViewById(postZoomVisRoot,plotId);
253253
if (wptBeforeZoom) {
254-
const centerProjPt= findHipsCenProjToPlaceWptOnDevPt(postPv,wptBeforeZoom,devicePt);
254+
const centerProjPt= findHipsCenProjToPlaceWptOnDevPtNEW(postPv,wptBeforeZoom,devicePt);
255255
centerProjPt && dispatchChangeCenterOfProjection({plotId,centerProjPt});
256256
}
257257
}

0 commit comments

Comments
 (0)