Skip to content

Accessing pixel coordinates of data without event #69

New issue

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

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

Already on GitHub? Sign in to your account

Open
lnunno opened this issue Apr 2, 2018 · 4 comments
Open

Accessing pixel coordinates of data without event #69

lnunno opened this issue Apr 2, 2018 · 4 comments

Comments

@lnunno
Copy link

lnunno commented Apr 2, 2018

I'm trying to do something similar to the following forums where I'm trying to get the x, y coordinates of a data point in order to use the Fx.loneHover to programmatically trigger a hover event.

Any advice on how to achieve this? If I inspect the chart ref in the PlotlyComponent in does not have the function l2p or d2p anywhere within the object and I do not have an event handle to use to retrieve the x and y relative pixel locations.

@yarl
Copy link

yarl commented Jun 27, 2018

After hew hours in the source code, here's what is working for me with Fx.hover:

in render():

<Plot
  ref={node => { this.graphNode = node; }}
  divId={`plot-${this.id}`}
  data={data}
  style={style}
  config={config}
  layout={layout}
  onHover={hover => this.onHover({ hover })}
  onUnhover={unhover => this.onHover({ unhover })}
  useResizeHandler
/>
<Plot
  ref={node => { this.graphNode2 = node; }}
  divId={`plot-${this.id}-2`}
  data={data}
  style={style}
  config={config}
  layout={layout}
  onHover={hover => this.onHover({ hover, plotIndex: 2 })}
  onUnhover={unhover => this.onHover({ unhover, plotIndex: 2 })}
  useResizeHandler
/>

and this.onHover() function:

onHover({ hover, unhover, plotIndex }) {
  const oppositeNode = plotIndex === 2 ? this.graphNode : this.graphNode2;

  if (hover && oppositeNode && oppositeNode.el) {
    Plotly.Fx.hover(oppositeNode.el, hover.event);
  } else if (unhover && oppositeNode && oppositeNode.el) {
    Plotly.Fx.unhover(oppositeNode.el, unhover.event);
  }
}

I hope it can help someone.

@sumantka
Copy link

sumantka commented Mar 6, 2019

thanks @yarl , I still don't think react-plotly has first class hover events support. Could you confirm. Thanks

@honeyspoon
Copy link

@yarl Where do you import the Plotly.Fx from?

@sureshgadupu
Copy link

install plotly js with below command
npm install plotly.js-cartesian-dist-min

and import Plotly object

import Plotly from "plotly.js-cartesian-dist";
Then u can run above example

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

No branches or pull requests

5 participants