-
Notifications
You must be signed in to change notification settings - Fork 278
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
[BUG] DrawingArea::fill
doesn't fill the right and bottom edge in some backends
#368
Comments
// ↓ Added
root.draw(&Rectangle::new(
[(0, 0), (500, 500)],
ShapeStyle {
color: RGBAColor(255, 0, 0, 1.0),
filled: true,
stroke_width: 0,
},
))
.unwrap();
// ↑ Added
root.fill(&WHITE).unwrap(); |
You need to update dependencies to see plotters-rs/plotters-cairo#20 works.
-plotters-cairo = "0.3.1"
-cairo-rs = "^0.9"
-gtk = "^0.9"
-gio = "^0.9"
+plotters-cairo = { git = "https://github.com/shinmili/plotters-cairo.git", branch = "fix-rect-width-height" }
+cairo-rs = "^0.15"
+gtk = "^0.15"
+gio = "^0.15"
let application = gtk::Application::new(
Some("io.github.plotters-rs.plotters-gtk-test"),
Default::default(),
- )
- .expect("Initialization failed...");
+ );
application.connect_activate(|app| {
build_ui(app);
});
- application.run(&args().collect::<Vec<_>>());
+ application.run_with_args(&args().collect::<Vec<_>>());
} (When should this patch be merged? After publishing plotters-cairo to crates.io?) |
Honestly, I don't know if we should fix the backends that don't work or whether we should rather fix plotters call to the backend. I think in this case the call to the backend is wrong. If the canvas is 100x100, the call would draw a rectangle with (0, 0) and (99, 99). And if the canvas was 0x0, the call would even draw a rectangle with (0, 0) and (-1, -1). That looks odd to me and is not how most backends work, as you pointed out in the issue. Lines 283 to 293 in a72bfbc
The question is should we fix the backends that don't work or should we fix the backend that work? I'd say SVG, canvas and cairo were rightfully printing too few pixels, due to the -1. And doing a +1 on in each backend would only harm the rectangle drawing because that should be correct like it is. |
IMHO the real problem is that there is no serious vector graphics backend abstraction (as discussed in #128), and implementing Looking around some codes and docs, I understood most parts of them assumes After a new trait for a vector graphics backend is introduced (or Or if we start #128 now, I'd like to help you, and would like to scrap those workaround patches now! |
@shinmili I agree and will support you with improving the internal code for vector graphics backends. IMO vector graphics should be the "default" and raster graphics should have to adjust, not the other way around. I just don't have a lot time right now due to exams. But there's one thing about the bitmap backend, I'm not sure whether it's actually correct: use plotters::prelude::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
//let root = BitMapBackend::new("plots/0.png", (6, 6)).into_drawing_area();
let root = SVGBackend::new("plots/0.svg", (6, 6)).into_drawing_area();
root.draw(&Rectangle::new(
[(0, 0), (5, 5)],
ShapeStyle {
color: RGBAColor(255, 0, 0, 1.0),
filled: true,
stroke_width: 0,
},
))?;
root.draw(&Rectangle::new(
[(0, 0), (1, 1)],
ShapeStyle {
color: RGBAColor(0, 255, 0, 1.0),
filled: true,
stroke_width: 0,
},
))?;
root.draw(&Rectangle::new(
[(0, 0), (0, 0)],
ShapeStyle {
color: RGBAColor(0, 0, 255, 1.0),
filled: true,
stroke_width: 0,
},
))?;
root.present()?;
Ok(())
} |
@AaronErhardt OK, I had a confusion over how raster graphics should be, and now have changed my mind on what to fix: For some reason, I had been thinking raster graphics APIs should take coordinate ranges inclusively, and calling a maybe-out-of-bounds coordinate a "right-bottom corner" sounded really odd to me. In the context of your example, if btimap got fixed, I stopped confusing after reviewing Win32 GDI API's
So that's how most graphics libraries work, even in raster graphics. It's just fine to use Thanks for your fruitful comments! |
We really appreciate your contributions. Please bear in mind that plotters and plotters-bitmap are now hosted on the same GitHub repo. Thanks! |
Hi guys, thanks for the investigation. I think we should adjust bitmap backend to match SVG backend for consistency. @shinmili 's PR looks good to me, and I am also wondering if @facorread and @AaronErhardt have any idea about the PR. And we need to clean up the plotters core code which assumes the rasterized backend - this is a legacy issue for a long time. Back to early days plotters was a program that renders PNG on a server. But since then plotters is becoming bigger and bigger - original rasterizing code was moved to plotters-backend as default rasterizer and plotters-bitmap was implemented as transparent optimization for framebuffer rendering. Unfortunately, the different assumption have never been cleaned up and ending up those crappy bugs we are seeing today. I strongly agree that we should have a new backend trait that really supports vector graphs. But this is a breaking change which means a major release of 0.4 - Once I have time I would definitely do that. While at the same time, I am also want to really think about interactivity support as well. It's not really relevant to the thread, but I think it's a time for a road map to next major release which allows us to make breaking change and properly fix all the legacy issue. Please let me know if you guys have any idea, and really appreciate for the awesome contribution! |
Describe the bug
DrawingArea::fill
doesn't fill the right and bottom edge in some backends and leaves transparent edges in a generated image. As far as I have checked, plotters-svg and plotters-canvas have this issue.BitMapBackend
is fine about this.For CanvasBackend, it's quick to see #165's attached image. It continues in the latest code too.
For SVGBackend, The repro code below prints this result.
width
andheight
in therect
element should be"100"
here.Other backends with sub-pixel coordinate might have the same issue. Can be related to #128.
To Reproduce
Version Information
plotters
: current master (a72bfbc)plotters-svg
: current master (plotters-rs/plotters-svg@47289e8)plotters-canvas
: current master (plotters-rs/plotters-canvas@111fce5)The text was updated successfully, but these errors were encountered: