@@ -30,10 +30,23 @@ export const DEF_IMAGE_CNT= 5;
30
30
export const MAX_IMAGE_CNT = 7 ;
31
31
const plotIdRoot = 'LC_FRAME-' ;
32
32
33
+
34
+ var webplotRequestCreator ;
35
+ /**
36
+ * A function to create a WebPlotRequest from the given parameters
37
+ * @callback WebplotRequestCreator
38
+ * @param {TableModel } tableModel
39
+ * @param {number } hlrow
40
+ * @param {number } cutoutSize
41
+ */
42
+
33
43
/**
34
- * This event manager is custom made for light curve viewer.
44
+ * This event manager is custom made for light curve viewer.
45
+ * @param {Object } params
46
+ * @props {WebplotRequestCreator} params.webplotRequestCreator
35
47
*/
36
- export function * lcManager ( ) {
48
+ export function * lcManager ( params = { } ) {
49
+ webplotRequestCreator = params . WebplotRequestCreator || getWebPlotRequestViaUrl ;
37
50
38
51
while ( true ) {
39
52
const action = yield take ( [
@@ -87,7 +100,7 @@ function handleTableLoad(layoutInfo, action) {
87
100
if ( isImageEnabledTable ( tbl_id ) ) {
88
101
layoutInfo = updateSet ( layoutInfo , 'showImages' , true ) ;
89
102
layoutInfo = updateSet ( layoutInfo , 'images.activeTableId' , tbl_id ) ;
90
- exec ( setupImages , tbl_id ) ;
103
+ setupImages ( tbl_id ) ;
91
104
}
92
105
return layoutInfo ;
93
106
}
@@ -98,15 +111,15 @@ function handleTableActive(layoutInfo, action) {
98
111
const { tbl_id} = action . payload ;
99
112
if ( isImageEnabledTable ( tbl_id ) ) {
100
113
layoutInfo = updateSet ( layoutInfo , 'images.activeTableId' , tbl_id ) ;
101
- exec ( setupImages , tbl_id ) ;
114
+ setupImages ( tbl_id ) ;
102
115
}
103
116
return layoutInfo ;
104
117
}
105
118
106
119
function handleTableHighlight ( layoutInfo , action ) {
107
120
const { tbl_id} = action . payload ;
108
121
if ( isImageEnabledTable ( tbl_id ) ) {
109
- exec ( setupImages , tbl_id ) ;
122
+ setupImages ( tbl_id ) ;
110
123
}
111
124
}
112
125
@@ -117,7 +130,7 @@ function isImageEnabledTable(tbl_id) {
117
130
function handleChangeMultiViewLayout ( layoutInfo , action ) {
118
131
const activeTableId = get ( layoutInfo , 'images.activeTableId' ) ;
119
132
const tbl = getTblById ( activeTableId ) ;
120
- if ( get ( tbl , 'totalRows' , 0 ) > 0 ) exec ( setupImages , activeTableId ) ;
133
+ if ( get ( tbl , 'totalRows' , 0 ) > 0 ) setupImages ( activeTableId ) ;
121
134
return layoutInfo ;
122
135
}
123
136
@@ -157,7 +170,7 @@ function getWebPlotRequest(tableModel, hlrow) {
157
170
158
171
}
159
172
160
- function getWebPlotRequestViaUrl ( tableModel , hlrow ) {
173
+ function getWebPlotRequestViaUrl ( tableModel , hlrow , cutoutSize ) {
161
174
const ra = getCellValue ( tableModel , hlrow , 'ra' ) ;
162
175
const dec = getCellValue ( tableModel , hlrow , 'dec' ) ;
163
176
const frameId = getCellValue ( tableModel , hlrow , 'frame_id' ) ;
@@ -167,21 +180,18 @@ function getWebPlotRequestViaUrl(tableModel, hlrow) {
167
180
const scangrp = res [ 2 ] ;
168
181
const frame_num = res [ 3 ] ;
169
182
170
- let { cutoutSize} = FieldGroupUtils . getGroupFields ( grpkey ) ;
171
- const cutoutsize = cutoutSize . value ;
172
-
173
183
/*the following should be from reading in the url column returned from LC search
174
184
we are constructing the url for wise as the LC table does
175
185
not have the url colume yet
176
186
It is only for WISE, using default cutout size 0.3 deg
177
187
const url = `http://irsa.ipac.caltech.edu/ibe/data/wise/merge/merge_p1bm_frm/${scangrp}/${scan_id}/${frame_num}/${scan_id}${frame_num}-w1-int-1b.fits`;
178
188
*/
179
189
const serverinfo = 'http://irsa.ipac.caltech.edu/ibe/data/wise/merge/merge_p1bm_frm/' ;
180
- const centerandsize = `?center=${ ra } ,${ dec } &size=${ cutoutsize } &gzip=false` ;
190
+ const centerandsize = cutoutSize ? `?center=${ ra } ,${ dec } &size=${ cutoutSize } &gzip=false` : '' ;
181
191
const url = `${ serverinfo } ${ scangrp } /${ scan_id } /${ frame_num } /${ scan_id } ${ frame_num } -w1-int-1b.fits${ centerandsize } ` ;
182
192
const plot_desc = `WISE-${ frameId } ` ;
183
193
const reqParams = WebPlotRequest . makeURLPlotRequest ( url , plot_desc ) ;
184
- reqParams . setTitle ( 'WISE-' + frameId + ' size: ' + cutoutsize + ' (deg)' ) ;
194
+ reqParams . setTitle ( 'WISE-' + frameId + ( cutoutSize ? ` size: ${ cutoutSize } (deg)` : '' ) ) ;
185
195
reqParams . setTitleOptions ( TitleOptions . NONE ) ;
186
196
reqParams . setGroupLocked ( true ) ;
187
197
reqParams . setPlotGroupId ( 'LightCurveGroup' ) ;
@@ -193,37 +203,42 @@ function getWebPlotRequestViaUrl(tableModel, hlrow) {
193
203
}
194
204
195
205
export function setupImages ( tbl_id ) {
196
- const viewer = getViewer ( getMultiViewRoot ( ) , IMG_VIEWER_ID ) ;
197
- const count = get ( viewer , 'layoutDetail.count' , DEF_IMAGE_CNT ) ;
198
- const tableModel = getTblById ( tbl_id ) ;
199
- if ( ! tableModel || isNil ( tableModel . highlightedRow ) ) return ;
200
- var vr = visRoot ( ) ;
201
- const newPlotIdAry = makePlotIds ( tableModel . highlightedRow , tableModel . totalRows , count ) ;
202
- const maxPlotIdAry = makePlotIds ( tableModel . highlightedRow , tableModel . totalRows , MAX_IMAGE_CNT ) ;
203
-
204
-
205
- newPlotIdAry . forEach ( ( plotId ) => {
206
- if ( ! getPlotViewById ( vr , plotId ) ) {
207
- const rowNum = Number ( plotId . substring ( plotIdRoot . length ) ) ;
208
- const webPlotReq = getWebPlotRequestViaUrl ( tableModel , rowNum ) ;
209
- dispatchPlotImage ( { plotId, wpRequest :webPlotReq ,
210
- setNewPlotAsActive :false ,
211
- holdWcsMatch :true ,
212
- pvOptions : { userCanDeletePlots : false } } ) ;
213
- }
214
- } ) ;
215
-
216
-
217
- dispatchReplaceViewerItems ( IMG_VIEWER_ID , newPlotIdAry ) ;
218
- dispatchChangeActivePlotView ( plotIdRoot + tableModel . highlightedRow ) ;
219
-
220
- vr = visRoot ( ) ;
221
-
222
- vr . plotViewAry
223
- . filter ( ( pv ) => pv . plotId . startsWith ( plotIdRoot ) )
224
- . filter ( ( pv ) => pv . plotId !== vr . mpwWcsPrimId )
225
- . filter ( ( pv ) => ! maxPlotIdAry . includes ( pv . plotId ) )
226
- . forEach ( ( pv ) => dispatchDeletePlotView ( { plotId :pv . plotId , holdWcsMatch :true } ) ) ;
206
+ try {
207
+ const viewer = getViewer ( getMultiViewRoot ( ) , IMG_VIEWER_ID ) ;
208
+ const count = get ( viewer , 'layoutDetail.count' , DEF_IMAGE_CNT ) ;
209
+ const tableModel = getTblById ( tbl_id ) ;
210
+ if ( ! tableModel || isNil ( tableModel . highlightedRow ) ) return ;
211
+ var vr = visRoot ( ) ;
212
+ const newPlotIdAry = makePlotIds ( tableModel . highlightedRow , tableModel . totalRows , count ) ;
213
+ const maxPlotIdAry = makePlotIds ( tableModel . highlightedRow , tableModel . totalRows , MAX_IMAGE_CNT ) ;
214
+
215
+ const cutoutSize = get ( FieldGroupUtils . getGroupFields ( grpkey ) , [ 'cutoutSize' , 'value' ] , null ) ;
216
+
217
+ newPlotIdAry . forEach ( ( plotId ) => {
218
+ if ( ! getPlotViewById ( vr , plotId ) ) {
219
+ const rowNum = Number ( plotId . substring ( plotIdRoot . length ) ) ;
220
+ const webPlotReq = webplotRequestCreator ( tableModel , rowNum , cutoutSize ) ;
221
+ dispatchPlotImage ( { plotId, wpRequest :webPlotReq ,
222
+ setNewPlotAsActive :false ,
223
+ holdWcsMatch :true ,
224
+ pvOptions : { userCanDeletePlots : false } } ) ;
225
+ }
226
+ } ) ;
227
+
228
+
229
+ dispatchReplaceViewerItems ( IMG_VIEWER_ID , newPlotIdAry ) ;
230
+ dispatchChangeActivePlotView ( plotIdRoot + tableModel . highlightedRow ) ;
231
+
232
+ vr = visRoot ( ) ;
233
+
234
+ vr . plotViewAry
235
+ . filter ( ( pv ) => pv . plotId . startsWith ( plotIdRoot ) )
236
+ . filter ( ( pv ) => pv . plotId !== vr . mpwWcsPrimId )
237
+ . filter ( ( pv ) => ! maxPlotIdAry . includes ( pv . plotId ) )
238
+ . forEach ( ( pv ) => dispatchDeletePlotView ( { plotId :pv . plotId , holdWcsMatch :true } ) ) ;
239
+ } catch ( E ) {
240
+ console . log ( E . toString ( ) ) ;
241
+ }
227
242
}
228
243
229
244
@@ -242,16 +257,3 @@ function makePlotIds(highlightedRow, totalRows, totalPlots) {
242
257
}
243
258
244
259
245
- /**
246
- * A simple wrapper to catch the exception then log it to console
247
- * @param {function } f function to execute
248
- * @param {* } args function's arguments.
249
- */
250
- function exec ( f , args ) {
251
- try {
252
- f ( args ) ;
253
- } catch ( E ) {
254
- console . log ( E . toString ( ) ) ;
255
- }
256
-
257
- }
0 commit comments