Conversation
|
Come to think of it, this macro would allow removal of the |
|
Sorry I didn't get to this this weekend. I'll try to look at it soon. |
|
Think this is ready for discussion now (though no rush). Happy to take feedback: I want to make it work for what you want and need for the project. |
|
Note that a couple of types are unfinished: these need finishing (if I can work out what they do) or removing. |
|
Alright, I have many little comments but I wanted to start with a high level API one. I really don't like how the ColorOpt/Color came out. I don't want to have weirdly capitalized functions masquerading as enum variants. I'd rather bite the bullet, and force the user to type enum ColorType<T>
{
RGBString(T),
}
enum PlotOption
{
Color(ColorType<T>)
}
...
[Color("red".into())]While it requires more characters, I think it's easier to understand what is happening. Calling |
|
That makes sense. I think I tried too hard to keep it to the same interface as before, but happy to make the change you suggest. |
|
Done (assuming tests pass). I think perhaps I got a bit carried away finding a way I could create the Also, I hadn't quite clicked that |
SiegeLord
left a comment
There was a problem hiding this comment.
Here's some more comments. Overall this looks pretty good. The main remaining issue I have is what to do with the alpha channel (see one of the comments).
| RGBInteger(ColorComponent, ColorComponent, ColorComponent), | ||
| /// tuple of u8 representing alpha, red, green and blue values as 0-255. | ||
| /// As with `RGBColor`, an alpha value of 0 represents a fully opaque color; | ||
| /// an alpha value of 255 (FF) represents full transparency. |
There was a problem hiding this comment.
It's very upsetting that gnuplot defines alpha backwards here (everywhere else, alpha = 0 -> fully transparent, alpha = 255 -> fully opaque). I wonder if the Rust API should invert it. I'll need to think about it.
There was a problem hiding this comment.
Yes, this is a tricky one. Both options could lead to "unexpected behaviour". The fix of inverting it could be done cleanly in the data() function, if that's the route you decide to go down.
…vnersion from public API
gnuplot/src/color.rs
Outdated
| Index(n) => &format!("{}", n), | ||
| Black => "black", | ||
| }; | ||
| String::from(str) |
There was a problem hiding this comment.
One thing I forgot: the double string conversion is a bit excessive. I think you can make it somewhat more efficient (and imo nicer to read) by making the match patterns return the string directly, i.e.
pub fn command(&self) -> String
{
match self
{
VariableRGBInteger(_) => "rgb variable".into(),
PaletteFracColor(v) => format!("palette frac {v}"),
}
}There was a problem hiding this comment.
Happy to make the change, and this is the way I wrote it first. I thought it was clearer with the selection logic separate from the conversion logic, but that's personal preference (and it's your project 😄 ). Fair point about efficiency though.
Strike that: having made the change it's far better your way!
|
Alright, this is merged as ffd11c0 with a few fixes (and the alpha inversion) in ab2c419. I verified that everything looks the same as before this change using the new output tests I added in a7dd0af. Thanks a lot for this, this was a lot of work and I appreciate you sticking through with it and addressing my comments. |
Thanks for engaging with it: It made a fair bit of work in reviewing as well! I like the new output tests, too. |
This is a (currently partial) implementation of some of the color types. More are planned to follow.
The main reason for starting a partial PR is to ask if the changes to the internal API are reasonable: the removal of the
new_plot_n()functions and effective replacement with agenerate_datamacro.(Also this has snowballed a bit and led me to try implementing several new plot types as I started trying to reproduce some of the gnuplot demos as my examples - those should probably come as separate PRs at some point)
Addresses #105 #86