Skip to content
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

Fix pie chart display when switching from notebook editor #42430

Conversation

JesseSDevaney
Copy link
Contributor

@JesseSDevaney JesseSDevaney commented May 8, 2024

Before

2024-05-08.17-09-22.mp4

After

2024-05-08.17-08-49.mp4

@JesseSDevaney JesseSDevaney added the .Team/DashViz Dashboard and Viz team label May 8, 2024
@JesseSDevaney JesseSDevaney requested review from alxnddr and a team May 8, 2024 21:14
@JesseSDevaney JesseSDevaney self-assigned this May 8, 2024
@metabase-bot metabase-bot bot added the visual Run Percy visual testing label May 8, 2024
Copy link

github-actions bot commented May 8, 2024

Codenotify: Notifying subscribers in CODENOTIFY files for diff 17852e5...b52c761.

Notify File(s)
@alxnddr frontend/src/metabase/visualizations/visualizations/PieChart/PieChart.jsx

@JesseSDevaney JesseSDevaney added the backport Automatically create PR on current release branch on merge label May 8, 2024
Copy link

replay-io bot commented May 8, 2024

Status Complete ↗︎
Commit b52c761
Results
⚠️ 7 Flaky
2480 Passed

@@ -258,11 +261,15 @@ export default class PieChart extends Component {
const { width, height } =
this.chartContainer.current.getBoundingClientRect();

if (width === 0 && height === 0) {
return this.updateChartViewportSize(delay + 200);
Copy link
Member

Choose a reason for hiding this comment

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

This looks a bit hackish, it would be great to avoid that.
So the problem is that ExplicitSize in ChartWithLegend resizes with a delay so that this updateChartViewportSize function is invoked when chartContainer still has zero width and zero height.

I think a more straightforward and reliable approach would be to call the previous version of updateChartViewportSize when ExplicitSize updates its size. Wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the feedback! I pushed up a commit to revert the hack and update the chart viewport size when ExplicitSize updates its size.

@@ -21,6 +21,15 @@ class ChartWithLegend extends Component {
style: {},
};

componentDidUpdate(prevProps) {
Copy link
Member

Choose a reason for hiding this comment

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

I believe a more suitable place for this would be right in ExplicitSize component:
In __updateSize we can change the line 186 to this.setState({ width, height }, () => this.props.onResize?.());

And then slightly tweak the prop you added in the PieChart: onResize={this.updateChartViewportSize}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, Sasha!

@JesseSDevaney JesseSDevaney enabled auto-merge (squash) May 10, 2024 20:22
@JesseSDevaney JesseSDevaney merged commit f1e1108 into master May 10, 2024
111 of 112 checks passed
@JesseSDevaney JesseSDevaney deleted the fix-pie-chart-null-display-when-switching-from-notebook-editor branch May 10, 2024 21:56
Copy link

@JesseSDevaney Did you forget to add a milestone to the issue for this PR? When and where should I add a milestone?

github-actions bot pushed a commit that referenced this pull request May 10, 2024
* fix pie chart display when switching from notebook editor

* remove hack

* fix missing pie chart display

* fix missing pie chart display

* address feedback

* fix type error
metabase-bot bot added a commit that referenced this pull request May 10, 2024
…42538)

* fix pie chart display when switching from notebook editor

* remove hack

* fix missing pie chart display

* fix missing pie chart display

* address feedback

* fix type error

Co-authored-by: Jesse Devaney <22608765+JesseSDevaney@users.noreply.github.com>
uladzimirdev pushed a commit that referenced this pull request May 11, 2024
* fix pie chart display when switching from notebook editor

* remove hack

* fix missing pie chart display

* fix missing pie chart display

* address feedback

* fix type error
@sloansparger sloansparger added this to the 0.49.10 milestone May 13, 2024
@bshepherdson bshepherdson removed this from the 0.49.10 milestone May 13, 2024
@alxnddr alxnddr added this to the 0.50 milestone May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport Automatically create PR on current release branch on merge .Team/DashViz Dashboard and Viz team visual Run Percy visual testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pie chart sometimes disappears
4 participants