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 1 commit 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 1 commit into
iterorganization:developfrom
mfiaudrin-epsyl:feature/scale_ratio

Conversation

@mfiaudrin-epsyl
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.

Copy link
Copy Markdown

Copilot AI left a comment

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 on lines +126 to +136
useEffect(() => {
const coordinateUnit = itemDataGrid.coordinates.find(
(c) => c.axeIndex === 0,
)?.unit;
const allPlotsHaveSameUnit = itemDataGrid.plot.every(
(plot) => plot.unit === itemDataGrid.plot[0]?.unit,
);
setShouldForceRatio(
allPlotsHaveSameUnit && coordinateUnit === itemDataGrid.plot[0]?.unit,
);
}, [itemDataGrid.coordinates]);
Comment on lines +138 to +140
/**
* Update layout to force ratio are not
*/
Comment on lines +96 to +104
useEffect(() => {
const firstCoordinateUnit = itemDataGrid.coordinates.find(
(c) => c.axeIndex === 0,
)?.unit;
const secondCoordinateUnit = itemDataGrid.coordinates.find(
(c) => c.axeIndex === 1,
)?.unit;
setShouldForceRatio(firstCoordinateUnit === secondCoordinateUnit);
}, [itemDataGrid.coordinates]);
Comment on lines +106 to +108
/**
* Update layout to force ratio are not
*/
@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.

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.

3 participants