Skip to content

Commit

Permalink
[FIX] FiguresContainer: chart resizing broken
Browse files Browse the repository at this point in the history
Previously, the chart resizing didn't work properly when the viewport
was scrolled and only part of the figure was visible.

This commit addresses the issue by enhancing the condition to check if
the figure extends beyond the header boundaries. Now, this condition
also considers scrolling, ensuring proper chart resizing.

Task ID: 3752060

closes #3824

X-original-commit: e87e56c
Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
Signed-off-by: Dhrutik Patel (dhrp) <dhrp@odoo.com>
  • Loading branch information
dhrp-odoo committed Mar 13, 2024
1 parent fb4c580 commit 3d5b815
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/components/figures/figure_container/figure_container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ export class FiguresContainer extends Component<Props, SpreadsheetChildEnv> {
currentMousePosition,
initialMousePosition,
keepRatio,
minFigSize
minFigSize,
this.env.model.getters.getActiveSheetScrollInfo()
);

const otherFigures = this.getOtherFigures(figure.id);
Expand Down
17 changes: 9 additions & 8 deletions src/components/helpers/figure_drag_helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export function dragFigureForResize(
{ x: mouseX, y: mouseY }: PixelPosition,
{ x: mouseInitialX, y: mouseInitialY }: PixelPosition,
keepRatio: boolean,
minFigSize: number
minFigSize: number,
{ scrollX, scrollY }: SheetScrollInfo
): Figure {
let { x, y, width, height } = initialFigure;

Expand Down Expand Up @@ -58,14 +59,14 @@ export function dragFigureForResize(
}
}

// Restrict resizing if x or y reaches header boundaries
if (x < 0) {
width += x;
x = 0;
// Adjusts figure dimensions to ensure it remains within header boundaries and viewport during resizing.
if (x + scrollX <= 0) {
width = width + x + scrollX;
x = -scrollX;
}
if (y < 0) {
height += y;
y = 0;
if (y + scrollY <= 0) {
height = height + y + scrollY;
y = -scrollY;
}

return { ...initialFigure, x, y, width, height };
Expand Down
23 changes: 23 additions & 0 deletions tests/components/figure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,29 @@ describe("figures", () => {
}
);

test.each([
["right", { mouseOffsetX: 300, mouseOffsetY: 0 }],
["bottom", { mouseOffsetX: 0, mouseOffsetY: 300 }],
["bottomRight", { mouseOffsetX: 300, mouseOffsetY: 300 }],
])(
"Resizing a figure does not crop it to its visible part in the viewport",
async (anchor: string, mouseMove: { mouseOffsetX: number; mouseOffsetY: number }) => {
const figureId = "someuuid";
const figure = { width: 200, height: 200 };
createFigure(model, { id: figureId, y: 0, x: 0, ...figure });
await nextTick();
setViewportOffset(model, 100, 100);
await simulateClick(".o-figure");
await dragAnchor(anchor, mouseMove.mouseOffsetX, mouseMove.mouseOffsetY, true);
const updatedFigure = {
...figure,
width: figure.width + mouseMove.mouseOffsetX,
height: figure.height + mouseMove.mouseOffsetY,
};
expect(model.getters.getFigure(sheetId, figureId)).toMatchObject(updatedFigure);
}
);

describe("Move a figure with drag & drop ", () => {
test("Can move a figure with drag & drop", async () => {
createFigure(model, { id: "someuuid", x: 200, y: 100 });
Expand Down

0 comments on commit 3d5b815

Please sign in to comment.