[BUG]: Mixed bar orientations hide one bar on initial render, but restyle renders correctly
未关闭
还没有人认领这个 Issue。
bug
P3
size: 3
- 主要语言
- Python
- 星标
- 18.8k
- 派生
- 2.8k
- 平均合并
- 16 小时 26 分钟
- 30 天内合并 PR
- 21
描述
Description
A figure with two go.Bar traces renders differently depending on when the second
trace is changed from horizontal to vertical.
If fig.data[1].orientation = "v" is set before the first render, one red vertical
bar is missing or clipped. If the same base figure is rendered first and the same
orientation value is applied later with Plotly.restyle, all three red bars are
visible.
Screenshots/Video
Steps to reproduce
import io
import plotly
import plotly.graph_objects as go
import plotly.io as pio
from PIL import Image, ImageChops
from playwright.sync_api import sync_playwright
print(f"Plotly version: {plotly.__version__}")
fig = go.Figure(
[
go.Bar(name="a", orientation="h", x=[1, 3, 2], y=[0, 1, 2]),
go.Bar(name="b", orientation="h", x=[3, 2, 1], y=[0, 1, 2]),
]
)
fig.update_layout(xaxis_title="value", yaxis_title="index", legend_title_text="variable")
# plot1.png: set orientation before the first render.
fig.data[1].orientation = "v"
assert fig.data[1].orientation == "v"
html1 = pio.to_html(fig, full_html=True, include_plotlyjs="cdn")
# plot2.png: render first, then apply the same value with Plotly.restyle.
fig.data[1].orientation = "h"
html2 = pio.to_html(fig, full_html=True, include_plotlyjs="cdn")
html2 = html2.replace(
"</body>",
"""
<script>
window.addEventListener("DOMContentLoaded", () => {
const plotEl = document.getElementsByClassName("plotly-graph-div")[0];
setTimeout(() => {
Plotly.restyle(plotEl, {"orientation": "v"}, [1]);
}, 1000);
});
</script>
</body>""",
)
with sync_playwright() as playwright:
browser = playwright.chromium.launch(
headless=True,
args=["--no-sandbox", "--disable-dev-shm-usage", "--disable-gpu"],
)
page = browser.new_page(viewport={"width": 1200, "height": 800})
page.set_content(html1)
page.wait_for_timeout(1500)
img1 = page.screenshot(path="plot1.png")
page.set_content(html2)
page.wait_for_timeout(2000)
img2 = page.screenshot(path="plot2.png")
browser.close()
diff = ImageChops.difference(
Image.open(io.BytesIO(img1)).convert("RGB"),
Image.open(io.BytesIO(img2)).convert("RGB"),
)
assert diff.getbbox() is not None, "Screenshots are unexpectedly identical."
print("Saved plot1.png and plot2.png")
```### Notes
_Add info here that doesn't fit in the other sections._
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
运行提供的 Python 和 Playwright 复现,并将初始渲染的截图与 Plotly.restyle 的结果进行比较。追踪水平和垂直方向混合时的柱条渲染路径;完成的标准是两种渲染都显示全部三根红色柱条,且没有裁剪或由渲染时序导致的差异。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, playwright, python
- 领域
- data-visualization, frontend
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100