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

Support clipping in DrawingBackend #622

Open
Zoxc opened this issue Jul 28, 2024 · 1 comment
Open

Support clipping in DrawingBackend #622

Zoxc opened this issue Jul 28, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Zoxc
Copy link
Contributor

Zoxc commented Jul 28, 2024

Currently drawing outside the chart area is handled incorrectly because the drawing backend has no clipping support. To fix this we could clip drawing to the chart area and no longer truncate coords in CoordMapper impls.

@Zoxc Zoxc added the bug Something isn't working label Jul 28, 2024
@bluenote10
Copy link

I guess this issue refers to the following problem:

use plotters::prelude::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let root = BitMapBackend::new("basic_plot.png", (640, 480)).into_drawing_area();

    root.fill(&WHITE)?;
    let mut chart = ChartBuilder::on(&root)
        .caption("y=x^2", ("sans-serif", 50).into_font())
        .margin(5)
        .x_label_area_size(30)
        .y_label_area_size(30)
        .build_cartesian_2d(-2f32..2f32, -0.1f32..1f32)?;

    chart.configure_mesh().draw()?;

    chart
        .draw_series(LineSeries::new(
            (-100..=100).map(|x| x as f32 / 50.0).map(|x| (x, x * x)),
            &RED,
        ))?
        .label("y = x^2")
        .legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], &RED));

    chart
        .configure_series_labels()
        .background_style(&WHITE.mix(0.8))
        .border_style(&BLACK)
        .draw()?;

    root.present()?;

    Ok(())
}

Produces:

basic_plot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants