22 * License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt
33 */
44
5- import { take , race , call } from 'redux-saga/effects' ;
6- import { isEmpty , get , debounce } from 'lodash' ;
7- import ImagePlotCntlr , { visRoot } from '../ImagePlotCntlr.js' ;
5+ import { race , call } from 'redux-saga/effects' ;
6+ import { get } from 'lodash' ;
7+ import { visRoot } from '../ImagePlotCntlr.js' ;
88import { clone } from '../../util/WebUtil.js' ;
99import { readoutRoot , dispatchReadoutData , makeValueReadoutItem , makePointReadoutItem ,
1010 makeDescriptionItem , isLockByClick } from '../MouseReadoutCntlr.js' ;
1111import { callGetFileFlux } from '../../rpc/PlotServicesJson.js' ;
1212import { Band } from '../Band.js' ;
1313import { MouseState } from '../VisMouseSync.js' ;
1414import { isBlankImage } from '../WebPlot.js' ;
15- import { primePlot , getPlotStateAry , getActivePlotView } from '../PlotViewUtil.js' ;
15+ import { primePlot , getPlotStateAry , getPlotViewById } from '../PlotViewUtil.js' ;
1616import { mouseUpdatePromise } from '../VisMouseSync.js' ;
1717
1818
@@ -22,41 +22,47 @@ const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
2222
2323export function * watchReadout ( ) {
2424
25- var lockByClick = false ;
25+ var lockByClick ;
2626 var mouseCtx ;
2727 yield call ( mouseUpdatePromise ) ;
2828
2929 mouseCtx = yield call ( mouseUpdatePromise ) ;
3030
31+ var getNextWithFlux ;
32+ var threeColor = false ;
33+ var plotView ;
3134
3235
3336 while ( true ) {
3437
38+ getNextWithFlux = false ;
3539 lockByClick = isLockByClick ( readoutRoot ( ) ) ;
36- var { plotId, worldPt, screenPt, imagePt, mouseState} = mouseCtx ;
40+ const { plotId, worldPt, screenPt, imagePt, mouseState} = mouseCtx ;
3741
38- if ( ! usePayload ( mouseState , lockByClick ) ) {
39- if ( ! lockByClick ) {
40- dispatchReadoutData ( plotId , { } ) ;
41- }
42- mouseCtx = yield call ( mouseUpdatePromise ) ;
43- continue ;
44- }
42+ if ( usePayload ( mouseState , lockByClick ) ) {
43+ plotView = getPlotViewById ( visRoot ( ) , plotId ) ;
44+ var plot = primePlot ( plotView ) ;
4545
46- const plotView = getActivePlotView ( visRoot ( ) ) ;
47- var plot = primePlot ( plotView ) ;
46+ if ( plot ) {
47+ var readout = makeReadoutWithFlux ( makeReadout ( plot , worldPt , screenPt , imagePt ) , plot , null , plot . plotState . threeColor ) ;
48+ threeColor = plot . plotState . isThreeColor ( ) ;
49+ dispatchReadoutData ( plotId , readout , threeColor ) ;
4850
49- var readout = makeReadout ( plot , worldPt , screenPt , imagePt ) ;
50- const threeColor = plot . plotState . isThreeColor ( ) ;
51- dispatchReadoutData ( plotId , readout , threeColor ) ;
51+ getNextWithFlux = ! isBlankImage ( plot ) ;
52+ }
53+ }
54+ else if ( ! lockByClick ) {
55+ dispatchReadoutData ( plotId , { } ) ;
56+ }
5257
53- if ( isBlankImage ( plot ) ) {
58+ if ( getNextWithFlux ) { // get the next mouse event or the flux
59+ mouseCtx = lockByClick ? yield call ( processImmediateFlux , readout , plotView , imagePt , threeColor ) :
60+ yield call ( processDelayedFlux , readout , plotView , imagePt , threeColor ) ;
61+ }
62+ else { // get the next mouse event
5463 mouseCtx = yield call ( mouseUpdatePromise ) ;
55- continue ;
5664 }
5765
58- mouseCtx = lockByClick ? yield call ( processImmediateFlux , readout , plotView , imagePt , threeColor ) :
59- yield call ( processDelayedFlux , readout , plotView , imagePt , threeColor ) ;
6066 }
6167}
6268
@@ -123,11 +129,11 @@ function usePayload(mouseState, lockByClick) {
123129
124130/**
125131 *
126- * @param plot
127- * @param worldPt
128- * @param screenPt
129- * @param imagePt
130- * @return {{worldPt: *, screenPt: *, imagePt: *, threeColor: (*| boolean), title: *, pixel: ({title, value, unit, precision}|{title: *, value: *, unit: *, precision: *})} }
132+ * @param { WebPlot } plot
133+ * @param { WorldPt } worldPt
134+ * @param { ScreenPt } screenPt
135+ * @param { ImagePt } imagePt
136+ * @return {{worldPt: *, screenPt: *, imagePt: *, threeColor: (boolean), title: *, pixel: ({title, value, unit, precision}|{title: *, value: *, unit: *, precision: *})} }
131137 */
132138function makeReadout ( plot , worldPt , screenPt , imagePt ) {
133139 return {
@@ -145,26 +151,28 @@ function makeReadout(plot, worldPt, screenPt, imagePt) {
145151/**
146152 *
147153 * @param readout
148- * @param plot
154+ * @param { WebPlot } plot
149155 * @param fluxResult
150156 * @param threeColor
151157 * @return {* }
152158 */
153159function makeReadoutWithFlux ( readout , plot , fluxResult , threeColor ) {
154160 readout = clone ( readout ) ;
155- const fluxData = getFlux ( fluxResult , plot ) ;
161+ const fluxData = fluxResult ? getFlux ( fluxResult , plot ) : null ;
156162 const labels = getFluxLabels ( plot ) ;
157163 if ( threeColor ) {
158164 const bands = plot . plotState . getBands ( ) ;
159165 bands . forEach ( ( b , idx ) => readout [ b . key + 'Flux' ] =
160- makeValueReadoutItem ( labels [ idx ] , fluxData [ idx ] . value , fluxData [ idx ] . unit , 6 ) ) ;
166+ makeValueReadoutItem ( labels [ idx ] , get ( fluxData , [ idx , ' value' ] ) , get ( fluxData , [ idx , ' unit' ] ) , 6 ) ) ;
161167 }
162168 else {
163- readout . nobandFlux = makeValueReadoutItem ( labels [ 0 ] , fluxData [ 0 ] . value , fluxData [ 0 ] . unit , 6 ) ;
169+ readout . nobandFlux = makeValueReadoutItem ( labels [ 0 ] , get ( fluxData , [ 0 , ' value' ] ) , get ( fluxData , [ 0 , ' unit' ] ) , 6 ) ;
164170 }
165- const oIdx = fluxData . findIndex ( ( d ) => d . imageOverlay ) ;
166- if ( oIdx > - 1 ) {
167- readout . imageOverlay = makeValueReadoutItem ( 'mask' , fluxData [ oIdx ] . value , fluxData [ oIdx ] . unit , 0 ) ;
171+ if ( fluxData ) {
172+ const oIdx = fluxData . findIndex ( ( d ) => d . imageOverlay ) ;
173+ if ( oIdx > - 1 ) {
174+ readout . imageOverlay = makeValueReadoutItem ( 'mask' , fluxData [ oIdx ] . value , fluxData [ oIdx ] . unit , 0 ) ;
175+ }
168176 }
169177 return readout ;
170178}
0 commit comments