Skip to content

feat(canvas): update DPR after resizing#1149

Merged
plainheart merged 4 commits into
ecomfe:masterfrom
Justin-ZS:feat/able_to_update_dpr_in_resize
May 26, 2026
Merged

feat(canvas): update DPR after resizing#1149
plainheart merged 4 commits into
ecomfe:masterfrom
Justin-ZS:feat/able_to_update_dpr_in_resize

Conversation

@Justin-ZS
Copy link
Copy Markdown

Summary

  • Allow dynamic devicePixelRatio updates through the resize() method
  • Add Layer.updateDpr() to keep canvas context dpr in sync

Fix

apache/echarts#21386

Usage

zr.resize({
    width: 800,
    height: 600,
    devicePixelRatio: window.devicePixelRatio
});

Changes

  • Add optional devicePixelRatio parameter to PainterBase.resize() interface
  • Add Layer.updateDpr() method
  • Update Painter.resize() to trigger layer resize on dpr change
  • Expose devicePixelRatio option in ZRender.resize()

Comment thread src/canvas/Painter.ts Outdated
@Justin-ZS Justin-ZS requested a review from plainheart January 30, 2026 10:21
Comment thread src/canvas/Painter.ts Outdated
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I tend to completely replace the constant devicePixelRatio in favor of the new getDevicePixelRatio() function.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

done

Comment thread src/canvas/Layer.ts Outdated
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The same here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Or just let the DPR fall back to 1 and only do it in zrender constructor?
https://github.com/Justin-ZS/zrender/blob/5a52347e793a2eeffcc9eaed5dd4538087755eac/src/zrender.ts#L92

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I prefer to do it only in the Canvas Painter constructor.

@Justin-ZS Justin-ZS requested a review from plainheart February 2, 2026 03:28
Comment thread src/canvas/Painter.ts
// TODO sting?
height = opts.height as number;
}
this.dpr = opts.devicePixelRatio || 1;
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@plainheart
Since this.dpr has already been initialized before, I removed this line.
Please let me know if forcing 1 here was intentional.

@Justin-ZS
Copy link
Copy Markdown
Author

Justin-ZS commented Mar 4, 2026

@plainheart Could you help to review again? Thanks!

@Jancheng-z

This comment was marked as off-topic.

@plainheart
Copy link
Copy Markdown
Collaborator

@plainheart Could you help to review again? Thanks!

Generally, I have no more comments. I plan to merge your PR if there is no review from other members after the release of ECharts v6.1.0

@plainheart plainheart changed the title feat(dpr): able to update dpr by resize feat(canvas): update DPR after resize May 26, 2026
@plainheart plainheart merged commit 3491110 into ecomfe:master May 26, 2026
1 check passed
@plainheart plainheart changed the title feat(canvas): update DPR after resize feat(canvas): update DPR after resizing May 28, 2026
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.

3 participants