Surface::surface_color has the wrong type: it should be a 2D numeric array, not Vec<Box<dyn Color>>
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 68/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- rust
- Ambito
- data-visualization
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Rust
- Stelle
- 1.5k
- Fork
- 130
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di plotly/plotly.rs
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 62/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 62/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 38/100
-
Support Plotly Express color sequencesForse già presa @iynehz l’ha presa 41 giorni fa. Apertaenhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
-
bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
Tutte le issue di plotly/plotly.rs
Issue simili
-
Perl - Readme DriftForse già presa @Omnideth l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
CommunityToolkit/Aspire#2375 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 86/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno