22 * License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt
33 */
44
5- import React , { memo , useEffect , useRef } from 'react' ;
5+ import React , { memo , useState , useEffect , useRef } from 'react' ;
66import PropTypes from 'prop-types' ;
77import { omit } from 'lodash' ;
88import shallowequal from 'shallowequal' ;
9- import { getPlotViewById , getAllDrawLayersForPlot , pvEqualForRender } from '../PlotViewUtil.js' ;
9+ import { getPlotViewById , getAllDrawLayersForPlot } from '../PlotViewUtil.js' ;
1010import { ImageViewerView } from './ImageViewerDecorate.jsx' ;
1111import { visRoot , ExpandType } from '../ImagePlotCntlr.js' ;
1212import { extensionRoot } from '../../core/ExternalAccessCntlr.js' ;
@@ -17,7 +17,7 @@ import {useStoreConnector} from '../../ui/SimpleComponent';
1717import { dlRoot } from '../DrawLayerCntlr' ;
1818
1919
20- const visRootOmitList = [ 'plotViewAry' , 'activePlotId' , 'processedTiles' , 'plotRequestDefaults '] ;
20+ const omitList = [ 'plotViewAry' , 'activePlotId' ] ;
2121
2222function hasVisRootChanged ( plotId , newVisRoot , oldVisRoot ) {
2323 if ( newVisRoot === oldVisRoot ) return false ;
@@ -26,16 +26,14 @@ function hasVisRootChanged(plotId,newVisRoot,oldVisRoot) {
2626 ( newVisRoot . activePlotId === plotId || oldVisRoot . activePlotId === plotId ) ) {
2727 return true ;
2828 }
29-
30- if ( ! pvEqualForRender ( getPlotViewById ( oldVisRoot , plotId ) , getPlotViewById ( newVisRoot , plotId ) ) ) return true ;
31- return ! shallowequal ( omit ( newVisRoot , visRootOmitList ) , omit ( oldVisRoot , visRootOmitList ) ) ; // compare certain keys in visRoot
29+ if ( getPlotViewById ( newVisRoot , plotId ) !== getPlotViewById ( oldVisRoot , plotId ) ) return true ;
30+ return ! shallowequal ( omit ( newVisRoot , omitList ) , omit ( oldVisRoot , omitList ) ) ; // compare certain keys in visRoot
3231}
3332
3433function hasStateChanged ( plotId , newState , oldState ) {
3534 if ( ! oldState ) return true ;
3635 if ( newState === oldState ) return false ;
37- if ( newState ?. plotView ?. localZoomStart ) return false ;
38- // if (!shallowequal(newState.drawLayersAry,oldState.drawLayersAry)) return true;
36+ if ( ! shallowequal ( newState . drawLayersAry , oldState . drawLayersAry ) ) return true ;
3937 if ( newState . extRoot !== oldState . extRoot || newState . taskCount !== oldState . taskCount ) return true ;
4038 return hasVisRootChanged ( plotId , newState . vr , oldState . vr ) ;
4139}
@@ -65,29 +63,29 @@ const TEN_SECONDS= 10000;
6563
6664export const ImageViewer = memo ( ( { showWhenExpanded= false , plotId, handleInlineTools= true , inlineTitle, aboveTitle} ) => {
6765
68- const { current : mouseRef } = useRef ( { mousePlotId : undefined } ) ;
66+ const [ mousePlotId , setMousePlotId ] = useState ( lastMouseCtx ( ) . plotId ) ;
6967 const [ { plotView, vr, drawLayersAry, taskCount} ] = useStoreConnector ( ( oldState ) => getStoreState ( plotId , oldState ) ) ;
7068 const { current :timeoutRef } = useRef ( { timeId :undefined } ) ;
7169
7270 useEffect ( ( ) => {
7371 let alive = true ;
7472 const removeListener = addImageMouseListener ( ( mState ) => {
75- mouseRef . mousePlotId = mState . plotId ;
73+ setMousePlotId ( mState . plotId ) ;
7674 timeoutRef . timeId && clearTimeout ( timeoutRef . timeId ) ;
7775 timeoutRef . timeId = undefined ;
78- if ( mState . mouseState !== MouseState . EXIT || mouseRef . mousePlotId !== plotId ) return ;
76+ if ( mState . mouseState !== MouseState . EXIT || mousePlotId !== plotId ) return ;
7977 timeoutRef . timeId = setTimeout (
8078 ( ) => {
8179 timeoutRef . timeId = undefined ;
82- if ( alive && lastMouseCtx ( ) . plotId === plotId ) mouseRef . mousePlotId = undefined ;
80+ if ( alive && lastMouseCtx ( ) . plotId === plotId ) setMousePlotId ( undefined ) ;
8381 } , TEN_SECONDS ) ; // 10 seconds
8482 } ) ;
8583 return ( ) => {
8684 alive = false ;
8785 timeoutRef . timeId && clearTimeout ( timeoutRef . timeId ) ;
8886 removeListener ( ) ;
8987 } ;
90- } , [ plotId ] ) ;
88+ } , [ mousePlotId , plotId ] ) ;
9189
9290
9391 if ( ! showWhenExpanded && vr . expandedMode !== ExpandType . COLLAPSE ) return false ;
@@ -97,7 +95,7 @@ export const ImageViewer= memo( ({showWhenExpanded=false, plotId, handleInlineTo
9795 < ImageViewerView plotView = { plotView }
9896 drawLayersAry = { drawLayersAry }
9997 visRoot = { vr }
100- mousePlotId = { mouseRef . mousePlotId }
98+ mousePlotId = { mousePlotId }
10199 handleInlineTools = { handleInlineTools }
102100 inlineTitle = { inlineTitle }
103101 aboveTitle = { aboveTitle }
0 commit comments