plotters icon indicating copy to clipboard operation
plotters copied to clipboard

[BUG] Stretched Area in Histogram

Open seanaye opened this issue 2 years ago • 2 comments

Describe the bug I have a simple histogram which plots some data in the wasm backend

fn draw(root_area: DrawingArea<CanvasBackend, Shift>, users: Vec<User>) -> Result<()> {
    let max_subs = users
        .iter()
        .map(|u| u.quantity)
        .fold(std::i64::MIN, |a, b| a.max(b));
    let emails = users.iter().map(|x| x.email.to_owned()).collect::<Vec<_>>();
    let mut ctx = ChartBuilder::on(&root_area)
        // .set_label_area_size(LabelAreaPosition::Left, 40)
        // .set_label_area_size(LabelAreaPosition::Bottom, 40)
        .build_cartesian_2d(emails.into_segmented(), 0..max_subs)
        .unwrap();

    ctx.configure_mesh().draw().unwrap();


    ctx.draw_series(
        Histogram::vertical(&ctx)
            .margin(100)
            .data(users.iter().map(|x| (&x.email, x.quantity))),
    )
    .unwrap();
    Ok(())
}

When this renders there is an area in the middle of the canvas that is stretched and warped. This appears to be a rendering bug Screen Shot 2023-07-20 at 4 00 19 PM

To Reproduce See code above

Version Information plotters = "0.3.5" plotters-canvas = "0.3.0"

seanaye avatar Jul 20 '23 20:07 seanaye

I have found this only occurs when there are >20 bars to plot. It also occurs in the opposite way in Histogram::vertical

seanaye avatar Jul 20 '23 20:07 seanaye

Could it be because you are using a very high value for margin (.margin(100))? 100 pixels seems too large to me. Maybe there should be some check for when the total margin in each direction is bigger than the rectangle size in that direction.

AliMMehr avatar Nov 06 '23 08:11 AliMMehr