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: DH-18685: Remove top margin from chart #1126

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

jnumainville
Copy link
Collaborator

@jnumainville jnumainville commented Mar 3, 2025

Plotly Express adds a top margin that I have now removed. Fixes DH-18685

from deephaven import empty_table, ui
from deephaven.plot import express as dx

t = empty_table(10).update(["x=i", "y=i"])
p = dx.line(t, x="x", y="y", title="Title")
p2 = dx.line(t, x="x", y="y")

@jnumainville jnumainville requested review from a team, Copilot and mattrunyon and removed request for a team March 3, 2025 20:59

Choose a reason for hiding this comment

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

PR Overview

This PR addresses the removal of the default 60-pixel top margin added by Plotly Express when a title is not specified. Key changes include updating the figure layout in generate.py to remove the top margin and modifying numerous test cases to reflect the removal of the margin.

Reviewed Changes

File Description
plugins/plotly-express/src/deephaven/plot/express/deephaven_figure/generate.py Updates the layout update call to remove the default top margin from the figure.
plugins/plotly-express/test/deephaven/plot/express/plots/*.py Adjusts expected layouts in tests by removing the top margin value.

Copilot reviewed 45 out of 45 changed files in this pull request and generated no comments.

Copy link

github-actions bot commented Mar 3, 2025

plotly-express docs preview (Available for 14 days)

Copy link

github-actions bot commented Mar 3, 2025

plotly-express docs preview (Available for 14 days)

Copy link
Collaborator

@mattrunyon mattrunyon left a comment

Choose a reason for hiding this comment

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

Do we have e2e tests with titles? Wanted to make sure this doesn't break things with titles, but haven't run the code yet

Comment on lines +1057 to +1063
# px adds a margin of 60 if a title is not specified
# since most charts still use px at their core and
# this isn't user controlled in any way, remove it after
# the figure is already created
px_fig.update_layout(
margin_t=None,
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just to make sure, the user couldn't set margin before this change and they still can't? Or the user can through unsafe_update_figure?

I'm guessing if we wanted to expose this as a prop in the future we would need to revisit this a bit to check if the user set the margin or we did.

Is there any way to set this via default themeing in plotly or is this added separately from the theme by plotly?

Copy link
Collaborator Author

@jnumainville jnumainville Mar 5, 2025

Choose a reason for hiding this comment

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

We don't have any e2e tests currently for title. The indicator review has one but probably a good idea to add more so I can do that. Titles did work correctly as per the example though. px has some conditional logic that adds this top margin only if title is not specified and that is handled by px still for most plots.
They could and still can set it through unsafe_update_figure. That is applied after a few returns outside of this.
If we wanted to expose it as a prop we could just remove this and have a default top margin of None. Then it would be added to the props list at the top of this file. I could do that anyways if we did think it was likely that we wanted to add that prop anytime soon.
This is added by plotly so we need to remove it anyways. I think we could theme this if we wanted to some day as well.

Copy link

github-actions bot commented Mar 5, 2025

plotly-express docs preview (Available for 14 days)

Copy link

github-actions bot commented Mar 5, 2025

plotly-express docs preview (Available for 14 days)

Copy link

github-actions bot commented Mar 6, 2025

plotly-express docs preview (Available for 14 days)

Copy link

github-actions bot commented Mar 6, 2025

plotly-express docs preview (Available for 14 days)

Copy link

github-actions bot commented Mar 6, 2025

plotly-express docs preview (Available for 14 days)

@jnumainville jnumainville requested a review from mattrunyon March 7, 2025 17:57
Copy link
Collaborator

@mattrunyon mattrunyon left a comment

Choose a reason for hiding this comment

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

I think there is an issue with the git history on this branch or you committed something to this branch that was meant for another

@@ -285,6 +287,28 @@ describe('PlotlyExpressChartModel', () => {
expect(mockSubscribe).toHaveBeenCalledTimes(0);
});

it('should swap replaceable WebGL traces without blocker events if WebGL is not supported', async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this test supposed to be on another branch? Seems unrelated to this PR

Copy link
Collaborator Author

@jnumainville jnumainville Mar 7, 2025

Choose a reason for hiding this comment

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

Ah my bad I meant to comment about that. I added the scatter e2e test but that was broken because webgl doesn't work in firefox headless mode. So all this seemingly unrelated code is to fix that (as well as the general case when webgl doesn't work).

Comment on lines +242 to +246
setWebGlTraceType(
this.plotlyData,
webgl && this.isWebGlSupported,
this.webGlTraceIndices
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same question about why there's webgl stuff in this PR

*
* @returns True if Web GL is supported, false otherwise
*/
export function isWebGLSupported(): boolean {
Copy link
Collaborator

Choose a reason for hiding this comment

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

webgl

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