plotly / plotly/plotly.js

[BUG]: forced minimum tick spacing (box/violin/candlestick/ohlc) leaks between figures on the same graph div

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

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

bug P2 size: 1
Ngôn ngữ chính
JavaScript
Star
18.3k
Fork
2k
Merge trung bình
2 ngày 12 giờ
Pull request đã merge (30 ngày)
28

Mô tả

Description

Box, violin, candlestick and ohlc traces ask their position axis for a minimum tick spacing, so that each box gets a tick of its own rather than ticks at meaningless in-between positions. That forcing is silently lost whenever the figure is drawn into a graph div that already held a different figure — so Plotly.react, restyle, addTraces and friends can produce different ticks than Plotly.newPlot of the exact same figure.

It goes the other way too: a graph div that once held a box plot keeps the forced spacing after you react to a trace type that never asked for it.

Steps to reproduce
var boxFig = {
    data: [{type: 'box', x: [1, 1, 2, 2, 3, 3], y: [1, 2, 3, 4, 5, 6]}],
    layout: {width: 700, height: 400}
};
var scatterFig = {data: [{y: [1, 2, 3]}], layout: {width: 700, height: 400}};

// x ticks: 1, 2, 3  — correct, one per box
Plotly.newPlot(gd, boxFig);

// x ticks: 0.5, 1, 1.5, 2, 2.5, 3, 3.5  — same figure, half the ticks land between boxes
Plotly.newPlot(gd, scatterFig).then(function() { return Plotly.react(gd, boxFig); });

It is most visible on a date axis. Five daily candles at width: 1000, reached by reacting from a line chart over the same dates:

newPlot:  Jan 1 | Jan 2 | Jan 3 | Jan 4 | Jan 5
react:    12:00 Dec 31, 2023 | 00:00 Jan 1, 2024 | 12:00 | 00:00 Jan 2, 2024 | 12:00 | ...

Every second tick falls in the gap between two candles, and the axis now starts on the day before the data.

Notes

Axes.minDtick keeps its state in ax._minDtick / ax._forceTick0, with three meanings: undefined (nothing forced yet — adopt this trace's spacing), a positive number (a forcing is in effect), and 0 (forcing cancelled — by non-grouped bars, or by scatter/heatmap calc — and sticky, so a later trace can't reinstate it).

The reset back to undefined between passes sits at the bottom of setConvert, but it can't take effect on a real axis: setConvert runs while supplyDefaults builds the new _fullLayout, where those keys don't exist yet, and relinkPrivateKeys then copies the old values back onto it. So whichever figure the graph div held first decides the forcing for every figure after it. newPlot escapes it only because it starts from an empty _fullLayout.

Found by a sweep comparing react against newPlot of the same figure — 7 of 12 divergences traced back here.

Fix proposed in #7950, which moves the reset into ax.clearCalc(), alongside the equivalent relink cleanup doCalcdata already does for shared color axes.

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

Mở hướng dẫn đóng góp

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

Bắt đầu bằng cách kiểm tra Axes.minDtick cùng các điểm vào setConvert, ax.clearCalc và doCalcdata được đề cập trong issue. Tái hiện sự khác biệt giữa Plotly.newPlot và Plotly.react bằng các figure box và scatter được cung cấp, sau đó xác minh rằng khoảng cách tick bị ép buộc được đặt lại giữa các figure và cả hai đường đi đều tạo ra cùng các tick.

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
Lĩnh vực
data-visualization
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
65/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.