Skip to content

Conversation

@Justin-ZS
Copy link

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()

@Justin-ZS Justin-ZS requested a review from plainheart January 30, 2026 10:21
Copy link
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
Author

Choose a reason for hiding this comment

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

done

Copy link
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
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
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
// TODO sting?
height = opts.height as number;
}
this.dpr = opts.devicePixelRatio || 1;
Copy link
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.

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.

2 participants