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

Missing executeAPICommand in exports.Plots #5794

Closed
cid8600 opened this issue Jul 1, 2021 · 5 comments
Closed

Missing executeAPICommand in exports.Plots #5794

cid8600 opened this issue Jul 1, 2021 · 5 comments

Comments

@cid8600
Copy link

cid8600 commented Jul 1, 2021

Bug: I Upgraded Plotly to v2.2.0 and noticed the Plotly.Plots.executeAPICommand handler was no longer in the latest version.

As a User I'd like to see executeAPICommand returned to exports.Plots. This allows one to control multiple plots via a single Event.

File: dist/plotly.js
Line: 155701

Is:

exports.Plots = {
    resize: Plots.resize,
    graphJson: Plots.graphJson,
    sendDataToCloud: Plots.sendDataToCloud,
};

Fix:

exports.Plots = {
    resize: Plots.resize,
    graphJson: Plots.graphJson,
    sendDataToCloud: Plots.sendDataToCloud,
    executeAPICommand: Plots.executeAPICommand
};

Example: try to execute Plotly.Plots.executeAPICommand(gd, method, args) to control a sibling Plot and notice the function is missing from the exports.Plots Object.

@alexcjohnson
Copy link
Collaborator

@cid8600 Can you give a full example of how you use this function? We intentionally removed a lot from Plotly.Plots, to minimize the surface area we need to maintain - see https://github.com/plotly/plotly.js/blob/master/CHANGELOG.md#removed, specifically:

Reduce the number of exported methods from Plotly.Fx and Plotly.Plots in the API [#5420]

I'm not inherently opposed to bringing this one back, just want to understand the use cases better before we do.

@cid8600
Copy link
Author

cid8600 commented Jul 1, 2021

@alexcjohnson, Indeed:

Let say I have two contour plots rendered on a page. Each Plot has a slider to stream through 3D data. The plot steps are synced. If I move the slider from Plot1, I expect the slider from Plot2 to follow and display the same frame.

React Pseudo code would look like:

const [startingSlice, setstartingSlice] = useState(1)
const Plot1 = useRef()
const Plot2 = useRef()

 const onSliderChange = (event) => {
    if (Plot1.current && Plot2.current) {
      const { slider, step } = event;
      if (slider._gd === Plot1.current.el) {
        // if from Plot1, update Plot2
        Plotly.Plots.executeAPICommand(Plot2.current.el, step.method, step.args);
      } else if (slider._gd === Plot2.current.el) {
        // if from Plot2, update Plot1
        Plotly.Plots.executeAPICommand(Plot1.current.el, step.method, step.args);
      }
      setstartingSlice(slider.active);
    }
  };

<Plot ref={Plot1} onSliderChange={onSliderChange}>
<Plot ref={Plot2} onSliderChange={onSliderChange}>

@cid8600
Copy link
Author

cid8600 commented Jul 1, 2021

image

@alexcjohnson
Copy link
Collaborator

I see. If you're explicitly calling executeAPICommand like that, can you call the method directly? ie change:

Plotly.Plots.executeAPICommand(Plot2.current.el, step.method, step.args);

to:

Plotly[step.method](Plot2.current.el, ...step.args);

@cid8600
Copy link
Author

cid8600 commented Jul 1, 2021

Great call. That works the same. I appreciate you looking into it.

@cid8600 cid8600 closed this as completed Jul 1, 2021
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

2 participants