Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow padding function 2 #887

Merged
merged 3 commits into from
Feb 11, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ export function findBestPlacement(

function approxTextBounds(label, textMetrics, rotated, rect, padding = {}) {
const { top = PADDING, bottom = PADDING, left = PADDING, right = PADDING } = padding;
const leftPadding = typeof left === 'function' ? left(textMetrics) : left;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the same padding properties as you added and documented in your previous PR, right? So there is no need for adding anything new in the api specs if I understand correct.

Could you adjust the testcase you added in. the last pr to also validate these bounds gets calculated using the functions?

const rightPadding = typeof right === 'function' ? right(textMetrics) : right;
const topPadding = typeof top === 'function' ? top(textMetrics) : top;
const bottomPadding = typeof bottom === 'function' ? bottom(textMetrics) : bottom;
const x0 = label.x + label.dx;
const y0 = label.y + label.dy;
const height = rotated ? Math.min(textMetrics.width, rect.height) : Math.min(textMetrics.height, rect.width);
Expand All @@ -218,10 +222,10 @@ function approxTextBounds(label, textMetrics, rotated, rect, padding = {}) {
const x = rotated ? x0 - offset : x0;
const y = rotated ? y0 : y0 - offset;
const bounds = {
x: x - left - PADDING_OFFSET,
y: y - top - PADDING_OFFSET,
width: width + (left + right) - PADDING_OFFSET,
height: height + (top + bottom) - PADDING_OFFSET,
x: x - leftPadding - PADDING_OFFSET,
y: y - topPadding - PADDING_OFFSET,
width: width + (leftPadding + rightPadding) - PADDING_OFFSET,
height: height + (topPadding + bottomPadding) - PADDING_OFFSET,
};
return bounds;
}
Expand Down
Loading