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 摘要。