@@ -236,10 +236,18 @@ var MetadataPlot = Panel.extend({
236236 } ,
237237
238238 onSelect : function ( evt , plotData ) {
239+ if ( this . _elementSelect ) {
240+ this . _elementSelect -= 1 ;
241+ if ( this . _afterSelect && ! this . _elementSelect ) {
242+ this . _afterSelect ( ) ;
243+ this . _afterSelect = null ;
244+ }
245+ return ;
246+ }
239247 if ( plotData . colDict [ '_3_annotation.id' ] === undefined || plotData . colDict [ '_5_annotationelement.id' ] === undefined ) {
240248 return ;
241249 }
242- // evt is undefined when selection is cleared
250+ // evt is undefined when the selection is cleared
243251 if ( evt === undefined ) {
244252 this . parentView . _resetSelection ( ) ;
245253 return ;
@@ -284,7 +292,27 @@ var MetadataPlot = Panel.extend({
284292 if ( ! points . length ) {
285293 return ;
286294 }
287- window . Plotly . restyle ( this . _plotlyNode [ 0 ] , { selectedpoints : [ points ] } ) ;
295+ /* Deselect any selection on plotly. There is no exposed function to
296+ * do this, so we synthesize several actions: (a) switch to box select
297+ * mode, (b) double click on the plot, (c) ignore the first selection
298+ * event (first click), (d) on the second selection event, the plot no
299+ * longer has a selection, so we can specify the selected points (in
300+ * the _afterSelect callback), (e) switch back to whatever tool the
301+ * user had selected on the plot. */
302+ this . _elementSelect = 2 ;
303+ const curactive = this . _plotlyNode . find ( '.modebar-btn.active' ) ;
304+ this . _afterSelect = ( ) => {
305+ window . Plotly . restyle ( this . _plotlyNode [ 0 ] , { selectedpoints : [ points ] } ) ;
306+ if ( curactive . length ) {
307+ curactive [ 0 ] . dispatchEvent ( new MouseEvent ( 'click' ) ) ;
308+ }
309+ } ;
310+ const plot = this . _plotlyNode . find ( '.drag' ) . first ( ) [ 0 ] ;
311+ for ( let i = 0 ; i <= 2 ; i += 1 ) {
312+ this . _plotlyNode . find ( '.modebar-btn[data-val="select"]' ) [ 0 ] . dispatchEvent ( new MouseEvent ( 'click' ) ) ;
313+ plot . dispatchEvent ( new MouseEvent ( 'mousedown' , { bubbles : true , cancelable : true , view : window , clientX : 10 , clientY : 10 } ) ) ;
314+ plot . dispatchEvent ( new MouseEvent ( 'mouseup' , { bubbles : true , cancelable : true , view : window , clientX : 10 , clientY : 10 } ) ) ;
315+ }
288316 } ,
289317
290318 _formatNumber : function ( val , significant ) {
0 commit comments