plotly / plotly/react-plotly.js

ranges does not get computed when same data is used but Plot is updated

Open
#326 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
1.1k
Forks
138
Avg merge
3d 2h
Merged PRs (30d)
4

Description

If layout is change but data stays the same, Plot's ranges are not computed correctly.

Consider this React component

(full project can be found here: https://github.com/saad-learns/react-plotly/tree/same_data

function App() {
  const [plotUpdated, setPlotUpdated] = React.useState<number>(0);
  const [plotParams, setPlotParams] = React.useState<PlotParams>({
    data: [
      {
        x: [-3, -2, -1, 0, 1, 2, 3],
        y: [
          -0.1411200080598672, -0.9092974268256817, -0.8414709848078965, 0,
          0.8414709848078965, 0.9092974268256817, 0.1411200080598672,
        ],
      },
    ],
    layout: {},
  });

  const updatePlot = () => {
    setPlotParams((prevState) => ({
      data: prevState.data,
      layout: {},
    }));
  };

  return (
    <div className="App">
      <div style={{ padding: 10 }}>
        <button onClick={updatePlot}>Update Plot</button>
      </div>

      <Plot
        data={plotParams.data}
        layout={plotParams.layout}
        onUpdate={() => setPlotUpdated((prevState) => prevState + 1)}
      />

      <div>Plot updated: {plotUpdated}</div>
    </div>
  );

At the start, ranges are calculated correctly. You can verify that with React Dev Tool's Component tab:

image

Or you can use Zoom In and Zoom Out button to verify that zooming is working.

But if you click on the Update Plot button, the ranges are not computed, in fact they get removed:

image

Thereafter, zooming does not work.

Here, updatePlot will use the same data object, but makes use of a new layout. According to https://github.com/plotly/react-plotly.js#refreshing-the-plot Plot should be refreshed, and it does, but ranges are no longer computed correctly.

There are other variation of the above issue:

  1. Use a new array but same previous data element: https://github.com/saad-learns/react-plotly/blob/new_array/src/App.tsx
  2. Use a new array, and a new element but with same previous data: https://github.com/saad-learns/react-plotly/blob/new_object/src/App.tsx

where ranges are not computed properly.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked same_data reproduction and trace the Plot component update path when layout changes but data is reused. Compare the new_array and new_object variations to identify the shared behavior. Done means ranges remain computed and zooming still works after clicking Update Plot.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, plotly, react
Domain
data-visualization, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.