Skip to content

Force scale ratio if x and y axis have same unit for 1D and 2D plots#80

Open
mfiaudrin-epsyl wants to merge 4 commits into
iterorganization:developfrom
mfiaudrin-epsyl:feature/scale_ratio
Open

Force scale ratio if x and y axis have same unit for 1D and 2D plots#80
mfiaudrin-epsyl wants to merge 4 commits into
iterorganization:developfrom
mfiaudrin-epsyl:feature/scale_ratio

Conversation

@mfiaudrin-epsyl

@mfiaudrin-epsyl mfiaudrin-epsyl commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

This feature add a rule to display the plots with the the same ratio between x & y axis if they have the same unit.

It also Closes #71

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds automatic 1:1 axis scaling for 1D and 2D plots when the relevant axes share the same unit, improving visual comparability for same-unit data.

Changes:

  • SimplePlotly: compute a shouldForceRatio rule and apply Plotly xaxis.scaleanchor/scaleratio accordingly.
  • Heatmap2D: compute a similar shouldForceRatio rule from coordinate units and apply the same Plotly layout constraint.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
frontend/src/renderer/components/plot/SimplePlotly.tsx Adds a same-unit detection rule and conditionally anchors x/y scaling via Plotly layout.
frontend/src/renderer/components/plot/Heatmap2D.tsx Adds a coordinate-unit equality rule and conditionally anchors x/y scaling via Plotly layout.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread frontend/src/renderer/components/plot/SimplePlotly.tsx Outdated
Comment thread frontend/src/renderer/components/plot/SimplePlotly.tsx
Comment thread frontend/src/renderer/components/plot/Heatmap2D.tsx Outdated
Comment thread frontend/src/renderer/components/plot/Heatmap2D.tsx
@olivhoenen

Copy link
Copy Markdown
Contributor

Errors encountered when testing this PR are described in #84 (it also affects the develop branch).

Otherwise the square ratio feature works as expected. From our last discussion with the group and @imbeauf, we mentioned that ideally there would be a customization option to allow the user to disable the fixed ratio (fix ratio is good as the default behavior), as well as to enable fixed ratio even if units are not the same in x and y.

@mfiaudrin-epsyl

Copy link
Copy Markdown
Collaborator Author

I hadn't planned on including ratio customization in this PR, but I've made good progress on the geometry overlay feature, so I'll add it to this PR. I'm marking it as DRAFT until it's implemented.

@mfiaudrin-epsyl mfiaudrin-epsyl marked this pull request as draft June 8, 2026 08:01
@mfiaudrin-epsyl mfiaudrin-epsyl marked this pull request as ready for review June 8, 2026 14:16
@mfiaudrin-epsyl

Copy link
Copy Markdown
Collaborator Author

@olivhoenen I've just added the axis ratios rule in visual customization / global.

Copilot's comments were also taken into account.

The PR is ready for review.

isTitleOverwritten: boolean;
displayErrorBand: boolean;
displayGrid: boolean;
xyRatioRule: 'Auto' | 'None' | 'Force';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Drop-down menu with these 3 options does not feel like the most friendly UI.
A simple boolean would be preferred here in the customization its square ratio or not. Auto shall just correspond of the value of this boolean while plotting the data for the first time.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As during our discussion this morning it was raised that these three modes were present because they apply also in 1D plots and when we switch back and forth between 2D and 1D, maybe we can simplify and only have this costumisation option for 2D plots?

That way this option has no effect on 1D plots, where fixed ratio between x and y ticks is less of an issue.
The initial value of this boolean is decided with the first plot (if units are the same then it toggles fixed ratio for 2D) and latter impact further 2D plots in the same figure until the user customize the plot. On the other hand, if a first 2D plot has different units (like [s] vs [m]) then fixed ratio won't be forced in the figure, and could later be custonized by user.

If this (default value of the boolean depending on units of the first 2D plot in the figure) we can also decide to simplify and set a static default value (e.g. fixed ratio, so spatial planes will look nicer) and let the user unselect the option if she/he wants a plot that covers the entire figure.

For further reference and additional context, please see how this is handled in h5view with this small video:

myhdf5-ratio-2026-06-12_11.36.57.mp4

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thank you for your the proposed solution. I agree that if we apply the square ratio only for 2D plots, it will simplify the use of a boolean instead.

We just need to improve the solution to be compatible with the feature allowing to change of axis. In this case, units of x & y axis can change. So I am wondering what we should do.

I see 2 possibilities:

  1. When adding a new dataGrid, we initialise the square ratio boolean (true or false depending x & y units). No matter if we change of axis later, we will keep the square ratio as it was at the initialisation
  2. Or we update the square ratio boolean each time we update axis. So, in case the user has forced to keep ratio to true for instance, it will overwrite the keep ratio value by applying the unit rule each time we change of axis

Which one do you think will be the most appropriate for the users ?

From my point of view, I think the second option will be better because by changing axis, we always ensure the user have the expected ratio for visualisation. And then, it's up to him to update the ratio.

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.

Allow editing the x/y-axis titles in plot customization

3 participants