Skip to content

Commit d6721c4

Browse files
committed
DM-7273: Mouse readout cleanup and bug fixes
- Mouse readout not longer will randomly switch to the bigger one. - The mouse readout will not blink as you go in and out of an image - Clean up flow of mouse readout saga - MouseReadoutWatch includes description of empty flux fields - Readout ui layout has been cleaned up: minimal is smaller, three color is tighter, standard api is cleaner - Readout now correctly shows empty flux display
1 parent ea4f51d commit d6721c4

File tree

6 files changed

+141
-119
lines changed

6 files changed

+141
-119
lines changed

src/firefly/js/api/ApiUtilImage.jsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import React from 'react';
66
import {take,race,call} from 'redux-saga/effects';
7+
import {has} from 'lodash';
78
import {MouseState} from '../visualize/VisMouseSync.js';
89
import ImagePlotCntlr, {visRoot, ExpandType} from '../visualize/ImagePlotCntlr.js';
910
import {primePlot} from '../visualize/PlotViewUtil.js';
@@ -59,20 +60,23 @@ export function getPrimePlot(plotId) {
5960
return primePlot(visRoot(), plotId);
6061
}
6162

63+
64+
65+
var isInit= false;
6266
/**
63-
* @summary initialize the auto readout. Must be call once at the begging to get the popup readout running.
67+
* @summary initialize the auto readout. Can only be called once at the begging to get the popup readout running.
68+
* Called internally during first image plot.
6469
* @param {object} ReadoutComponent - either a PopupMouseReadoutMinimal or PopupMouseReadoutFull
6570
* @param {object} props - a list of the properties
6671
* @public
6772
* @function initAutoReadout
6873
* @memberof firefly.util.image
6974
*/
7075
export function initAutoReadout(ReadoutComponent= DefaultApiReadout,
71-
// props={MouseReadoutComponent:PopupMouseReadoutMinimal, showThumb:false,showMag:false}){
7276
props={MouseReadoutComponent:PopupMouseReadoutFull, showThumb:true,showMag:true } ){
73-
74-
77+
if (isInit) return;
7578
dispatchAddSaga(autoReadoutVisibility, {ReadoutComponent,props});
79+
isInit= true;
7680
}
7781

7882

@@ -138,7 +142,7 @@ function *autoReadoutVisibility({ReadoutComponent,props}) {
138142
mouse: call(mouseUpdatePromise),
139143
timer: call(delay, 3000)
140144
});
141-
if ((!winner.expandedChange || !winner.mouse) && !inDialog && !isLockByClick(readoutRoot()) && !isAutoReadIsLocked(readoutRoot())) {
145+
if ((has(winner,'timer')) && !inDialog && !isLockByClick(readoutRoot()) && !isAutoReadIsLocked(readoutRoot())) {
142146
hideReadout();
143147
}
144148
else {

src/firefly/js/visualize/saga/MouseReadoutWatch.js

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
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';
88
import {clone} from '../../util/WebUtil.js';
99
import {readoutRoot, dispatchReadoutData, makeValueReadoutItem, makePointReadoutItem,
1010
makeDescriptionItem, isLockByClick} from '../MouseReadoutCntlr.js';
1111
import {callGetFileFlux} from '../../rpc/PlotServicesJson.js';
1212
import {Band} from '../Band.js';
1313
import {MouseState} from '../VisMouseSync.js';
1414
import {isBlankImage} from '../WebPlot.js';
15-
import {primePlot, getPlotStateAry, getActivePlotView} from '../PlotViewUtil.js';
15+
import {primePlot, getPlotStateAry, getPlotViewById} from '../PlotViewUtil.js';
1616
import {mouseUpdatePromise} from '../VisMouseSync.js';
1717

1818

@@ -22,41 +22,47 @@ const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
2222

2323
export 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
*/
132138
function 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
*/
153159
function 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
}

src/firefly/js/visualize/ui/DefaultApiReadout.jsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import {ThumbnailView} from './ThumbnailView.jsx';
1414
import {MagnifiedView} from './MagnifiedView.jsx';
1515

1616
var fullStyle= {
17-
width: 680,
18-
height: 70,
19-
minWidth: 680,
20-
minHeight:70,
17+
// width: 680,
18+
// height: 70,
19+
// minWidth: 680,
20+
// minHeight:70,
2121
display: 'inline-block',
2222
position: 'relative',
2323
verticalAlign: 'top',
@@ -27,10 +27,10 @@ var fullStyle= {
2727
};
2828

2929
var minimalStyle= {
30-
width: 360,
31-
height: 70,
32-
minWidth: 360,
33-
minHeight:70,
30+
// width: 360,
31+
// height: 70,
32+
// minWidth: 360,
33+
// minHeight:70,
3434
display: 'inline-block',
3535
position: 'relative',
3636
verticalAlign: 'top',
@@ -86,9 +86,9 @@ export class DefaultApiReadout extends Component {
8686
const style = MouseReadoutComponent && MouseReadoutComponent.name==='PopupMouseReadoutMinimal'?minimalStyle:fullStyle;
8787
return (
8888

89-
<div style={{display:'inline-block', float:'right', whiteSpace:'nowrap'}}>
89+
<div style={{display:'flex',flexWrap:'nowrap'}}>
9090
<div style={style}>
91-
<div style={{position:'absolute', color:'black'}}>
91+
<div style={{position:'relative', color:'black', height:'100%'}}>
9292
<MouseReadoutComponent readout={readout} showMag={ showMag} showThumb={showThumb}/>
9393
</div>
9494
</div>

src/firefly/js/visualize/ui/MouseReadout.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const rS = {
3030
whiteSpace: 'nowrap',
3131
overflow: 'hidden'
3232
};
33-
const EMPTY = <div style={rS}></div>;
33+
const EMPTY = <div style={rS}/>;
3434
const EMPTY_READOUT = '';
3535
const coordinateMap = {
3636
galactic: CoordinateSys.GALACTIC,
@@ -194,15 +194,15 @@ export function getFluxInfo(sndReadout){
194194
}
195195
var fluxValueArrays=[];
196196
var fluxLabelArrays=[];
197-
var fluxValue, formatStr;
197+
var fluxValue;
198198

199199
for (let i = 0; i < fluxObj.length; i++) {
200200
if (!isNaN(fluxObj[i].value )) {
201201
fluxValue = (fluxObj[i].value < 1000) ? `${myFormat(fluxObj[i].value, fluxObj[i].precision)}` : fluxObj[i].value.toExponential(6).replace('e+', 'E');
202202
if (fluxObj[i].unit && !isNaN(fluxObj[i].value)) fluxValue+= ` ${fluxObj[i].unit}`;
203203
fluxValueArrays.push(fluxValue);
204-
fluxLabelArrays.push(fluxObj[i].title);
205204
}
205+
fluxLabelArrays.push(fluxObj[i].title);
206206
}
207207

208208
if (fluxLabelArrays.length<3) { //fill with empty
@@ -231,7 +231,7 @@ export function getMouseReadout(readoutItems, toCoordinateName) {
231231
var wpt = readoutItems.worldPt;
232232
if (!wpt.value) return;
233233

234-
var result,fStr, obj;
234+
var result, obj;
235235
var {coordinate, type} = getCoordinateMap(toCoordinateName);
236236
if (coordinate) {
237237
var ptInCoord = VisUtil.convert(wpt.value, coordinate);

0 commit comments

Comments
 (0)