Skip to content

Commit 94fc67b

Browse files
committed
DM-7535 script that shows the API functions that should be documented first
1 parent 0e8f625 commit 94fc67b

File tree

6 files changed

+136
-62
lines changed

6 files changed

+136
-62
lines changed

src/firefly/html/demo/ffapi-2images.html

Lines changed: 88 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ <h3>Firefly - new API demo</h3>
2929
<div id="container" style="white-space: nowrap; padding: 5px">
3030
<input id="selectionCallbackTrigger" type="button" onclick="ffTrackSelections()" value="Track selections"/>
3131
&nbsp;
32+
<input id="selectionExtensions" type="button" onclick="ffSelectionExtensions()" value="Add selection extensions"/>
33+
&nbsp;
3234
<input id="readoutCallbackTrigger" type="button" onclick="ffTrackReadout()" value="Track mouse readout"/>
3335
&nbsp;
3436
<input id="regionsToggle" type="button" onclick="ffToggleRegions()" value="Show regions"/>
@@ -42,6 +44,7 @@ <h3>Firefly - new API demo</h3>
4244

4345
var trackSelectionRemover;
4446
var doTrackSelection = false;
47+
var hasSelectionExtensions = false;
4548

4649
var trackReadoutRemover;
4750
var doTrackReadout = false;
@@ -54,10 +57,17 @@ <h3>Firefly - new API demo</h3>
5457
];
5558
var regionsShown = false;
5659

60+
const regionsToAdd = [
61+
'image; box 400 400 72 72 0 # color=green',
62+
'image; box 328 400 72 72 0 # color=green',
63+
'image; box 256 400 72 72 0 # color=green',
64+
'image; box 184 400 72 72 0 # color=green',
65+
'image; box 112 400 72 72 0 # color=green'
66+
];
5767
var regionAdd = true;
5868
var regionIdx = 0;
5969

60-
const regionToAdd = 'image; box 400 400 72 72 0 # color=green';
70+
6171

6272
function ffTrackSelections() {
6373
doTrackSelection = !doTrackSelection;
@@ -81,6 +91,61 @@ <h3>Firefly - new API demo</h3>
8191
}
8292
}
8393

94+
const extensionCallback= function(data) {
95+
// do something when the extension is selected called.
96+
console.log('Callback for '+data.type+' extension '+data.id);
97+
console.log(data);
98+
};
99+
100+
const extensions = [
101+
{ // point selection extension: object literal to create extension definition
102+
id : 'PointExtension', // extension id
103+
plotId : 'image1', // plot to put extension on
104+
title : 'Point operation description', // title user sees
105+
imageUrl : 'http://localhost:8080/firefly/images/catalog_28x28.png', // url to the icon
106+
toolTip : 'Custom operation on point selection', // tooltip
107+
extType: 'POINT', // type of extension
108+
callback: extensionCallback // function (defined above) for callback
109+
},
110+
{ // area selection extension: object literal to create extension definition
111+
id : 'AreaExtension', // extension id
112+
plotId : 'image1', // plot to put extension on
113+
title : 'Area operation description', // title user sees
114+
imageUrl : 'http://localhost:8080/firefly/images/mask_28x28.png', // url to the icon
115+
toolTip : 'Custom operation on area selection', // tooltip
116+
extType: 'AREA_SELECT', // type of extension
117+
callback: extensionCallback // function (defined above) for callback
118+
},
119+
{ // line selection extension: object literal to create extension definition
120+
id : 'LineExtension', // extension id
121+
plotId : 'image1', // plot to put extension on
122+
title : 'Do something', // title user sees
123+
toolTip : 'Custom operation on line selection', // tooltip
124+
extType: 'LINE_SELECT', // type of extension
125+
callback: extensionCallback // function (defined above) for callback
126+
}];
127+
128+
function ffSelectionExtensions() {
129+
hasSelectionExtensions = !hasSelectionExtensions;
130+
const btn = document.getElementById('selectionExtensions');
131+
if (!btn) {
132+
console.log('Internal error: can not find selectionExtensions button');
133+
return;
134+
}
135+
// add/remove a button in image context menu, which appears on selection
136+
// and triggers user defined callback, when pressed
137+
if (hasSelectionExtensions) {
138+
extensions.forEach(firefly.util.image.extensionAdd);
139+
btn.value = 'Remove selection extensions';
140+
} else {
141+
const removeExtension = function(extension) {
142+
firefly.util.image.extensionRemove(extension.id);
143+
};
144+
extensions.forEach(removeExtension);
145+
btn.value = 'Add selection extensions';
146+
}
147+
}
148+
84149
function ffTrackReadout() {
85150
doTrackReadout = !doTrackReadout;
86151
const btn = document.getElementById('readoutCallbackTrigger');
@@ -125,24 +190,25 @@ <h3>Firefly - new API demo</h3>
125190
return;
126191
}
127192
if (regionAdd) {
128-
// issue1: empty region array does not work - there should be at least 1 region
129-
// issue2: if color=green (same color as the color of regionToAdd) it's not possible to add the region,
130-
// because the original and added regions will be perceived the same
131-
// issue3: when region1 is present, it's not possible to select regions in region2
132-
firefly.action.dispatchCreateRegionLayer('region2', 'Region Layer 2', null, ['image; box 40 400 72 72 0 # color=blue'], ['image1', 'image2']);
133-
firefly.action.dispatchAddRegionEntry('region2', regionToAdd);
134-
regionAdd = false;
135-
btn.value = 'Delete region';
193+
firefly.action.dispatchAddRegionEntry('dynregions', regionsToAdd[regionIdx], ['image1', 'image2'], 'Dynamic Regions');
194+
regionIdx++;
195+
if (regionIdx === regionsToAdd.length) {
196+
regionAdd = false;
197+
btn.value = 'Delete region';
198+
regionIdx--;
199+
}
136200
} else {
137-
firefly.action.dispatchRemoveRegionEntry('region2', regionToAdd);
138-
firefly.action.dispatchDeleteRegionLayer('region2', ['image1', 'image2']);
139-
regionAdd = true;
140-
btn.value = 'Add region';
201+
firefly.action.dispatchRemoveRegionEntry('dynregions', regionsToAdd[regionIdx]);
202+
regionIdx--;
203+
if (regionIdx < 0) {
204+
regionAdd = true;
205+
btn.value = 'Add region';
206+
regionIdx++;
207+
}
141208
}
142209
}
143210

144211

145-
146212
/**
147213
* @typedef {object} ChangePlotAttrAction action object
148214
* @prop {string} type action type
@@ -160,7 +226,9 @@ <h3>Firefly - new API demo</h3>
160226

161227
/*
162228
* Action listener for CHANGE_PLOT_ATTRIBUTE action
163-
* Callback function should accept action object, which has type and payload properties:
229+
* Callback function should accept action object, which has type and payload properties.
230+
* Please, note, that the coordinate system of a point in the action payload
231+
* depends on the user selection. To make sure we always get image coordinates, we need to convert.
164232
* @param {ChangePlotAttrAction}
165233
*/
166234
function onPlotAttributeChange(action) {
@@ -170,10 +238,12 @@ <h3>Firefly - new API demo</h3>
170238
if (action.payload.attValue.pt) {
171239
console.log(action.payload.plotId+' '+action.payload.attKey+' pt:');
172240
console.log(getImagePt(action.payload.attValue.pt));
173-
} else if (action.payload.attValue.pt0) {
241+
}
242+
if (action.payload.attValue.pt0) {
174243
console.log(action.payload.plotId+' '+action.payload.attKey+' pt0:');
175244
console.log(getImagePt(action.payload.attValue.pt0));
176-
} else if (action.payload.attValue.pt1) {
245+
}
246+
if (action.payload.attValue.pt1) {
177247
console.log('pt1:');
178248
console.log(getImagePt(action.payload.attValue.pt1));
179249
}
@@ -237,9 +307,7 @@ <h3>Firefly - new API demo</h3>
237307
};
238308
firefly.showImage('image2_div', req2);
239309

240-
firefly.action.dispatchCreateRegionLayer('region2', 'Region Layer 2', null, ['image; box 200 200 72 72 0 # color=red'], ['image1', 'image2']);
241-
242-
310+
firefly.action.dispatchCreateRegionLayer('statregion', 'Static region', null, ['image; box 220 220 20 80 45 # color=#0CB5ED'], ['image1', 'image2']);
243311
}
244312
}
245313
</script>

src/firefly/js/api/ApiBuild.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import './ApiStyle.css';
5757

5858
/**@namespace firefly.util*/
5959

60-
/** @namespace firefly.util.chat*/
60+
/** @namespace firefly.util.chart*/
6161

6262
/** @namespace firefly.util.data*/
6363

@@ -89,24 +89,24 @@ export function initApi() {
8989

9090
/**
9191
92-
Structure of API
93-
{
94-
//--- High level API , all high level api are in the root
95-
all high level functions....
96-
97-
//--- Low level API, lowlevel api are under action, ui, util
98-
action : { all dispatch functions...
99-
type: {all action type constants}
100-
}
101-
ui: { high level react components }
102-
util { renderDom, unrenderDom, isDebug, debug // built by ApiUtil.js
103-
image : {image utility routines} // imported from ApiUtilImage.js
104-
xyplot : {xyplot utility routines} // imported from ApiUtilXYPlot.js //todo
105-
table : {table utility routines} // imported from ApiUtilTable.js //todo
106-
data : {data utility routines???? } // //todo do we need this?????
92+
Structure of API
93+
{
94+
//--- High level API , all high level api are in the root
95+
all high level functions....
96+
97+
//--- Low level API, lowlevel api are under action, ui, util
98+
action : { all dispatch functions...
99+
type: {all action type constants}
100+
}
101+
ui: { high level react components }
102+
util { renderDom, unrenderDom, isDebug, debug // built by ApiUtil.js
103+
image : {image utility routines} // imported from ApiUtilImage.js
104+
chart : {chart utility routines} // imported from ApiUtilChart.js
105+
table : {table utility routines} // imported from ApiUtilTable.js
106+
data : {data utility routines???? } //todo do we need this?????
107+
}
107108
}
108-
}
109-
*/
109+
*/
110110

111111
/**
112112
* Return the api object.

src/firefly/js/api/ApiUtilImage.jsx

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ const API_READOUT= 'apiReadout';
2626
// It should have a jsdoc
2727
//----------------------------------------------------------------
2828
// NOTE
29-
// NOTE
30-
31-
/**
32-
* @namespace firefly.util.image.CCUtil
33-
**/
29+
// NOTE
3430

3531
/**
3632
* @public
@@ -41,18 +37,14 @@ export {WPConst, WebPlotRequest, findInvalidWPRKeys, confirmPlotRequest} from '.
4137
export {RequestType} from '../visualize/RequestType';
4238
export {ExpandType, dispatchApiToolsView} from '../visualize/ImagePlotCntlr.js';
4339

44-
export {CsysConverter} from '../visualize/CsysConverter.js';
40+
export {CysConverter} from '../visualize/CsysConverter.js';
4541
export {CCUtil} from '../visualize/CsysConverter.js';
4642
export {watchCoverage} from '../visualize/saga/CoverageWatcher.js';
4743
export {watchImageMetaData} from '../visualize/saga/ImageMetaDataWatcher.js';
4844

45+
export {extensionAdd, extensionRemove} from '../core/ExternalAccessUtils.js';
46+
4947

50-
/*
51-
*
52-
*
53-
*
54-
*
55-
*/
5648
/**
5749
* @summary Get plot object with the given plot id, when plotId is not included, active plot is returned.
5850
* @param {string} [plotId] the plotId, optional
@@ -91,7 +83,7 @@ export function initAutoReadout(ReadoutComponent= DefaultApiReadout,
9183
* @param algorithm the stretch algorithm to use, may be 'Linear', 'Log', 'LogLog', 'Equal', 'Squared', 'Sqrt'
9284
* @public
9385
* @function serializeSimpleRangeValues
94-
* @memberof firefly.util.image
86+
* @memberof firefly.util.image
9587
*/
9688
export function serializeSimpleRangeValues(stretchType,lowerValue,upperValue,algorithm) {
9789
const rv= RangeValues.makeSimple(stretchType,lowerValue,upperValue,algorithm);

src/firefly/js/core/ExternalAccessCntlr.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*
22
* License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt
33
*/
4-
5-
import ExternalAccessUtils, {extensionActivate} from './ExternalAccessUtils.js';
4+
import ExternalAccessUtils from './ExternalAccessUtils.js';
65

76
const EXTENSION_ADD= 'ExternalAccessCntlr/extensionAdd';
7+
const EXTENSION_REMOVE= 'ExternalAccessCntlr/extensionRemove';
88
const EXTENSION_ACTIVATE= 'ExternalAccessCntlr/extensionActivate';
99
const CHANNEL_ACTIVATE= 'ExternalAccessCntlr/channelActivate';
1010

@@ -25,6 +25,10 @@ export function dispatchExtensionAdd(extension) {
2525
flux.process({type: ExternalAccessCntlr.EXTENSION_ADD, payload: {extension}});
2626
}
2727

28+
export function dispatchExtensionRemove(extensionId) {
29+
flux.process({type: ExternalAccessCntlr.EXTENSION_REMOVE, payload: {id: extensionId}});
30+
}
31+
2832
export function dispatchExtensionActivate(extension, resultData) {
2933
flux.process({type: ExternalAccessCntlr.EXTENSION_ACTIVATE, payload: {extension, resultData}});
3034
}
@@ -35,7 +39,6 @@ export function dispatchChannelActivate(channelId) {
3539

3640

3741

38-
3942
const extensionActivateActionCreator= function(rawAction) {
4043
return (dispatcher) => {
4144

@@ -60,6 +63,9 @@ function reducer(state=initState, action={}) {
6063
case EXTENSION_ADD :
6164
retState= addExtension(state,action);
6265
break;
66+
case EXTENSION_REMOVE :
67+
retState= removeExtension(state,action);
68+
break;
6369
case EXTENSION_ACTIVATE :
6470
retState= state;// todo something
6571
break;
@@ -78,6 +84,11 @@ const addExtension= function(state, action) {
7884
return Object.assign({}, state, {extensionList:newAry});
7985
};
8086

87+
const removeExtension= function(state, action) {
88+
var {id}= action.payload;
89+
var newAry= state.extensionList.filter((extension) => {return (extension.id !== id);});
90+
return Object.assign({}, state, {extensionList:newAry});
91+
};
8192

8293
const updateChannel= function(state, action) {
8394
var {channelId}= action.payload;
@@ -90,7 +101,7 @@ const updateChannel= function(state, action) {
90101
//============ EXPORTS ===========
91102

92103
var ExternalAccessCntlr = {
93-
reducer, extensionActivateActionCreator, EXTENSION_ADD,
104+
reducer, extensionActivateActionCreator, EXTENSION_ADD, EXTENSION_REMOVE,
94105
EXTENSION_ACTIVATE, CHANNEL_ACTIVATE, EXTERNAL_ACCESS_KEY,
95106
ALL_MPW
96107
};

src/firefly/js/core/ExternalAccessUtils.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {flux} from '../Firefly.js';
77
import ExternalAccessCntlr from './ExternalAccessCntlr.js';
88
import {reportUserAction} from '../rpc/SearchServicesJson.js';
99
import { parseImagePt, parseWorldPt, parseScreenPt } from '../visualize/Point.js';
10-
import {getWsChannel} from './messaging/WebSocketClient.js'
10+
import {getWsChannel} from './messaging/WebSocketClient.js';
1111

1212
const EMPTY_ARRAY=[];
1313

@@ -56,6 +56,10 @@ export const extensionAdd= function(extension) {
5656
flux.process({type: ExternalAccessCntlr.EXTENSION_ADD, payload: {extension}});
5757
};
5858

59+
export const extensionRemove= function(extensionId) {
60+
flux.process({type: ExternalAccessCntlr.EXTENSION_REMOVE, payload: {id: extensionId}});
61+
};
62+
5963
export const extensionActivate= function(extension, resultData) {
6064
flux.process({type: ExternalAccessCntlr.EXTENSION_ACTIVATE, payload: {extension, resultData}});
6165
};
@@ -66,6 +70,6 @@ export const channelActivate= function(channelId) {
6670
};
6771

6872

69-
var ExternalAccessUtils= { doExtensionActivate, extensionAdd, extensionActivate, channelActivate,
73+
var ExternalAccessUtils= { doExtensionActivate, extensionAdd, extensionRemove, extensionActivate, channelActivate,
7074
getRemoteChannel, getExtensionList };
7175
export default ExternalAccessUtils;

0 commit comments

Comments
 (0)