-
Notifications
You must be signed in to change notification settings - Fork 300
integrate palette colors into plotters as a feature #20
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
Conversation
Hi Lukas, Thank you for the PR. It seems the PR removed the color trait and replace it with the crate completely. I have a few concern about it. First, one of the reason for having built-in color representation is I want to keep a minimal required dependency. Although it's not important for most of the case, but if you are creating a WASM application, this might be a matter. Second, after the removal of Plotters' color layer, Plotters is now directly coupled with Palette crate, and I have some concern about this. Since one of the guideline for creating this crate is make the core Plotter code as small as possible and easy to extend. (P.S. You can see both font and color implementation can be replaced easily. And I am currently looking for a replacement for current font implementation, because the crate isn't in good quality and causing memory leak.) This is why those "unnecessary" trait exist in the code base. But removing that Plotters will lose the flexibility on color representation. Third, One of the plan in the future is make the color description also supports gradient. Or allows the actual color determined by it's value etc. This is another reason a color abstraction is needed in the crate, but removing the trait makes it harder to extend the crate supports that. a color descriptor might be extend to some texture descriptor in the future, but the guideline is do not block any future extensions. Finally, this is a breaking change which may cause problems. I know the existing color system isn't good and needs a lot improvement but making a huge change without backward compatibility doesn't seem ideal. The reason why I keep use reference to pass color descriptors, since it may become a huge data structure and needs to pass by ref. As I previously mentioned, the color descriptor may extend to texture, gradient, hot map, etc .... I think it's great is the underlying color data is using this crate since it's much better implemented than the builtin impls. It should be as easy as make change inside the What I am concerning is the PR is getting rid of possibility for future extension and introducing breaking change. I am open to discussion, please let me know if you don't think what I said make sense. Thanks you ! |
Ah yes, I get your points regarding this. So if I get this right a plan for now would be to just allow palette colors to interface with the Color trait and probably even feature gate it(being a default feature or not would be question then as well)? This would allow it to have minimal dependencies as well since its opt-in(or opt-out). Or is there anything else I missed from your write up that can be done without much discussion/thinking about for now? While making this PR I already expected serveral discussion points since I made drastic changes here and there, partially due to experimentation as well, which is why I didnt ask a lot in the issue itself. |
That sounds good. I like the idea making the palette crate default implementation of color while people want to minimize the code size can use the builtin version (which enabled if the crate is opt-out) And I think it's nice to have palette crate behind the color interfaces. And I am open to replace To clearify what I don't want to merge into Plotters is:
Besides that I really like the idea. I should have more discussion with you before you start working on it. If you have any idea, please let me know. Also, any ideas on the color abstraction layer itself is welcome. I am open to change (but not remove) it as well. Thanks again, really appreciate for your help! |
Alright, I'll think some more about it tomorrow and get back to you then. 👍 |
Okay so I'm just gonna try to integrate the The only breaking change I might consider is to change the color structs defined here to be just all So what I would ideally propose is to still allow me to make the breaking change as to change those colors all to constants but expose the same special colors implemented as |
On that Note, I would also propose to remove the |
Hi, Thank you for the detailed proposal. I really like it. Please see the comment inline below. Really appreciated for your help. Thanks,
This sounds really good, and should have less work needs to do as well.
Ah, I see if a compatible module will be introduced, I think it's Ok to do that.
That sound good, as long as the API doesn't change, the only difference is importing another module.
And for this one, the |
Okay, so to summarize what this PR does(I pushed before your comment already which is assume you already saw): We have this module which implements the Color traits for all of the palette colors The only breakage here now is that all the predefined colors are constants instead of structs which also changes the character cases of them(this is what makes the PR so chaotic since it replaces all the predefined color uses with the new constant names). In the lib.rs file we then reexport the palette crate. Whether this is really needed or not is preference since it has advantages and disadvantages. Advantage being that if for some reason the end user has multiple versions of palette(which shouldnt happen since this is not a crate that is being used often by other crates) he can easily use the exact version needed through the reexport in their code. Disadvantage being upgrading palette could incur a version bump for plotters since the palette api might change itself, but i believe this would be needed even if we were to not reexport it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything looks pretty good to me and thank you so much for the work. I've been thinking about enhancement for the color system for a long time.
The only one thing is the dependencies for WASM target seems not working. Just make sure you also tried the WASM sample as well :)
|
||
[target.'cfg(target_arch = "wasm32")'.dependencies] | ||
web-sys = { version = "0.3.4", features = ['Document', 'Element', 'HtmlElement', 'Node', 'Window', 'HtmlCanvasElement', 'CanvasRenderingContext2d'] } | ||
js-sys= "0.3.4" | ||
wasm-bindgen = "0.2.43" | ||
|
||
[features] | ||
default = ["bitmap", "svg", "chrono"] | ||
default = ["bitmap", "svg", "chrono", "palette_ext"] | ||
palette_ext = ["palette", "num-traits"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems this cause default WASM fail to build.
I think we need to include the dependency when target is wasm32 as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, forgot about that. Ill move that up into the overall dependencies then,
though i gotta say im slightly confused as to why wasm builds with the image
dependency given that is only defined for non wasm builds but its still part of the default features list through the bitmap feature.
@@ -1,12 +1,12 @@ | |||
use plotters::prelude::*; | |||
fn main() -> Result<(), Box<dyn std::error::Error>> { | |||
let root = BitMapBackend::new("plotters-doc-data/5.png", (640, 480)).into_drawing_area(); | |||
root.fill(&White); | |||
root.fill(&WHITE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems you already done this.
Since we use rustdoc as README.md as well. So README.md
and RustDoc in lib.rs
are generated by doc-template/update_readme.sh
.
If you haven't done this I will do it before merge :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no used the scripts since I wasnt sure how to exactly use them. I simply did a project wide replacement of the colors.
The wasm sample seems to compile but i cant run it properly cause wasm-bindgen fails for me due to
This panic happens with the palette_ext feature as well as without it though. |
I have tried this and seen the similar error message. When I try to update my wasm-bindgen-cli, the error seems gone. |
Unfortunately I am on the most recent version so updating isnt an option for me to fix this. |
It's panic in the But I think I tried it works on my Linux machine. So I guess it's ready to merge, or you want to dig into that. It's up to you :) |
Nah, its probably OS specific then and I havent really dug into wasm stuff myself anyways. I'd say it's ready to merge then if it works for you on linux. |
Alright, I am merging the PR. Thank you for this amazing work! |
This PR attempts to replace the crates color implementations with the palette crate. I have removed the Palette traits and structures for now since their use was weird to me and i wasnt sure how to translate them properly. The readme is also not updated since i saw that you have a script for that but i wasnt sure how to use it.This is obviously a breaking change since this changes the public api drastically in terms of using a new crates for colors.Focus has shifted, read comments.
Fixes #19