File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -352,6 +352,29 @@ HTMLWidgets.widget({
352
352
Shiny . setInputValue ( ".clientValue-plotly_afterplot-" + x . source , "afterplot" , { priority : "event" } ) ;
353
353
} ) ;
354
354
355
+ var legendEventData = function ( d ) {
356
+ // if legendgroup is not relevant just return the trace
357
+ var trace = d . data [ d . curveNumber ] ;
358
+ if ( ! trace . legendgroup ) {
359
+ Shiny . setInputValue ( ".clientValue-plotly_legendclick-" + x . source , trace ) ;
360
+ return ;
361
+ }
362
+
363
+ // if legendgroup was specified, return all traces that match the group
364
+ var legendgrps = d . data . map ( function ( trace ) { return trace . legendgroup ; } ) ;
365
+ var traces = [ ] ;
366
+ for ( i = 0 ; i < legendgrps . length ; i ++ ) {
367
+ if ( legendgrps [ i ] == trace . legendgroup ) {
368
+ traces . push ( d . data [ i ] ) ;
369
+ }
370
+ }
371
+
372
+ Shiny . setInputValue ( ".clientValue-plotly_legendclick-" + x . source , traces ) ;
373
+ } ;
374
+
375
+ graphDiv . on ( 'plotly_legendclick' , legendEventData ) ;
376
+ graphDiv . on ( 'plotly_legenddoubleclick' , legendEventData ) ;
377
+
355
378
}
356
379
357
380
// Given an array of {curveNumber: x, pointNumber: y} objects,
You can’t perform that action at this time.
0 commit comments