codeant-ai-for-open-source[bot] commented on code in PR #43456:
URL: https://github.com/apache/superset/pull/43456#discussion_r3843312689
##########
superset-frontend/src/utils/downloadAsImage.tsx:
##########
@@ -223,30 +236,58 @@ const processCloneForVisibility = (clone: HTMLElement) =>
{
});
};
-const preserveCanvasContent = (original: Element, clone: Element) => {
+const preserveCanvasContent = (
+ original: Element,
+ clone: Element,
+ getInstanceByDom?: EChartsGetInstanceByDom,
+) => {
const originalCanvases = original.querySelectorAll('canvas');
const clonedCanvases = clone.querySelectorAll('canvas');
+ // `renderToCanvas` flattens all of an ECharts instance's zrender layers
into a single canvas,
+ // so a host that owns several <canvas> layers (e.g. a hover layer) must be
re-rendered once.
+ const renderedHosts = new WeakSet<Element>();
originalCanvases.forEach((originalCanvas, i) => {
- if (originalCanvases[i] && clonedCanvases[i]) {
- const clonedCanvas = clonedCanvases[i] as HTMLCanvasElement;
- const ctx = clonedCanvas.getContext('2d');
- if (ctx) {
- clonedCanvas.width = originalCanvas.width;
- clonedCanvas.height = originalCanvas.height;
- ctx.drawImage(originalCanvas, 0, 0);
- }
+ const clonedCanvas = clonedCanvases[i] as HTMLCanvasElement | undefined;
+ if (!clonedCanvas) return;
+ const ctx = clonedCanvas.getContext('2d');
+ if (!ctx) return;
+
+ // For ECharts (canvas renderer) charts such as sunburst, re-render the
chart at a higher
+ // pixel ratio instead of copying the on-screen bitmap, so the PNG path
upscales a matching
+ // high-resolution source rather than stretching a low-resolution one.
+ const host = originalCanvas.closest(`.${ECHARTS_HOST_CLASS}`);
+ const instance = host ? getInstanceByDom?.(host as HTMLElement) :
undefined;
+ if (host && instance) {
+ // A secondary layer of an already re-rendered host is fully covered by
the flattened
+ // render above; leave its blank clone untouched so the chart is not
drawn twice.
+ if (renderedHosts.has(host)) return;
+ renderedHosts.add(host);
+ const hiResCanvas = instance.renderToCanvas({
+ pixelRatio: EXPORT_CANVAS_PIXEL_RATIO,
+ backgroundColor: 'transparent',
+ });
Review Comment:
**Suggestion:** The re-render forcibly makes every ECharts canvas
transparent, even when the requested export uses a solid background or the
chart configuration defines its own `backgroundColor`. The existing `bgcolor`
option cannot restore pixels that were already omitted from the rendered
canvas, so solid exports can lose the chart's configured background. Pass the
effective export background consistently or preserve the chart background for
solid exports. [logic error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ Solid ECharts exports lose configured chart backgrounds.
- ⚠️ JPEG downloads flatten charts onto the wrong background.
- ⚠️ PNG exports with solid backgrounds can differ from live charts.
```
</details>
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset-frontend/src/utils/downloadAsImage.tsx
**Line:** 266:269
**Comment:**
*Logic Error: The re-render forcibly makes every ECharts canvas
transparent, even when the requested export uses a solid background or the
chart configuration defines its own `backgroundColor`. The existing `bgcolor`
option cannot restore pixels that were already omitted from the rendered
canvas, so solid exports can lose the chart's configured background. Pass the
effective export background consistently or preserve the chart background for
solid exports.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43456&comment_hash=8d113b7d7658f44c51aa5946eb4e59320ac8da3e1a76af61ebde20bfd1ffa620&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43456&comment_hash=8d113b7d7658f44c51aa5946eb4e59320ac8da3e1a76af61ebde20bfd1ffa620&reaction=dislike'>👎</a>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]