@@ -29,6 +29,8 @@ <h3>Firefly - new API demo</h3>
29
29
< div id ="container " style ="white-space: nowrap; padding: 5px ">
30
30
< input id ="selectionCallbackTrigger " type ="button " onclick ="ffTrackSelections() " value ="Track selections "/>
31
31
32
+ < input id ="selectionExtensions " type ="button " onclick ="ffSelectionExtensions() " value ="Add selection extensions "/>
33
+
32
34
< input id ="readoutCallbackTrigger " type ="button " onclick ="ffTrackReadout() " value ="Track mouse readout "/>
33
35
34
36
< input id ="regionsToggle " type ="button " onclick ="ffToggleRegions() " value ="Show regions "/>
@@ -42,6 +44,7 @@ <h3>Firefly - new API demo</h3>
42
44
43
45
var trackSelectionRemover ;
44
46
var doTrackSelection = false ;
47
+ var hasSelectionExtensions = false ;
45
48
46
49
var trackReadoutRemover ;
47
50
var doTrackReadout = false ;
@@ -54,10 +57,17 @@ <h3>Firefly - new API demo</h3>
54
57
] ;
55
58
var regionsShown = false ;
56
59
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
+ ] ;
57
67
var regionAdd = true ;
58
68
var regionIdx = 0 ;
59
69
60
- const regionToAdd = 'image; box 400 400 72 72 0 # color=green' ;
70
+
61
71
62
72
function ffTrackSelections ( ) {
63
73
doTrackSelection = ! doTrackSelection ;
@@ -81,6 +91,61 @@ <h3>Firefly - new API demo</h3>
81
91
}
82
92
}
83
93
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
+
84
149
function ffTrackReadout ( ) {
85
150
doTrackReadout = ! doTrackReadout ;
86
151
const btn = document . getElementById ( 'readoutCallbackTrigger' ) ;
@@ -125,24 +190,25 @@ <h3>Firefly - new API demo</h3>
125
190
return ;
126
191
}
127
192
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
+ }
136
200
} 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
+ }
141
208
}
142
209
}
143
210
144
211
145
-
146
212
/**
147
213
* @typedef {object } ChangePlotAttrAction action object
148
214
* @prop {string } type action type
@@ -160,7 +226,9 @@ <h3>Firefly - new API demo</h3>
160
226
161
227
/*
162
228
* 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.
164
232
* @param {ChangePlotAttrAction }
165
233
*/
166
234
function onPlotAttributeChange ( action ) {
@@ -170,10 +238,12 @@ <h3>Firefly - new API demo</h3>
170
238
if ( action . payload . attValue . pt ) {
171
239
console . log ( action . payload . plotId + ' ' + action . payload . attKey + ' pt:' ) ;
172
240
console . log ( getImagePt ( action . payload . attValue . pt ) ) ;
173
- } else if ( action . payload . attValue . pt0 ) {
241
+ }
242
+ if ( action . payload . attValue . pt0 ) {
174
243
console . log ( action . payload . plotId + ' ' + action . payload . attKey + ' pt0:' ) ;
175
244
console . log ( getImagePt ( action . payload . attValue . pt0 ) ) ;
176
- } else if ( action . payload . attValue . pt1 ) {
245
+ }
246
+ if ( action . payload . attValue . pt1 ) {
177
247
console . log ( 'pt1:' ) ;
178
248
console . log ( getImagePt ( action . payload . attValue . pt1 ) ) ;
179
249
}
@@ -237,9 +307,7 @@ <h3>Firefly - new API demo</h3>
237
307
} ;
238
308
firefly . showImage ( 'image2_div' , req2 ) ;
239
309
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' ] ) ;
243
311
}
244
312
}
245
313
</ script >
0 commit comments