diff --git a/src/firefly/js/visualize/CsysConverter.js b/src/firefly/js/visualize/CsysConverter.js index 015353b0d8..ac2f02fbce 100644 --- a/src/firefly/js/visualize/CsysConverter.js +++ b/src/firefly/js/visualize/CsysConverter.js @@ -356,7 +356,7 @@ export class CysConverter { getDevicePtCoordsOptimize(wpt, retPt) { const success= this.getScreenCoordsOptimize(wpt,retPt); - if (!success) return false; + if (!success || !this.affTrans) return false; const {x,y}= Matrix.from(this.affTrans).applyToPoint(retPt.x,retPt.y); retPt.x= x; retPt.y= y; @@ -371,7 +371,7 @@ export class CysConverter { * @return {DevicePt} */ makeDevicePtFromSp(sp, altTransform) { - if (!sp) return null; + if (!sp || !this.affTrans) return null; const {x,y}= Matrix.from(altTransform || this.affTrans).applyToPoint(sp.x,sp.y); return makeDevicePt(x,y); } @@ -421,7 +421,7 @@ export class CysConverter { } makeSpFromDevPt(devPt) { - if (!devPt) return null; + if (!devPt || !this.affTrans) return null; const {x,y}= Matrix.from(this.affTrans).inverse().applyToPoint(devPt.x,devPt.y); return makeScreenPt(x,y); } diff --git a/src/firefly/js/visualize/ImageViewerLayout.jsx b/src/firefly/js/visualize/ImageViewerLayout.jsx index fc0a4b3502..0d9bcc78d1 100644 --- a/src/firefly/js/visualize/ImageViewerLayout.jsx +++ b/src/firefly/js/visualize/ImageViewerLayout.jsx @@ -4,7 +4,7 @@ import React, {Component, PureComponent} from 'react'; import PropTypes from 'prop-types'; -import {xor,isEmpty,get, isString, isFunction, throttle} from 'lodash'; +import {xor,isNil, isEmpty,get, isString, isFunction, throttle} from 'lodash'; import {ImageRender} from './iv/ImageRender.jsx'; import {EventLayer} from './iv/EventLayer.jsx'; import {ImageViewerStatus} from './iv/ImageViewerStatus.jsx'; @@ -273,6 +273,7 @@ function isImageOnScreen(plotView) { const {viewDim}= plotView; const plot= primePlot(plotView); + if (isNil(plotView.scrollX) || isNil(plotView.scrollY)) return false; const cc= CysConverter.make(plot); const {screenSize}= plot; const devAsScreenAry= [ @@ -486,11 +487,15 @@ class DrawingLayers extends Component { shouldComponentUpdate(np) { const p= this.props; - return np.plot!==p.plot || !isEmpty(xor(np.drawLayersIdAry,p.drawLayersIdAry)); + return np.plot!==p.plot || !isEmpty(xor(np.drawLayersIdAry,p.drawLayersIdAry)) || + np.plotView.scrollX!==p.plotView.scrollX || np.plotView.scrollY!==p.plotView.scrollY; } - + render() { const {plotView:pv, plot, drawLayersIdAry:dlIdAry}= this.props; + const {scrollX, scrollY}= pv; + const draw= !isNil(scrollX) && !isNil(scrollY); + if (!draw) return null; let drawingAry= null; const {width,height}= pv.viewDim; if (dlIdAry) { diff --git a/src/firefly/js/visualize/PlotTransformUtils.js b/src/firefly/js/visualize/PlotTransformUtils.js index 9709918c2f..03a2113d2f 100644 --- a/src/firefly/js/visualize/PlotTransformUtils.js +++ b/src/firefly/js/visualize/PlotTransformUtils.js @@ -6,7 +6,7 @@ * License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt */ -import {get} from 'lodash'; +import {get, isNil} from 'lodash'; import {Matrix} from 'transformation-matrix-js'; import {primePlot} from './PlotViewUtil.js'; import {clone, updateSet} from '../util/WebUtil.js'; @@ -57,6 +57,7 @@ export function updateTransform(pv) { * @return {Matrix} */ export function makeTransform(offsetX,offsetY,scrollX,scrollY, rotation, flipX, flipY, viewDim) { + if (isNil(scrollX) || isNil(scrollY)) return undefined; const left= offsetX-scrollX; const top= offsetY-scrollY; const {width:w, height:h}= viewDim; diff --git a/src/firefly/js/visualize/iv/CanvasTileDrawer.js b/src/firefly/js/visualize/iv/CanvasTileDrawer.js index dfe52804dc..fbd7307477 100644 --- a/src/firefly/js/visualize/iv/CanvasTileDrawer.js +++ b/src/firefly/js/visualize/iv/CanvasTileDrawer.js @@ -3,6 +3,7 @@ */ import CsysConverter from '../CsysConverter.js'; +import {isNil} from 'lodash'; import {makeDevicePt} from '../Point.js'; import {createImageUrl,isTileVisible} from './TileDrawHelper.jsx'; import {makeTransform} from '../PlotTransformUtils.js'; @@ -222,9 +223,11 @@ function renderToScreen(plotView, targetCanvas, offscreenCanvas, opacity, offset const {scrollX, scrollY, flipX,flipY, viewDim, rotation}= plotView; if (flipY) offsetX*=-1; - const affTrans= makeTransform(offsetX,offsetY, scrollX, scrollY, rotation, flipX, flipY, viewDim); - ctx.setTransform(affTrans.a, affTrans.b, affTrans.c, affTrans.d, affTrans.e, affTrans.f); - ctx.drawImage(offscreenCanvas, 0,0); + if (!isNil(plotView.scrollX) && !isNil(plotView.scrollY)) { + const affTrans= makeTransform(offsetX,offsetY, scrollX, scrollY, rotation, flipX, flipY, viewDim); + ctx.setTransform(affTrans.a, affTrans.b, affTrans.c, affTrans.d, affTrans.e, affTrans.f); + ctx.drawImage(offscreenCanvas, 0,0); + } ctx.restore(); }); } diff --git a/src/firefly/js/visualize/reducer/HandlePlotChange.js b/src/firefly/js/visualize/reducer/HandlePlotChange.js index 6c1daae2c1..fb200145bb 100644 --- a/src/firefly/js/visualize/reducer/HandlePlotChange.js +++ b/src/firefly/js/visualize/reducer/HandlePlotChange.js @@ -396,10 +396,13 @@ function updateViewSize(state,action) { const newSp= findWCSMatchScrollPosition(state, state.mpwWcsPrimId, plotId, makeScreenPt(scrollX,scrollY)); pv= updatePlotViewScrollXY(pv, newSp); } + else if (isUndefined(pv.scrollX) || isUndefined(pv.scrollY)) { + pv= recenterPv(null, false)(pv); + } else { const centerImagePt= (pv.scrollX<0 || pv.scrollY<0) ? - makeImagePt(plot.dataWidth/2, plot.dataHeight/2) : - findCurrentCenterPoint(pv); + makeImagePt(plot.dataWidth/2, plot.dataHeight/2) : + findCurrentCenterPoint(pv); pv= updatePlotViewScrollXY(pv, findScrollPtToCenterImagePt(pv,centerImagePt)); } diff --git a/src/firefly/js/visualize/reducer/PlotView.js b/src/firefly/js/visualize/reducer/PlotView.js index 5b571a2a26..c62eb44cd2 100644 --- a/src/firefly/js/visualize/reducer/PlotView.js +++ b/src/firefly/js/visualize/reducer/PlotView.js @@ -259,7 +259,8 @@ export function replacePlots(pv, plotAry, overlayPlotViews, expandedMode, newPlo * @return {PlotView} new copy of plotView */ export function updatePlotViewScrollXY(plotView,newScrollPt) { - if (!plotView || !newScrollPt) return plotView; + if (!plotView) return plotView; + if (!newScrollPt) return Object.assign({},plotView, {scrollX:undefined, scrollY:undefined}); const plot= primePlot(plotView); if (!plot) return plotView; @@ -461,13 +462,17 @@ export function findCurrentCenterPoint(plotView,scrollX,scrollY) { const {viewDim}= plotView; let cc; - if (isUndefined(scrollX) || isUndefined(scrollY)) { - cc= CysConverter.make(plot); - } - else { + if (!isUndefined(scrollX) && isUndefined(!scrollY)) { const trans= makeTransform(0,0, scrollX, scrollY, plotView.rotation, plotView.flipX, plotView.flipY, viewDim); cc= CysConverter.make(plot,trans); } + else if (isUndefined(plotView.scrollX) || isUndefined(plotView.scrollY)) { + const trans= makeTransform(0,0, 0, 0, plotView.rotation, plotView.flipX, plotView.flipY, viewDim); + cc= CysConverter.make(plot,trans); + } + else { + cc= CysConverter.make(plot); + } const pt= makeDevicePt(viewDim.width/2, viewDim.height/2); return cc.getImageCoords(pt); } @@ -532,13 +537,18 @@ export function findScrollPtToCenterImagePt(plotView, ipt) { */ export function findScrollPtToPlaceOnDevPt(pv, ipt, targetDevPtPos) { const plot= primePlot(pv); - const point= CCUtil.getScreenCoords(plot, ipt); - const target= CCUtil.getScreenCoords(plot, targetDevPtPos); + const altAffTrans= makeTransform(0,0, 0, 0, pv.rotation, pv.flipX, pv.flipY, pv.viewDim); + const cc= CysConverter.make(plot,altAffTrans); + + const point= cc.getScreenCoords(ipt); + if (!point) return null; + + const target= cc.getScreenCoords(targetDevPtPos); + if (!target) return null; const x= point.x - target.x; const y= point.y - target.y; - - return makeScreenPt(pv.flipY ? pv.scrollX-x : pv.scrollX+x,pv.flipX ? pv.scrollY-y : pv.scrollY+y); + return makeScreenPt(pv.flipY ? -x : x,pv.flipX ? -y : y); }