@@ -277,29 +277,71 @@ HTMLWidgets.widget({
277
277
) ;
278
278
} ) ;
279
279
graphDiv . on ( 'plotly_hover' , function ( d ) {
280
+
280
281
Shiny . onInputChange (
281
282
".clientValue-plotly_hover-" + x . source ,
282
283
JSON . stringify ( eventDataWithKey ( d ) )
283
284
) ;
285
+
286
+ // When persistent selection is enabled (either through
287
+ // shift or highlight()), remember click data
288
+ if ( x . highlight . persistentShift ) {
289
+ var dShift = graphDiv . _shiny_plotly_hover || { points : [ ] } ;
290
+ var pts = [ ] . concat ( dShift . points , d . points ) ;
291
+ var d = { points : pts , event : d . event } ;
292
+ graphDiv . _shiny_plotly_hover = d ;
293
+ } else {
294
+ graphDiv . _shiny_plotly_hover = undefined ;
295
+ }
296
+
297
+ Shiny . onInputChange (
298
+ ".clientValue-plotly_hover_persist_on_shift-" + x . source ,
299
+ JSON . stringify ( eventDataWithKey ( d ) )
300
+ ) ;
301
+
284
302
} ) ;
285
303
graphDiv . on ( 'plotly_click' , function ( d ) {
304
+
286
305
Shiny . onInputChange (
287
- ".clientValue-plotly_click-" + x . source ,
306
+ ".clientValue-plotly_click-" + x . source ,
288
307
JSON . stringify ( eventDataWithKey ( d ) )
289
308
) ;
309
+
310
+ // When persistent selection is enabled (either through
311
+ // shift or highlight()), remember click data
312
+ if ( x . highlight . persistentShift ) {
313
+ var dShift = graphDiv . _shiny_plotly_click || { points : [ ] } ;
314
+ var pts = [ ] . concat ( dShift . points , d . points ) ;
315
+ var d = { points : pts , event : d . event } ;
316
+ graphDiv . _shiny_plotly_click = d ;
317
+ } else {
318
+ graphDiv . _shiny_plotly_click = undefined ;
319
+ }
320
+
321
+ Shiny . onInputChange (
322
+ ".clientValue-plotly_click_persist_on_shift-" + x . source ,
323
+ JSON . stringify ( eventDataWithKey ( d ) )
324
+ ) ;
325
+
290
326
} ) ;
327
+
291
328
graphDiv . on ( 'plotly_selected' , function ( d ) {
292
329
Shiny . onInputChange (
293
330
".clientValue-plotly_selected-" + x . source ,
294
331
JSON . stringify ( eventDataWithKey ( d ) )
295
332
) ;
296
333
} ) ;
334
+
297
335
graphDiv . on ( 'plotly_unhover' , function ( eventData ) {
298
- Shiny . onInputChange ( ".clientValue-plotly_hover-" + x . source , null ) ;
336
+ if ( ! x . highlight . persistentShift ) {
337
+ Shiny . onInputChange ( ".clientValue-plotly_hover-" + x . source , null ) ;
338
+ }
299
339
} ) ;
340
+
300
341
graphDiv . on ( 'plotly_doubleclick' , function ( eventData ) {
301
342
Shiny . onInputChange ( ".clientValue-plotly_click-" + x . source , null ) ;
302
343
} ) ;
344
+
303
345
// 'plotly_deselect' is code for doubleclick when in select mode
304
346
graphDiv . on ( 'plotly_deselect' , function ( eventData ) {
305
347
Shiny . onInputChange ( ".clientValue-plotly_selected-" + x . source , null ) ;
0 commit comments