Skip to content

Commit 8785a63

Browse files
Topdev97anhe-odoo
andcommitted
[FIX] Figure container: Crop figures to avoid overlap with headers
The introduction of dashboard mode in a709ca18 mistakenly removed the cropping of figures when they overlap on headers. This commit fixes that issue. Task 2889602 closes odoo/o-spreadsheet#1451 Signed-off-by: Pierre Rousseau (pro) <pro@odoo.com> Co-authored-by: Anthony Hendrickx <anhe@odoo.com>
1 parent 14333d2 commit 8785a63

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/components/figures/container/container.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,20 @@ export class FiguresContainer extends Component<Props, SpreadsheetChildEnv> {
137137
let x = target.x - offsetX - 1;
138138
let y = target.y - offsetY - 1;
139139

140+
// width and height of wrapper need to be adjusted so we do not overlap
141+
// with headers
142+
const correctionX = this.env.isDashboard() ? 0 : Math.max(0, -x);
143+
x += correctionX;
144+
const correctionY = this.env.isDashboard() ? 0 : Math.max(0, -y);
145+
y += correctionY;
140146
if (width < 0 || height < 0) {
141147
return `position:absolute;display:none;`;
142148
}
143149
const offset =
144150
ANCHOR_SIZE + ACTIVE_BORDER_WIDTH + (isSelected ? ACTIVE_BORDER_WIDTH : BORDER_WIDTH);
145-
return `position:absolute; top:${y + 1}px; left:${x + 1}px; width:${width + offset}px; height:${
146-
height + offset
147-
}px`;
151+
return `position:absolute; top:${y + 1}px; left:${x + 1}px; width:${
152+
width - correctionX + offset
153+
}px; height:${height - correctionY + offset}px`;
148154
}
149155

150156
setup() {

tests/components/figure.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { App, Component, xml } from "@odoo/owl";
22
import { Model, Spreadsheet } from "../../src";
3+
import { DEFAULT_CELL_HEIGHT, DEFAULT_CELL_WIDTH } from "../../src/constants";
34
import { figureRegistry } from "../../src/registries";
45
import { CreateFigureCommand, Figure, SpreadsheetChildEnv, UID } from "../../src/types";
56
import {
@@ -202,4 +203,20 @@ describe("figures", () => {
202203
await nextTick();
203204
expect(figure.classList).not.toContain("o-dragging");
204205
});
206+
207+
test("Figures are cropped to avoid overlap with headers", async () => {
208+
const figureId = "someuuid";
209+
createFigure(model, { id: figureId, x: 100, y: 20, height: 200, width: 100 });
210+
await nextTick();
211+
const figure = fixture.querySelector(".o-figure-wrapper")!;
212+
expect(window.getComputedStyle(figure).width).toBe("111px"); // width + borders
213+
expect(window.getComputedStyle(figure).height).toBe("211px"); // height + borders
214+
model.dispatch("SET_VIEWPORT_OFFSET", {
215+
offsetX: 2 * DEFAULT_CELL_WIDTH,
216+
offsetY: 3 * DEFAULT_CELL_HEIGHT,
217+
});
218+
await nextTick();
219+
expect(window.getComputedStyle(figure).width).toBe("18px"); // width + borders - 2 * DEFAULT_CELL_WIDTH
220+
expect(window.getComputedStyle(figure).height).toBe("161px"); // height + offset - 2 * DEFAULT_CELL_WIDTH
221+
});
205222
});

0 commit comments

Comments
 (0)