-
Notifications
You must be signed in to change notification settings - Fork 264
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
It is really hard to extend the api, is there any plan to modify the api for easier using? #516
Comments
One idea could be to collect the impl<DB: DrawingBackend> Drawable<DB> for RectAndText {
fn draw<I: Iterator<Item = plotters_backend::BackendCoord>>(
&self,
mut points: I,
backend: &mut DB,
parent_dim: (u32, u32),
) -> Result<(), DrawingErrorKind<DB::ErrorType>> {
let points: Vec<plotters_backend::BackendCoord> = points.collect(); // collect points into a vector.
self.rect.draw(points.iter().cloned(), backend, parent_dim)?; // points.iter().cloned() will make an iterator. I use Iterator::cloned() to convert Iterator<&(i32, i32)> to Iterator<(i32, i32)>
let mut points = points.iter().cloned(); // Again make another iterator
match (points.next(), points.next()) {
(Some(a), Some(b)) => {
todo!()
}
_ => Ok(()),
}
}
} |
Agreeing with @alimm1995, at current moment, the api has too much boiler code. Even a simple line plot requires 26 lines of code, when I can switch to python and achieve that with 3 lines import matplotlib.pyplot as plt
plt.plot(x, y)
plt.show() |
Thanks for your solution, That collecting a |
It needs someone to pack the package into a new crate, just like |
It's true that the original maintainer of plotters is inactive, but plotters is still maintained. It is lacking active development though and IMO the crate could use some major clean-ups under the hood, but so far nobody has stepped up. Help with this would be highly appreciated :) |
Agreeing that there are some major overhauls that are required and wrapper would be great. There is currently a crate that uses Plotly in backend, however, for me, the biggest advantage of this crate is the ability to display plots in CLI and natively. |
|
It appears to be active, last commit 2 weeks ago https://github.com/plotters-rs/plotters |
I think changing an API is always hard as you need to get all stakeholders on board. It seems like many crates are extending plotters and we want them to switch to the new version too. I don't have an overview how easy it is to reach the maintainers of those crates, but major changes should be discussed with them as well. I think moving the style information in the type that wraps your rectangle is good. You may conclude the fill properties from the state of your "logical" rectangle but this should be done only once before drawing. My first instinct would be to extend Drawable with a fn collect_styles(&mut self); that may be called early in draw? But as a new user of plotters, I'm not confident to change APIs that are affecting so many other places. Maybe a good start would be to reduce the mentioned "talkiness" because that could be done with additions without changing too much of the underlying API as a starting contributer? |
For example, if I need to make a plot element drawing a rectangle, in which show a text:
If I plot the two part in one block, I would implement the type like this:
But the
rect.style
is private, so I can't do that.If I plot the two parts separately:
Then the points is lost. I find no way to do it.
Then I have to do it in this way, which does not effectively utilize the components that are already in place:
The text was updated successfully, but these errors were encountered: