Surface::surface_color has the wrong type: it should be a 2D numeric array, not Vec<Box<dyn Color>>
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 68/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- rust
调研方向
Start in plotly/src/traces/surface.rs by reviewing the Surface surface_color field and the serialize_surface unit test. Check the proposed 2D numeric representation against the reproduction and expected JSON, then resolve the public API choice before updating the field and test. Done means nested numeric values compile and serialize as a 2D surfacecolor array.
由索引模型根据 Issue 内容生成。
描述
Description
In plotly/src/traces/surface.rs, the surfacecolor attribute of the Surface trace is defined as:
#[serde(rename = "surfacecolor")]
surface_color: Option<Vec<Box<dyn Color>>>,
This doesn't match plotly.js. There, surface.surfacecolor is a data array:
Sets the surface color values, used for setting a color scale independent of
z.
The naming in this case is misleading and might have resulted in the current state. Plotly.js expects a 2D numeric matrix with the same shape as z and not some of the common string color representations that Plotly.js can digest. The numeric values are mapped through colorscale (and cmin/cmax/cmid) in place of z. A common use is e.g. coloring a surface by a second scalar field, e.g. showing temperature on a height map.
The current type causes two problems:
- It's only one-dimensional.
Coloris implemented for numeric types such asf64, so.surface_color(vec![0.1, 0.2, ...])compiles. But it can't express[[...], [...]], becauseVec<f64>doesn't implementColor. - It suggests CSS colors. Because of the
Colorbound, users and the existing unit test pass values like"#123456". Plotly.js doesn't accept those for this attribute.
Reproduction
use plotly::{Plot, Surface};
fn main() {
let z = vec![vec![0.0, 1.0], vec![1.0, 2.0]];
let c = vec![vec![2.0, 0.0], vec![0.0, 2.0]];
let trace = Surface::new(z)
.x(vec![0.0, 1.0])
.y(vec![0.0, 1.0])
.surface_color(c); // does not compile: `Vec<{float}>` does not implement `Color`
let mut plot = Plot::new();
plot.add_trace(trace);
plot.show();
}
The existing unit test serialize_surface also expects JSON that plotly.js treats as invalid for this attribute:
.surface_color(vec!["#123456"])
// ...
"surfacecolor": ["#123456"],
Expected behaviour
You can pass a 2D numeric array with the same shape as z, and it serializes as:
"surfacecolor": [[2.0, 0.0], [0.0, 2.0]]
Proposed fix
Change the field to a 2D numeric array, for example:
#[serde(rename = "surfacecolor")]
surface_color: Option<Vec<Vec<f64>>>,
and update the serialize_surface test:
.surface_color(vec![vec![0.0, 1.0]])
// ...
"surfacecolor": [[0.0, 1.0]],
Considerations
- A 4th generic parameter
Surface<X, Y, Z, C = f64>withsurface_color: Option<Vec<Vec<C>>>. This is could be more flexible. Default type parameters on structs are allowed, but they aren't used when inferring the type ofSurface::new(...), so some existing call sites could still stop compiling. - Reuse
Z, i.e.Option<Vec<Vec<Z>>>. This is simpler, but it forces the color values to have the same type asz.
Environment
plotlycrate version: 0.14.1- Rust version: rustc 1.98.1
- OS: Windows
This would change the public API and might therefore be a breaking change. As this a fix to feature that was not working consider which level of release version this should result in.
I'm happy to open a PR once we agree on the preferred type.
- 主要语言
- Rust
- 星标
- 1.5k
- 派生
- 130
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
plotly/plotly.rs 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 62/100
-
难度 4/5 3-5 天 新手友好度 62/100
-
难度 5/5 一周以上 新手友好度 38/100
-
Support Plotly Express color sequences可能已有人在做 @iynehz 于 41 天前认领。 未关闭enhancement
难度 5/5 一周以上 新手友好度 35/100
-
bug
难度 3/5 1-2 天 新手友好度 55/100
相似的 Issue
-
Perl - Readme Drift可能已有人在做 @Omnideth 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
CommunityToolkit/Aspire#2375 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 86/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复