Skip to content

Test graph PDF output with more than 1000 points - #3988

Open
lorenzozanee wants to merge 2 commits into
plotly:devfrom
lorenzozanee:fix/graph-print-large-data
Open

lorenzozanee wants to merge 2 commits into
plotly:devfrom
lorenzozanee:fix/graph-print-large-data

Conversation

@lorenzozanee

Copy link
Copy Markdown

Adds a deterministic browser integration fixture for 1000 and 1001 point graphs. The test emulates print media and exercises Chrome Page.printToPDF while preserving the existing graph and browser-log assertions.

The assertion verifies a valid non-empty PDF and a visible SVG trace; it does not inspect rendered PDF pixels, so cross-browser validation remains for CI and maintainers.

Contributor Checklist

  • I have broken down my PR scope into the following TODO tasks
    • task 1
    • task 2
  • I have run the tests locally and they passed. (refer to testing section in contributing)
  • I have added tests, or extended existing tests, to cover any new features or bugs fixed in this PR

optionals

  • I have added entry in the CHANGELOG.md
  • If this PR needs a follow-up in dash docs, community thread, I have mentioned the relevant URLS as follows
    • this GitHub #PR number updates the dash docs
    • here is the show and tell thread in Dash community

Fixes #3889

@sonarqubecloud

Copy link
Copy Markdown

@T4rk1n T4rk1n left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't fix #3889 and the test would pass on dev as-is, so it can't guard against the bug. The 1000-point cutoff in the issue comes from px.line: with render_mode="auto", plotly express switches to scattergl once you pass 1000 rows (px.line(x=range(1001), y=range(1001)).data[0].type == "scattergl"). So the actual bug is about WebGL canvas content not making it into print or html2canvas output. This test hardcodes type: "scatter", which renders SVG at any point count, and it uses Chrome native print, which the issue already says works. I'd block on this: please drop the Fixes #3889 line. Either turn this into a real repro (scattergl, checking the printed output) or close it and leave the issue open.

app.layout = dcc.Graph(
id="graph",
figure={
"data": [{"type": "scatter", "mode": "lines", "x": points, "y": points}],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type: "scatter" never goes down the path that breaks. 1000 and 1001 points both render as SVG, so the parametrize doesn't test the threshold at all. The switch at 1001 happens because px picks scattergl. Can you use scattergl (or build the figure with px.line) so the test hits the WebGL path?


driver.execute_cdp_cmd("Emulation.setEmulatedMedia", {"media": "print"})
pdf = driver.execute_cdp_cmd(
"Page.printToPDF", {"printBackground": True, "preferCSSPageSize": True}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue says Chrome's native print works fine at 2000 points. The failing cases are Firefox print and html2pdf/html2canvas. A Chrome Page.printToPDF check passes whether the bug is there or not. What case is this meant to fail on?

)

pdf_bytes = base64.b64decode(pdf["data"])
assert pdf_bytes.startswith(b"%PDF")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These assertions don't look at what got printed. Any page makes a PDF with a %PDF header that's over 1000 bytes, and the is_displayed() check reads the live DOM, not the PDF. An empty plot in the PDF (the reported symptom) passes all three. If you want to test print output, can you render the PDF, or a canvas snapshot of the graph, and check that the trace pixels are there?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Graphs excluded from print pages if they have over 1000 datapoints

3 participants