-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Test graph PDF output with more than 1000 points #3988
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import base64 | ||
|
|
||
| import pytest | ||
|
|
||
| from dash import Dash, dcc | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("point_count", [1000, 1001]) | ||
| def test_grpr001_graph_survives_print(point_count, dash_dcc): | ||
| app = Dash(__name__) | ||
| points = list(range(point_count)) | ||
| app.layout = dcc.Graph( | ||
| id="graph", | ||
| figure={ | ||
| "data": [{"type": "scatter", "mode": "lines", "x": points, "y": points}], | ||
| "layout": {"width": 600, "height": 400}, | ||
| }, | ||
| ) | ||
|
|
||
| dash_dcc.start_server(app) | ||
| dash_dcc.wait_for_element("#graph .main-svg") | ||
|
|
||
| driver = dash_dcc.driver | ||
| if not hasattr(driver, "execute_cdp_cmd"): | ||
| pytest.skip("print-to-PDF regression requires Chrome DevTools Protocol") | ||
|
|
||
| driver.execute_cdp_cmd("Emulation.setEmulatedMedia", {"media": "print"}) | ||
| pdf = driver.execute_cdp_cmd( | ||
| "Page.printToPDF", {"printBackground": True, "preferCSSPageSize": True} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| ) | ||
|
|
||
| pdf_bytes = base64.b64decode(pdf["data"]) | ||
| assert pdf_bytes.startswith(b"%PDF") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| assert len(pdf_bytes) > 1000 | ||
| assert dash_dcc.find_element("#graph .scatterlayer .trace path").is_displayed() | ||
| assert dash_dcc.get_logs() == [] | ||
There was a problem hiding this comment.
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 becausepxpicksscattergl. Can you usescattergl(or build the figure withpx.line) so the test hits the WebGL path?