plotly / plotly/react-plotly.js

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

未關閉
#326 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

主要語言
JavaScript
星號
1.1k
分支
138
平均合併
3 天 2 小時
30 天內合併 PR
4

描述

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.

貢獻指南

這個儲存庫沒有索引到貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從連結的 same_data 重現開始,追蹤 layout 發生變更但 data 被重複使用時 Plot 元件的更新路徑。比較 new_array 和 new_object 變體,以找出它們共通的行為。按一下 Update Plot 後,ranges 仍會計算且縮放仍然有效,即表示完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
javascript, plotly, react
領域
data-visualization, frontend
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
48/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。