react-plotly.js icon indicating copy to clipboard operation
react-plotly.js copied to clipboard

onSelected event not being called

Open porteron opened this issue 5 years ago • 9 comments

When selecting a region on the <Plot> the onSelected event is not firing. Other events such as onUpdate and onClick work.

Plot Component:

            <Plot
                onSelected={(data) => this.setTotalData(data)}
                layout={layout}
                useResizeHandler={true}
                style={{ width: "100%", height: "100%" }}
                data={data}
            />

Function to be called:

    setTotalData = (data) => {
        console.log("Selected Data: ", data)
    }

porteron avatar Dec 19 '18 20:12 porteron

@antoinerg Could you check this out? Thank you.

porteron avatar Dec 19 '18 23:12 porteron

@mnoster i use it in exactly the same way and it works for me

alagiz avatar Jan 21 '19 11:01 alagiz

@ArtemAlagizov What version of react?

porteron avatar Jan 23 '19 03:01 porteron

@mnoster "react": "^16.4.2",
"plotly.js": "^1.43.2", "react-plotly.js": "^2.2.0"

alagiz avatar Jan 23 '19 06:01 alagiz

and the usage:

import React, {Component} from 'react';
import Plot from 'react-plotly.js';

class TabPanelContent extends Component {
  state = {
	data: [],
	layout: {}
  };

  ....

  onSelected = data => {
	console.log(data, 'data');
  }

  render() {
	return (
	  <div className="scatterplot-container">
		<Plot
		  data={this.state.data}
		  layout={this.state.layout}
		  onSelected={data => this.onSelected(data)}
		  style={{width: "100%", height: "50%"}}
		  useResizeHandler={true}
		/>
	  </div>
	);
  }
}

export default TabPanelContent;

alagiz avatar Jan 23 '19 08:01 alagiz

I want to use onSelected and onClick both the events for the plot. If i use that, even for the click, it is going to onSelected, How to use onSelected and onClick events.

Thilak8654 avatar Jul 23 '20 10:07 Thilak8654

@mnoster you are using the event prop correctly. I might know where your confusion lays:

To properly use the onSelected prop, you should select 'Box Select' or 'lasso Select' from the options on the plotly chart. The default selection is for zooming.

image

Sednaoui avatar Oct 22 '20 18:10 Sednaoui

onSelected is not working for me, but onSelecting is working

KestutisMa avatar Apr 09 '21 12:04 KestutisMa

Can somebody please make a reproduction of the issue?

dmt0 avatar Apr 09 '21 16:04 dmt0