Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Traces for Mesh3d, Image, ScatterMapbox #88

Merged
merged 34 commits into from
Nov 3, 2022
Merged

Conversation

JoelSjogren
Copy link
Contributor

Hi, I have implemented some basic wrapping code for go.Mesh3D and go.Image as suggested in #49. I used @mrhrzg's scatter3d.rs as a starting point.

I am sending this pull request now to get some feedback. Should I do the following things to complete the added features? Anything else?

  • add one example for each new trace type
  • implement setters for all remaining parameters listed in the documentation
  • fix all cargo warnings
  • add entry in change log
  • run test suite

Just before sending this I decided to also add some mapbox support, as suggested in #86. Specifically I started adding go.Scattermapbox. I am a little confused about layout.mapbox and layout.mapbox_style which seems to lack a documentation entry, and I have not been able to get layout.mapbox_style to work properly. I tried "stamen-watercolor" and "open-street-map" but they seem to have no effect. I guess it should be turned into an enum in the end, but this can't be the problem can it?

By the way I am using Evcxr.

Also by the way I think there is a fair bit of code duplication going on with parameters being repeated across different structs. Maybe this could be improved using some kind of rust macro? I guess the most difficult part of this might be to handle the documentation properly.

@mfreeborn
Copy link
Contributor

Thanks for the PR. Yes, as a basic requirement, the code would need to be rustfmted with all the warnings resolved.

Adding the remaining setters, along with tests would be necessary, and then crediting yourself in the changelog would be essential. Scatter3D and Sankey are good examples to base the code structure on.

I agree, there is a lot of code duplication, but I haven't figured out a good way of resolving that at present...

@JoelSjogren
Copy link
Contributor Author

May I ask what is the reason for using traits so much?

For example
pub fn x0<V: Into<NumOrString>>(mut self, x0: V) -> Box<Self> {
instead of just
pub fn x0(mut self, x0: NumOrString) -> Box<Self> {
and also

pub fn new<I, K, L>(x: I, y: K, z: L) -> Box<Self>
    where
        I: IntoIterator<Item = X>,
        K: IntoIterator<Item = Y>,
        L: IntoIterator<Item = Z>,
    {

instead of just

pub fn new(x: &[X], y: &[Y], z: &[Z]) -> Box<Self>
    {

or even

pub fn new(x: Vec<X>, y: Vec<Y>, z: Vec<Z>) -> Box<Self>
    {

@mfreeborn
Copy link
Contributor

mfreeborn commented Jun 2, 2022

Mostly it was a decision taken before I started contributing, but I think it does make for a clean user API. For NumOrString, for example, the user doesn't need to worry particularly about NumOrString, they can just pass whatever type implements Into<NumOrString> for it:

let trace = Scatter::new().x0(10_u32);

// or...

let trace = Scatter::new().x0("something");

Without, it would look something like:

let trace = Scatter::new().x0(NumOrString::I(10_u32 as i64));

// or...

let trace = Scatter::new().x0(NumOrString::S("something".to_string()));

I think the former is much nicer.

@JoelSjogren
Copy link
Contributor Author

Ah I see, so it is sort of dual to the use of #[serde(untagged)].

@JoelSjogren
Copy link
Contributor Author

Hi, in the latest commit I have sketched a new trait for the Image trace, to allow input directly from the ndarray or image packages without the user having to convert these into Vec<Vec<PixelColor<U>>> manually. Do you think this would be sensible, based on what we said about traits before? If so I need to figure out how to serialize this trait properly. Maybe you could give some comments on how to do this, e.g. what parts of the Color trait to reuse.

@JoelSjogren
Copy link
Contributor Author

It is pretty much all done now, except for that part about an ImageData trait.

@JoelSjogren
Copy link
Contributor Author

That's some intense refactoring going on there :-)

@mfreeborn
Copy link
Contributor

mfreeborn commented Nov 3, 2022 via email

@mfreeborn mfreeborn merged commit 086d012 into plotly:dev Nov 3, 2022
This was referenced Nov 3, 2022
mfreeborn added a commit that referenced this pull request Nov 3, 2022
* Refactor examples and readme (#113)

* update main readme

* update plotly_kaleido readme

* update readme

* typo

* add readme

* Refactor examples and readme

* update changelog

* fix CI workflow

* update workflows

* tpyo

* formatting

* fix workflows

* update workflows

* update readme

* update readme

* update url

* final tweaks

* Remove 'static lifetime requirement for `Plot.to_inline_html()` (#115)

* remove 'static lifetime requirement

* update changelog

* add `legend_group_title` to existing traces (#110)

* feat: add legendgrouptitle too all existing traces

Fixes #109

* update changelog

Co-authored-by: Michael Freeborn <michaelfreeborn1@gmail.com>

* Traces for Mesh3d, Image, ScatterMapbox (#88)

* Add basic Mesh3D trace functionality

* Add basic Image trace functionality

* Add basic ScatterMapbox functionality

* Fix compilation errors due to merge

* Copy some setters

* Fill in some more Mesh3D setters

* Complete the Mesh3D setters

* Complete the Image setters

* Sketch idea of ImageData trait

* Complete the ScatterMapbox setters

* Add tests for Mesh3D

* Fix cargo warnings

* Make greater use of IntoIterator trait

* Add tests for Image

* Add tests for ScatterMapbox

* Fix compilation errors

* Insert _ in setter names

* Run rustfmt and add line breaks to documentation

* Add jupyter lab examples for Mesh3D, Image, ScatterMapbox

* Update CHANGELOG

* Remove setter assertions

* refactoring

* fix tests

* formatting

* add ImageData trait

* add Image trace examples

* add mesh3d example

* rustfmt

* add map example

* tweak zoom data type

* rustfmt

* clippy

* update workflows

Co-authored-by: Michael Freeborn <michaelfreeborn1@gmail.com>

* add plotly_image to features list

* v0.8.2

Co-authored-by: Kai Howelmeyer <kai@hoewelmeyer.eu>
Co-authored-by: Joel Sjögren <joelsjogren.wii@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants