Repository navigation
fix(dashboard): stop wide table charts bleeding over neighbours in dashboard image export #44414
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -159,7 +159,23 @@ const copyAllComputedStyles = ( | |
| } | ||
| }; | ||
|
|
||
| const processCloneForVisibility = (clone: HTMLElement) => { | ||
| // True when the element clips its content on at least one axis. `copyAllComputedStyles` | ||
| // writes the computed `overflow` inline on the whole tree, so `[style*="overflow"]` below | ||
| // matches nearly every node; only the ones that actually clip should have their overflow | ||
| // rewritten. Both the shorthand and the longhands are read because engines disagree on | ||
| // which of them a computed style resolves: browsers resolve the longhands, jsdom only | ||
| // echoes back whichever form was specified. | ||
| const clipsOverflow = (element: HTMLElement) => { | ||
| const computed = window.getComputedStyle(element); | ||
| return /auto|scroll|hidden|clip/.test( | ||
| `${computed.overflow} ${computed.overflowX} ${computed.overflowY}`, | ||
| ); | ||
| }; | ||
|
|
||
| const processCloneForVisibility = ( | ||
| clone: HTMLElement, | ||
| clipHorizontalOverflow = false, | ||
| ) => { | ||
| const cloneStyle = clone.style; | ||
| cloneStyle.height = 'auto'; | ||
| cloneStyle.maxHeight = 'none'; | ||
|
|
@@ -183,9 +199,25 @@ const processCloneForVisibility = (clone: HTMLElement) => { | |
| scrollableSelectors.forEach(selector => { | ||
| clone.querySelectorAll(selector).forEach(el => { | ||
| const element = el as HTMLElement; | ||
| element.style.overflow = 'visible'; | ||
| element.style.height = 'auto'; | ||
| element.style.maxHeight = 'none'; | ||
| if (!clipsOverflow(element)) return; | ||
| if (clipHorizontalOverflow) { | ||
| // The vertical axis stays unclipped so the whole chart paints while the | ||
| // grid reflows around its now auto-height slot. The horizontal axis keeps | ||
| // its clip: the clone preserves every element's on-screen pixel width, so | ||
| // a table that scrolls sideways would otherwise paint its off-slot columns | ||
| // across the charts sitting next to it in the same dashboard row. | ||
| // `clip` rather than `hidden`, because `hidden` paired with `visible` is | ||
| // not a legal computed combination: the engine promotes the `visible` axis | ||
| // to `auto` and clips that one too. `clip` paired with `visible` clips a | ||
| // single axis and leaves the element a non-scroll-container, so nothing | ||
| // but the sideways bleed changes. | ||
| element.style.overflowX = 'clip'; | ||
| element.style.overflowY = 'visible'; | ||
|
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. Suggestion: Dashboard exports make every matching clipped element vertically visible, including chart header titles that rely on hidden overflow for ellipsis, allowing labels to bleed outside their chart. Assessment: 🟠 Prompt for AI Agent 🤖This is a comment left during a code review.
**Path:** superset-frontend/src/utils/downloadAsImage.tsx
**Line:** 217:217
**Comment:**
*Logic Error: Dashboard exports make every matching clipped element vertically visible, including chart header titles that rely on hidden overflow for ellipsis, allowing labels to bleed outside their chart.
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 |
||
| } else { | ||
| element.style.overflow = 'visible'; | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
|
|
@@ -302,6 +334,7 @@ const createEnhancedClone = ( | |
| originalElement: Element, | ||
| theme?: SupersetTheme, | ||
| getInstanceByDom?: EChartsGetInstanceByDom, | ||
| clipHorizontalOverflow = false, | ||
| ): { clone: HTMLElement; cleanup: () => void } => { | ||
| const clone = originalElement.cloneNode(true) as HTMLElement; | ||
| copyAllComputedStyles(originalElement, clone, theme); | ||
|
|
@@ -319,7 +352,7 @@ const createEnhancedClone = ( | |
| tempContainer.appendChild(clone); | ||
| document.body.appendChild(tempContainer); | ||
|
|
||
| processCloneForVisibility(clone); | ||
| processCloneForVisibility(clone, clipHorizontalOverflow); | ||
|
|
||
| const cleanup = () => { | ||
| if (tempContainer.parentElement) { | ||
|
|
@@ -583,6 +616,7 @@ export default function downloadAsImageOptimized( | |
| elementToPrint, | ||
| theme, | ||
| getInstanceByDom, | ||
| isDashboardCapture, | ||
| ); | ||
| cleanup = cleanupFn; | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
clipsOverflowcallswindow.getComputedStyle(element)for every node matching the scrollable selectors — including[style*="overflow"], which the comment notes matches nearly every node. Each call forces a style/layout recalc, adding O(n) forced layouts on the dashboard export path where the previous code set overflow directly. Reuse the computed styles already cached bycopyAllComputedStyles.Code Review Run #2e3788
Should Bito avoid suggestions like this for future reviews? (Manage Rules)