Skip to content

Commit d8a4ea8

Browse files
author
Cindy Wang
committed
DM-11349 fix the dispatch functions for attaching draw layer to and detaching draw layer from the plot,
and the use of these two functons.
1 parent de31231 commit d8a4ea8

File tree

10 files changed

+53
-30
lines changed

10 files changed

+53
-30
lines changed

src/firefly/js/drawingLayers/DistanceTool.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
import numeral from 'numeral';
6-
import {isBoolean, get} from 'lodash';
6+
import {isBoolean, isEmpty, get} from 'lodash';
77
import DrawLayerCntlr, {DRAWING_LAYER_KEY} from '../visualize/DrawLayerCntlr.js';
88
import {getPreference} from '../core/AppDataCntlr.js';
99
import {visRoot,dispatchAttributeChange} from '../visualize/ImagePlotCntlr.js';
@@ -123,7 +123,7 @@ function getLayerChanges(drawLayer, action) {
123123
return end(action);
124124
break;
125125
case DrawLayerCntlr.ATTACH_LAYER_TO_PLOT:
126-
if (!get(action.payload, 'isExistingDrawLayer', false)) {
126+
if (isEmpty(get(drawLayer, ['drawData', 'data']))) {
127127
return attach();
128128
}
129129
break;

src/firefly/js/drawingLayers/FootprintTool.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export function footprintCreateLayerActionCreator(rawAction) {
6767
get(visRoot(), 'activePlotId') : isArray(plotId) ? plotId[0] : plotId;
6868

6969
if (pId) {
70-
dispatchAttachLayerToPlot(drawLayerId, pId, attachPlotGroup, attachPlotGroup);
70+
dispatchAttachLayerToPlot(drawLayerId, pId, attachPlotGroup);
7171

7272
var plot = primePlot(visRoot(), pId);
7373
if (plot) {
@@ -322,7 +322,7 @@ function getLayerChanges(drawLayer, action) {
322322
}
323323
break;
324324
case DrawLayerCntlr.ATTACH_LAYER_TO_PLOT:
325-
if (get(action.payload, 'isExistingDrawLayer', false)) {
325+
if (!isEmpty(get(drawLayer, ['drawData', 'data']))) {
326326
return attachToNewPlot(drawLayer, get(action.payload, ['plotIdAry', '0']));
327327
}
328328
break;

src/firefly/js/drawingLayers/MarkerTool.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export function markerToolCreateLayerActionCreator(rawAction) {
6969
get(visRoot(), 'activePlotId') : isArray(plotId) ? plotId[0] : plotId;
7070

7171
if (pId) {
72-
dispatchAttachLayerToPlot(drawLayerId, pId, attachPlotGroup, attachPlotGroup);
72+
dispatchAttachLayerToPlot(drawLayerId, pId, attachPlotGroup);
7373

7474
showMarkersByTimer(dispatcher, DrawLayerCntlr.MARKER_CREATE, pId,
7575
MarkerStatus.attached, markerInterval, drawLayerId, {isOutline: true, isResize:true});
@@ -298,7 +298,7 @@ function getLayerChanges(drawLayer, action) {
298298
return retV;
299299

300300
case DrawLayerCntlr.ATTACH_LAYER_TO_PLOT:
301-
if (get(action.payload, 'isExistingDrawLayer', false)) {
301+
if (!isEmpty(get(drawLayer, ['drawData', 'data']))) {
302302
return attachToNewPlot(drawLayer, get(action.payload, ['plotIdAry', '0']));
303303
}
304304
break;

src/firefly/js/drawingLayers/PointSelection.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import CsysConverter from '../visualize/CsysConverter.js';
1515
import {MouseState} from '../visualize/VisMouseSync.js';
1616
import {flux} from '../Firefly.js';
1717
import {clone} from '../util/WebUtil.js';
18-
import {get} from 'lodash';
18+
import {get, isEmpty} from 'lodash';
1919

2020
const ID= 'POINT_SELECTION';
2121
const TYPE_ID= 'POINT_SELECTION_TYPE';
@@ -61,8 +61,7 @@ function creator(initPayload, presetDefaults) {
6161
var options= {
6262
isPointData:true,
6363
hasPerPlotData:true,
64-
canUserChangeColor: ColorChangeType.DYNAMIC,
65-
destroyWhenAllDetached: true
64+
canUserChangeColor: ColorChangeType.DYNAMIC
6665
};
6766
return DrawLayer.makeDrawLayer(`${ID}-${idCnt}`,TYPE_ID, 'Selected Point', options, drawingDef, actionTypes, pairs);
6867
}
@@ -98,11 +97,18 @@ function makeSelectedPt(screenPt,plotId) {
9897
function selectAPoint(drawLayer, action, active, pId) {
9998
var {screenPt, plotId, plotIdAry}= action.payload;
10099

100+
const isEmptyData = () => {
101+
const data = get(drawLayer, ['drawData', 'data']);
102+
103+
if (isEmpty(data)) return true;
104+
const idx = Object.keys(data).findIndex((onePid) => !isEmpty(data[onePid]));
105+
106+
return idx < 0;
107+
};
101108
// attach drawing layer to the plot which is created after the drawing layer
102109
if (!screenPt &&
103110
action.type === DrawLayerCntlr.ATTACH_LAYER_TO_PLOT &&
104-
get(action.payload, 'isExistingDrawLayer', false) &&
105-
plotIdAry && plotIdAry.includes(pId)) {
111+
!isEmptyData() && plotIdAry && plotIdAry.includes(pId)) {
106112
if (drawLayer.plotIdAry) {
107113
let dAry;
108114

src/firefly/js/drawingLayers/SelectArea.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ function getLayerChanges(drawLayer, action) {
152152
return end(drawLayer,action);
153153
break;
154154
case DrawLayerCntlr.ATTACH_LAYER_TO_PLOT:
155-
if (!get(action.payload, 'isExistingDrawLayer', false)) {
155+
if (isEmpty(get(drawLayer, ['drawData', 'data']))) {
156156
return attach();
157157
}
158158
break;

src/firefly/js/visualize/DrawLayerCntlr.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
import {flux} from '../Firefly.js';
6-
import {getPlotViewIdListInGroup, getDrawLayerById, getConnectedPlotsIds, getPlotViewAry} from './PlotViewUtil.js';
6+
import {getPlotViewIdListInGroup, getDrawLayerById, getConnectedPlotsIds, getAllPlotViewId} from './PlotViewUtil.js';
77
import ImagePlotCntlr, {visRoot} from './ImagePlotCntlr.js';
88
import DrawLayerReducer from './reducer/DrawLayerReducer.js';
99
import {without,union,isEmpty} from 'lodash';
@@ -131,7 +131,7 @@ export function getDrawLayerCntlrDef(drawLayerFactory) {
131131
[REGION_ADD_ENTRY] : regionUpdateEntryActionCreator,
132132
[REGION_REMOVE_ENTRY] : regionUpdateEntryActionCreator
133133
};
134-
},
134+
}
135135
};
136136
}
137137

@@ -299,29 +299,24 @@ export function dispatchDestroyDrawLayer(id) {
299299
* @summary attach drawing layer to plot
300300
* @param {string|string[]} id make the drawLayerId or drawLayerTypeId, this may be an array
301301
* @param {string|string[]} plotId to attach this may by a string or an array of strings
302-
* @param attachPlotGroup
303-
* @param {boolean} isExistingDrawLayer this drawing layer already exists, attach it to a new plot
302+
* @param attachAllPlot
304303
* @memberof firefly.action
305304
* @public
306305
* @function dispatchAttachLayerToPlot
307306
*/
308-
export function dispatchAttachLayerToPlot(id,plotId, attachPlotGroup=false, attachAllPlot=false, isExistingDrawLayer) {
307+
export function dispatchAttachLayerToPlot(id,plotId, attachAllPlot=false) {
309308
var plotIdAry;
310309

311310
if (Array.isArray(plotId)) {
312311
plotIdAry= plotId;
313312
}
314313
else {
315-
if (attachAllPlot) {
316-
plotIdAry = getPlotViewAry(visRoot()).map((pv) => pv.plotId);
317-
} else {
318-
plotIdAry = attachPlotGroup ? getPlotViewIdListInGroup(visRoot(), plotId) : [plotId];
319-
}
314+
plotIdAry = attachAllPlot ? getAllPlotViewId(visRoot(), plotId) : [plotId];
320315
}
321316

322317
getDrawLayerIdAry(dlRoot(),id,false)
323318
.forEach( (drawLayerId) => {
324-
flux.process({type: ATTACH_LAYER_TO_PLOT, payload: {drawLayerId, plotIdAry, isExistingDrawLayer} });
319+
flux.process({type: ATTACH_LAYER_TO_PLOT, payload: {drawLayerId, plotIdAry} });
325320
});
326321
}
327322

@@ -330,22 +325,22 @@ export function dispatchAttachLayerToPlot(id,plotId, attachPlotGroup=false, att
330325
* @summary Detatch drawing layer from the plot
331326
* @param {string|string[]} id make the drawLayerId or drawLayerTypeId, this may be an array
332327
* @param {string|string[]} plotId to attach this may by a string or an array of string
333-
* @param detachPlotGroup
328+
* @param detachAllPlot
334329
* @param useLayerGroup
335330
* @param destroyWhenAllDetached if all plots are detached then destroy this plot
336331
* @public
337332
* @memberof firefly.action
338333
* @function dispatchDetachLayerFromPlot
339334
*/
340-
export function dispatchDetachLayerFromPlot(id,plotId, detachPlotGroup=false,
335+
export function dispatchDetachLayerFromPlot(id,plotId, detachAllPlot=false,
341336
useLayerGroup=true, destroyWhenAllDetached=false) {
342337
var plotIdAry;
343338

344339
if (Array.isArray(plotId)) {
345340
plotIdAry= plotId;
346341
}
347342
else {
348-
plotIdAry= detachPlotGroup ? getPlotViewIdListInGroup(visRoot(), plotId) : [plotId];
343+
plotIdAry= detachAllPlot ? getAllPlotViewId(visRoot(), plotId) : [plotId];
349344
}
350345

351346
getDrawLayerIdAry(dlRoot(),id,useLayerGroup)

src/firefly/js/visualize/PlotViewUtil.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,28 @@ export function getPlotViewIdListInGroup(visRoot,pvOrId,onlyIfGroupLocked=true,
107107
return idList.filter( (id) => get(getPlotViewById(visRoot,id),'plots.length') );
108108
}
109109

110+
/**
111+
* return an array of plotIds that are all under visRoot and based on the group lock of the group associated
112+
* width the pvOrId parameter
113+
* @param visRoot
114+
* @param pvOrId
115+
* @param hasPlots
116+
* @returns {*}
117+
*/
118+
export function getAllPlotViewId(visRoot, pvOrId, hasPlots=false) {
119+
if (!pvOrId) return [];
120+
const pv= (typeof pvOrId ==='string') ? getPlotViewById(visRoot,pvOrId) : pvOrId;
121+
const gid= pv.plotGroupId;
122+
const group= getPlotGroupById(visRoot,gid);
123+
const locked= hasGroupLock(pv,group);
124+
125+
if (!locked) {
126+
return [pv.plotId];
127+
} else {
128+
return visRoot.plotViewAry.filter((pv) => (!hasPlots || get(pv, 'plots.length')))
129+
.map((pv) => pv.plotId);
130+
}
131+
}
110132

111133
/**
112134
* Is this plotview the active one

src/firefly/js/visualize/region/RegionTask.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function createRegionLayer(regionAry, title, drawLayerId, plotId,
108108
}
109109

110110
if (pId) {
111-
dispatchAttachLayerToPlot(drawLayerId, pId, true, true);
111+
dispatchAttachLayerToPlot(drawLayerId, pId, true);
112112
}
113113
}
114114

src/firefly/js/visualize/task/PlotImageTask.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ function addDrawLayers(request, plot ) {
315315
DrawLayerCntlr.dispatchAttachLayerToPlot(dl.drawLayerId, plotId);
316316
}
317317
} else if (dl.canAttachNewPlot) {
318-
DrawLayerCntlr.dispatchAttachLayerToPlot(dl.drawLayerId, plotId, false, false, true);
318+
DrawLayerCntlr.dispatchAttachLayerToPlot(dl.drawLayerId, plotId);
319319
}
320320
});
321321
});
@@ -324,7 +324,7 @@ function addDrawLayers(request, plot ) {
324324
const dl = getDrawLayerByType(dlRoot(), WebGrid.TYPE_ID);
325325
const useLabels= request.getGridOn()===GridOnStatus.TRUE;
326326
if (!dl) dispatchCreateDrawLayer(WebGrid.TYPE_ID, {useLabels});
327-
dispatchAttachLayerToPlot(WebGrid.TYPE_ID, plotId, true, true);
327+
dispatchAttachLayerToPlot(WebGrid.TYPE_ID, plotId, true);
328328
}
329329
}
330330

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function onOff(pv,typeId,todo) {
6464
}
6565

6666
if (!isDrawLayerAttached(dl,pv.plotId)) {
67-
dispatchAttachLayerToPlot(typeId,pv.plotId,true, true);
67+
dispatchAttachLayerToPlot(typeId,pv.plotId,true);
6868
}
6969
else {
7070
dispatchDetachLayerFromPlot(typeId,pv.plotId,true,true, dl.destroyWhenAllDetached);

0 commit comments

Comments
 (0)