2
2
* License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt
3
3
*/
4
4
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' ;
8
8
import { clone } from '../../util/WebUtil.js' ;
9
9
import { readoutRoot , dispatchReadoutData , makeValueReadoutItem , makePointReadoutItem ,
10
10
makeDescriptionItem , isLockByClick } from '../MouseReadoutCntlr.js' ;
11
11
import { callGetFileFlux } from '../../rpc/PlotServicesJson.js' ;
12
12
import { Band } from '../Band.js' ;
13
13
import { MouseState } from '../VisMouseSync.js' ;
14
14
import { isBlankImage } from '../WebPlot.js' ;
15
- import { primePlot , getPlotStateAry , getActivePlotView } from '../PlotViewUtil.js' ;
15
+ import { primePlot , getPlotStateAry , getPlotViewById } from '../PlotViewUtil.js' ;
16
16
import { mouseUpdatePromise } from '../VisMouseSync.js' ;
17
17
18
18
@@ -22,41 +22,47 @@ const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
22
22
23
23
export function * watchReadout ( ) {
24
24
25
- var lockByClick = false ;
25
+ var lockByClick ;
26
26
var mouseCtx ;
27
27
yield call ( mouseUpdatePromise ) ;
28
28
29
29
mouseCtx = yield call ( mouseUpdatePromise ) ;
30
30
31
+ var getNextWithFlux ;
32
+ var threeColor = false ;
33
+ var plotView ;
31
34
32
35
33
36
while ( true ) {
34
37
38
+ getNextWithFlux = false ;
35
39
lockByClick = isLockByClick ( readoutRoot ( ) ) ;
36
- var { plotId, worldPt, screenPt, imagePt, mouseState} = mouseCtx ;
40
+ const { plotId, worldPt, screenPt, imagePt, mouseState} = mouseCtx ;
37
41
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 ) ;
45
45
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 ) ;
48
50
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
+ }
52
57
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
54
63
mouseCtx = yield call ( mouseUpdatePromise ) ;
55
- continue ;
56
64
}
57
65
58
- mouseCtx = lockByClick ? yield call ( processImmediateFlux , readout , plotView , imagePt , threeColor ) :
59
- yield call ( processDelayedFlux , readout , plotView , imagePt , threeColor ) ;
60
66
}
61
67
}
62
68
@@ -123,11 +129,11 @@ function usePayload(mouseState, lockByClick) {
123
129
124
130
/**
125
131
*
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: *})} }
131
137
*/
132
138
function makeReadout ( plot , worldPt , screenPt , imagePt ) {
133
139
return {
@@ -145,26 +151,28 @@ function makeReadout(plot, worldPt, screenPt, imagePt) {
145
151
/**
146
152
*
147
153
* @param readout
148
- * @param plot
154
+ * @param { WebPlot } plot
149
155
* @param fluxResult
150
156
* @param threeColor
151
157
* @return {* }
152
158
*/
153
159
function makeReadoutWithFlux ( readout , plot , fluxResult , threeColor ) {
154
160
readout = clone ( readout ) ;
155
- const fluxData = getFlux ( fluxResult , plot ) ;
161
+ const fluxData = fluxResult ? getFlux ( fluxResult , plot ) : null ;
156
162
const labels = getFluxLabels ( plot ) ;
157
163
if ( threeColor ) {
158
164
const bands = plot . plotState . getBands ( ) ;
159
165
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 ) ) ;
161
167
}
162
168
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 ) ;
164
170
}
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
+ }
168
176
}
169
177
return readout ;
170
178
}
0 commit comments