Explicit node coordinates (x/y positions) not fully respected in Sankey diagram
未关闭
还没有人认领这个 Issue。
bug
good first issue
P3
- 主要语言
- JavaScript
- 星标
- 18.3k
- 派生
- 2k
- 平均合并
- 2 天 12 小时
- 30 天内合并 PR
- 28
描述
We (@janosh) are trying to generate a Sankey diagram but for some reason the explicit coordinates are not fully respected. The "right_a" node has a coordinate of (0.9, 0.05) (top right), but for some reason shows at bottom left.
plotly 6.3.1, macos 26.0.1
import plotly.graph_objects as go
labels = ["left_a", "left_b", "left_c", "left_d", "left_e", "left_f", "left_g", "left_h", "left_i", "left_j", "left_k", "left_l", "left_m",
"left_n", "left_o", "left_p", "left_q", "left_r",
"right_a", "right_b", "right_c", "right_d", "right_e", "right_f", "right_g", "right_h", "right_i", "right_j", "right_k", "right_l"]
node_pos = {
"left_a": (0.1, 0.1), "left_b": (0.1, 0.14), "left_c": (0.1, 0.18), "left_d": (0.1, 0.23),
"left_e": (0.1, 0.27), "left_f": (0.1, 0.31), "left_g": (0.1, 0.35),
"left_h": (0.1, 0.40), "left_i": (0.1, 0.44), "left_j": (0.1, 0.48),
"left_k": (0.1, 0.52), "left_l": (0.1, 0.56), "left_m": (0.1, 0.61),
"left_n": (0.1, 0.65), "left_o": (0.1, 0.69), "left_p": (0.1, 0.73),
"left_q": (0.1, 0.77), "left_r": (0.1, 0.82),
"right_a": (0.9, 0.05),
"right_b": (0.9, 0.15), "right_c": (0.9, 0.25), "right_d": (0.9, 0.35), "right_e": (0.9, 0.45), "right_f": (0.9, 0.55), "right_g": (0.9, 0.65),
"right_h": (0.9, 0.75), "right_i": (0.9, 0.85), "right_j": (0.9, 0.93), "right_k": (0.9, 0.97), "right_l": (0.9, 0.99)}
sources = [0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10,
10, 10, 11, 12, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 16, 16, 16, 18, 18, 18, 19, 19, 19, 19, ]
targets = [23, 21, 20, 26, 30, 20, 24, 22, 21, 20, 20, 25, 29, 22, 22, 29, 20, 20, 22, 25, 24, 29, 20, 22, 29, 21, 21, 20, 24, 30, 22,
20, 20, 21, 25, 22, 30, 28, 24, 29, 20, 21, 24, 20, 20, 22, 20, 23, 21, 24, 31, 25, 21, 22, 20, 23, 30, 27, 26, 24, 21, 20, 22,
23, 30, 25, 20, 21, 22, 20, 21, 25, 20, 22, 21, 24, ]
values = [1 for _ in targets]
assert len(sources) == len(targets) == len(values)
x_positions: list[float] = [node_pos[lbl][0] for lbl in labels]
y_positions: list[float] = [node_pos[lbl][1] for lbl in labels]
fig = go.Figure(
go.Sankey(
arrangement="fixed",
node=dict(
label=labels,
x=x_positions,
y=y_positions,
),
link=dict(
source=sources,
target=targets,
value=values,
),
)
)
# fig.show()
fig.write_image("debug.svg", format="svg")
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先运行提供的 Sankey 复现,并使用 arrangement="fixed" 导出 debug.svg,然后跟踪 Sankey 的实现及其对节点 x/y 坐标的处理。完成的标准是,right_a 在 (0.9, 0.05) 等显式坐标能够反映在渲染出的图表中,同时不会使其他固定位置节点出现回归问题。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 52/100