Skip to content
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

How do I use Plotly.Fx.hover with react-plotly.js? #339

Open
NathanPB opened this issue Feb 28, 2024 · 0 comments
Open

How do I use Plotly.Fx.hover with react-plotly.js? #339

NathanPB opened this issue Feb 28, 2024 · 0 comments

Comments

@NathanPB
Copy link

NathanPB commented Feb 28, 2024

I am building something like this: https://plotly.com/javascript/hover-events/#coupled-hover-events, but I can't find a way to reproduce this behavior with react-plotly.js

Fx is not present in plotly.js anymore (isn't it?), and I can't find a way to find a Plotly's Plot instance (not the wrapper's instance) in order to try different methods.

Does anyone know how I could achieve a similar effect?

What I have so far looks something like:

import {FC, useEffect, useMemo, useRef} from "react";
import {BoxPlotData, Layout} from 'plotly.js'
import Plot from 'react-plotly.js';

export const MyPlot: FC = () => {
  const boxplotRef = useRef<Plot>(null)

  useEffect(() => {
    if (boxplotRef.current) {
      // What now?
      // I would like to do something like
      // boxplotRef.current.plot.hover([ { pointNumber: 1 }, { pointNumber: 2 }, { pointNumber: 3 } ])
    }
  }, []);

  const myLayout = useMemo((): Layout => { ... }, [])
  const myData = useMemo((): Partial<BoxPlotData> => { ... }, [])

  return (
    <Plot
      ref={boxplotRef}
      data={myData}
      layout={myLayout}
    />
  )
}
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

1 participant