Skip to content

Commit

Permalink
fix: mark position calculation when only x or y are defined (#974)
Browse files Browse the repository at this point in the history
  • Loading branch information
marshallpete authored Nov 16, 2024
1 parent ae1ec95 commit 795bd70
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,8 @@ export function getMarkBounds(
let parentItem = item;
while (parentItem.mark.group) {
parentItem = parentItem.mark.group;
if ('x' in parentItem && 'y' in parentItem) {
left += parentItem.x;
top += parentItem.y;
}
left += parentItem.x ?? 0;
top += parentItem.y ?? 0;
}

const markWidth = markBounds.x2 - markBounds.x1;
Expand Down
4 changes: 4 additions & 0 deletions test/position.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ describe('getMarkBounds()', () => {
expect(getMarkBounds({left: 0, top: 0}, [0, 0], defaultItem)).toEqual({x1: 150, x2: 200, y1: 75, y2: 125});
expect(getMarkBounds({left: 0, top: 0}, [0, 0], item)).toEqual({x1: 190, x2: 240, y1: 135, y2: 185});
});
test('should sum the offsets even if only x is defined', () => {
const item = {...defaultItem, mark: {group: {x: 10, mark: {group: {x: 30, mark: {}}}}}};
expect(getMarkBounds({left: 0, top: 0}, [0, 0], item)).toEqual({x1: 190, x2: 240, y1: 75, y2: 125});
});
});

describe('getPositions()', () => {
Expand Down

0 comments on commit 795bd70

Please sign in to comment.