Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

support plotselected / plothover / plotclick events #8

Open
iabw opened this issue Oct 30, 2017 · 0 comments
Open

support plotselected / plothover / plotclick events #8

iabw opened this issue Oct 30, 2017 · 0 comments

Comments

@iabw
Copy link
Contributor

iabw commented Oct 30, 2017

I'm trying to migrate an existing flot graph that has handlers like

$('#graph').on('plotclick', function (event, pos, item) {
    // do stuff
});

I'm going to try to add these in the componentDidUpdate hook of my component that wraps ReactFlot, but it seems like the 'correct' way to do this is to pass the handler as a prop to ReactFlot.

Something like:

// App.js
class MyReactFlotWrapper extends Component {
  handlePlotClick(event, pos, item){
    // do stuff
  }
  render() {
    return (
      <ReactFlot
        onPlotClick={::this.handlePlotClick}
      />
    );
  }
}
// ReactFlot.jsx
class ReactFlot extends Component {
  draw(event, data) {
    const chart = $.plot($(`#${this.props.id}`), data || this.props.data, this.props.options);
    addLabels(chart, this.props.options);
    this.bindHandlers();
  }
  
  bindHandlers() {
    if (this.props.onPlotClick) {
      $(`#${this.props.id}`).on('plotclick', this.props.onPlotClick);
    }
    if (this.props.onPlotSelected) {
      $(`#${this.props.id}`).on('plotselected', this.props.onPlotSelected);
    }
  }
}

The unused event parameter for draw makes it seem like maybe you initially intended to include something like this?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant