Skip to content

Plot not filling the height of the container/screen. #240

Closed
@jdbosser

Description

@jdbosser

Hi! I am just getting started with plotly. I am using the example from the book. . I have modified the example to output an HTML file in out.html.
Here is the code

use plotly::common::Mode;
use plotly::{Plot, Scatter};

fn line_and_scatter_plot() {
    let trace1 = Scatter::new(vec![1, 2, 3, 4], vec![10, 15, 13, 17])
        .name("trace1")
        .mode(Mode::Markers);
    let trace2 = Scatter::new(vec![2, 3, 4, 5], vec![16, 5, 11, 9])
        .name("trace2")
        .mode(Mode::Lines);
    let trace3 = Scatter::new(vec![1, 2, 3, 4], vec![12, 9, 15, 12]).name("trace3");

    let mut plot = Plot::new();
    plot.add_trace(trace1);
    plot.add_trace(trace2);
    plot.add_trace(trace3);
    plot.write_html("out.html");
}

fn main() -> std::io::Result<()> {
    line_and_scatter_plot();
    Ok(())
}

Here is the Cargo.toml

[package]
name = "gp"
version = "0.1.0"
edition = "2021"

[dependencies]
plotly = "0.10.0"

This produces this result in chromium (Version 130.0.6723.69 (Official Build) snap (64-bit)), as seen in the screenshot.
Image

It is rendered similarly in Firefox.

My problem is that I want it to extend to the whole height of the screen. I have tried to modify the plotly code to include

    // ....
    let mut plot = Plot::new();
    let c = plot.configuration(); 
    let c = c.clone().responsive(true);
    let c = c.autosizable(true);
   //....

as per suggestions in forums [1][2]
Yet, it did not scale as it should.

I found a comment suggesting to make sure that the parent is 100% . Indeed, modifying the inline CSS in the browser produces a correct plot. See the attached screenshot.
Image
I have noticed that html, body, and the first div in the body all need this property set for it to work. Note that, I seem to need to resize the window or interact with the plot for the changes to take effect.

I am a bit skeptical though. I found no comments in this repository about people having this issue. I cannot imagine I am the first one, since I stumbled upon it as I was testing my first example. I rather assume I am doing something wrong. If so, can someone give me some guidance and/or update (or help me update) the docs? Alternatively, the behavior is intentional. In that case, would it be possible to include an option to opt out of the limited height?

If this truly is an error, then I have noticed that the fix should be to implement the styling in plot.html-template. . I can contribute with a PR if this is the right way to solve this issue.

Thank you for a nice crate! It seems well put together and I look very much forward to using it!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions