plotly / plotly/react-plotly.js

Chart behaves identical whether it's dumb (no state) or whether it has state

Đang mở
#309 0 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
JavaScript
Star
1.1k
Fork
138
Merge trung bình
3 ngày 2 giờ
Pull request đã merge (30 ngày)
4

Mô tả

The docs state that: This is a "dumb" component that doesn't merge its internal state with any updates. This means that if a user interacts with the plot, by zooming or panning for example, any subsequent re-renders will lose this information unless it is captured and upstreamed via the onUpdate callback prop.
But the following two pieces of code behave identically:

  • without state:
function StackedAreaChart({) {
  const layout = {
    showlegend: true,
    legend: {
      x: 0,
      y: -0.15,
      orientation: "h",
      traceorder: "normal",
      yanchor: "top",
    },
    autosize: true,
    margin: { pad: 10, b: 10, l: 40, r: 40, t: 80 },
  };

  const plotData = [...someData]

  return (
    <div style={{ height: 650 }} data-cy="stacked-area-chart">
      <Plot
        data={plotData}
        layout={layout}
        style={{ width: "100%", height: "100%" }}
        useResizeHandler
      />
    </div>
  );
}
export default StackedAreaChart;
  • and with state:
function StackedAreaChart() {
  const [chart, setChart] = useState({
    data: [],
    layout: {
      showlegend: true,
      legend: {
        x: 0,
        y: -0.15,
        orientation: "h",
        traceorder: "normal",
        yanchor: "top",
      },
      xaxis: { range: [2000, 2019] },
      autosize: true,
      margin: { pad: 10, b: 10, l: 40, r: 40, t: 80 },
    },
    config: { responsive: true },
  });

  useEffect(() => {
    const plotData = [...someData];

    setChart((prevState) => ({
      ...prevState,
      data: [...plotData],
    }));
  }, [setChart, data]);

  return (
    <div style={{ height: 650 }} data-cy="stacked-area-chart">
      <Plot
        data={chart.data}
        layout={chart.layout}
        config={chart.config}
        style={{ width: "100%", height: "100%" }}
        useResizeHandler
      />
    </div>
  );
}
export default StackedAreaChart;

I can pan and zoom and then double click to return to its initial state on both codes. I can also modify the viewport width, making the chart to resize, while zoomed in and the chart still behaves perfectly.

I don't understand the warning in the documentation.
Am I doing something wrong ?

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Issue không nêu tệp nào trong repository hay bài kiểm thử nào; hãy bắt đầu bằng cách xác định đoạn tài liệu về component “dumb” và so sánh đoạn đó với hai ví dụ React. Tái hiện hành vi pan, zoom, rerender và resize được báo cáo, sau đó làm rõ cảnh báo hoặc ghi lại sự khác biệt dự kiến khi hành vi mong muốn đã được xác nhận.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript, react
Lĩnh vực
data-visualization, documentation
Loại issue
Tài liệu
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.