@@ -168,24 +168,105 @@ window.Widgets.Panel.Utils = {};
168
168
// setup the left click capability
169
169
ns . selectArray = [ ] ;
170
170
ns . leftclick = function ( event , d ) {
171
+
172
+ // Setup the local theme
173
+ if ( ! ns . theme ) {
174
+ if ( ns . options . theme === 'light' ) {
175
+ ns . theme = ns . options . light_theme
176
+ } else {
177
+ ns . theme = ns . options . dark_theme
178
+ }
179
+ }
180
+
171
181
let len = ns . selectArray . length ;
172
182
console . log ( `clicked on: ${ d } ` ) ;
173
183
const selected = d3 . select ( this ) ; // can't use arrow scoping
174
- if ( event . ctrlKey ) {
184
+
185
+ if ( selected . classed ( 'clicked' ) ) {
186
+ // Toggle-off the clicked state
187
+ //
188
+ // 1. Pop the element from the array
189
+ for ( var i = ns . selectArray . length - 1 ; i >= 0 ; i -- ) {
190
+ if ( ns . selectArray [ i ] . id === selected . id ) {
191
+ ns . selectArray . splice ( i , 1 ) ;
192
+ }
193
+ }
194
+ // 2. deselect the node
195
+ selected . classed ( "selected" , false ) ;
196
+ selected . style ( "stroke" , "none" ) ;
197
+ selected . style ( "stroke-width" , 0 ) ;
198
+
199
+ }
200
+ else if ( event . ctrlKey ) {
175
201
// we will do a multi-select
176
202
if ( len < 2 ) {
177
- // we add the data element to the array
203
+ // Then Just add selected onto the end of the array, and style it
204
+ //
205
+ // 1. add the data element to the array
178
206
ns . selectArray . push ( d ) ;
179
- // highlight the node
207
+ // 2. highlight the node
208
+ selected . classed ( "selected" , true ) ;
180
209
selected . style ( "stroke" , ns . theme . select ) ;
181
210
selected . style ( "stroke-width" , 5 ) ;
182
211
} else if ( len === 2 ) {
183
- // we first need to select the first object in the list
184
-
212
+ // First deselect the first in the list, then add the new one
213
+ //
214
+ // 1. We need to get and remove the first object in the select array
215
+ let deselect = ns . selectArray . shift ( ) ;
216
+ // 2. Get the DOM object that has to be deselected based on the id
217
+ const deselected = d3 . select ( "#" + deselect . id ) ;
218
+ console . log ( "multi deselect->" , deselect ) ;
219
+ console . log ( "multi deselected->" , deselected ) ;
220
+ // 3. Use the deselected object ref to remove the styling
221
+ deselected . classed ( "selected" , false ) ;
222
+ deselected . style ( "stroke" , "none" ) ;
223
+ deselected . style ( "stroke-width" , 0 ) ;
224
+ // 4. Add the new data element to the select array
225
+ ns . selectArray . push ( d ) ;
226
+ // 5. Highlight the selected node
227
+ selected . classed ( "selected" , true ) ;
228
+ selected . style ( "stroke" , ns . theme . select ) ;
229
+ selected . style ( "stroke-width" , 5 ) ;
230
+ } else {
231
+ console . log ( "ERORR: multi-select array is broken, too many items" , ) ;
232
+ ns . selectArray . length = 0 ;
185
233
}
186
234
187
235
} else {
188
236
// we will do a single select
237
+ if ( len === 0 ) {
238
+ // Then Just add selected onto the end of the array, and style it
239
+ //
240
+ // 1. add the data element to the array
241
+ ns . selectArray . push ( d ) ;
242
+ // 2. highlight the node
243
+ selected . classed ( "selected" , true ) ;
244
+ selected . style ( "stroke" , ns . theme . select ) ;
245
+ selected . style ( "stroke-width" , 5 ) ;
246
+ } else {
247
+ // Deselect all in the list, then add the new one
248
+ //
249
+ // 1. Deselect each object in the array
250
+ ns . selectArray . forEach ( ( item , index ) => {
251
+ // 2. Get the DOM object that has to be deselected based on the id
252
+ const deselected = d3 . select ( "#" + item . id ) ;
253
+ console . log ( "single deselect->" , item ) ;
254
+ console . log ( "single deselected->" , deselected ) ;
255
+ // 3. Use the deselected object ref to remove the styling
256
+ deselected . classed ( "selected" , false ) ;
257
+ deselected . style ( "stroke" , "none" ) ;
258
+ deselected . style ( "stroke-width" , 0 ) ;
259
+
260
+ } ) ;
261
+ // 2. Make the List Empty
262
+ ns . selectArray . length = 0 ;
263
+ // 3. add the new data element to the array
264
+ ns . selectArray . push ( d ) ;
265
+ // 5. Highlight the newly selected node
266
+ selected . classed ( "selected" , true ) ;
267
+ selected . style ( "stroke" , ns . theme . select ) ;
268
+ selected . style ( "stroke-width" , 5 ) ;
269
+ }
189
270
}
190
271
191
272
}
0 commit comments