Skip to content

feat(canvas): update devicePixelRatio to prevent chart being blurry after resizing#21489

Merged
plainheart merged 3 commits into
apache:masterfrom
Justin-ZS:feat/able_to_update_dpr_in_resize
May 28, 2026
Merged

feat(canvas): update devicePixelRatio to prevent chart being blurry after resizing#21489
plainheart merged 3 commits into
apache:masterfrom
Justin-ZS:feat/able_to_update_dpr_in_resize

Conversation

@Justin-ZS
Copy link
Copy Markdown
Contributor

@Justin-ZS Justin-ZS commented Jan 22, 2026

Brief Information

This pull request is in the type of:

  • bug fixing
  • new feature
  • others

What does this PR do?

Auto update devicePixelRatio on resize() to fix blurry chart after browser zoom.
Zoom in to 500% and call resize().
Before:
截屏2026-01-22 17 15 14
After:
截屏2026-01-22 17 13 53

Fixed issues

Details

Before: What was the problem?

When browser zoom changes, calling chart.resize() does not update devicePixelRatio, resulting in blurry charts.

After: How does it behave after the fixing?

resize() now defaults to use window.devicePixelRatio, so charts automatically become crisp after browser zoom.

Document Info

Misc

Security Checking

  • This PR uses security-sensitive Web APIs.

ZRender Changes

Related test cases or examples to use the new APIs

Merging options

  • Please squash the commits into a single one when merging.

Other information

This PR also includes a small CI workflow fix for the lint job. The job restores node_modules from cache and skips npm ci on cache hits, but npm ci is the step that normally runs prepare -> build:lib and generates types/dist/echarts. Without regenerating those type files, npm run checktype can fail with Cannot find module './types/dist/echarts'.

To make the PR check deterministic, the workflow now runs npm run build:lib explicitly before npm run checktype.

@echarts-bot echarts-bot Bot added PR: awaiting doc Document changes is required for this PR. PR: awaiting review labels Jan 22, 2026
@echarts-bot
Copy link
Copy Markdown

echarts-bot Bot commented Jan 22, 2026

Thanks for your contribution!
The community will review it ASAP. In the meanwhile, please checkout the coding standard and Wiki about How to make a pull request.

Please DO NOT commit the files in dist, i18n, and ssr/client/dist folders in a non-release pull request. These folders are for release use only.

Document changes are required in this PR. Please also make a PR to apache/echarts-doc for document changes and update the issue id in the PR description. When the doc PR is merged, the maintainers will remove the PR: awaiting doc label.

This PR depends on ZRender changes. Please update the ZRender dependency to the latest nightly version including this change, which takes place everyday at 8:00 UTC (16:00 Beijing Time).
You can use npm i zrender@npm:zrender-nightly@dev to update package.json.
If you have any question about this, please leave a comment and we will give you extra help on this.

@Justin-ZS Justin-ZS requested a review from plainheart January 22, 2026 09:39
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 22, 2026

The changes brought by this PR can be previewed at: https://echarts.apache.org/examples/editor?version=PR-21489@a29afe9

@plainheart plainheart changed the title feat(drp): use current dpr when resize feat(core): use current device pixel ratio when resize Jan 22, 2026
Comment thread src/core/echarts.ts Outdated
@Justin-ZS Justin-ZS force-pushed the feat/able_to_update_dpr_in_resize branch from a29afe9 to 66901e6 Compare May 27, 2026 08:02
@Justin-ZS
Copy link
Copy Markdown
Contributor Author

@plainheart Could you help to review ? Thanks!

@plainheart plainheart merged commit dc60bdd into apache:master May 28, 2026
2 checks passed
@echarts-bot
Copy link
Copy Markdown

echarts-bot Bot commented May 28, 2026

Congratulations! Your PR has been merged. Thanks for your contribution! 👍

@plainheart plainheart changed the title feat(core): use current device pixel ratio when resize feat(canvas): update devicePixelRatio to prevent chart being blurry after resizing May 28, 2026
@plainheart plainheart added this to the 6.2.0 milestone May 28, 2026
@Justin-ZS
Copy link
Copy Markdown
Contributor Author

Doc PR: apache/echarts-doc#514

@echarts-bot echarts-bot Bot added PR: doc ready and removed PR: awaiting doc Document changes is required for this PR. labels May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] resize() does not redraw chart with correct devicePixelRatio after browser zoom

2 participants