Skip to content

Commit

Permalink
fix: overlapPadding not work in shiftY
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoluoHe committed Dec 20, 2024
1 parent 88c1c38 commit 4645df2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions packages/vrender-components/src/label/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ export class LabelBase<T extends BaseLabelAttrs> extends AbstractComponent<T> {
bitmap.setRange(range);
} else {
if (clampForce) {
const placedAfterClampForce = this._processClampForce(text as IText, bmpTool, bitmap);
const placedAfterClampForce = this._processClampForce(text as IText, bmpTool, bitmap, overlapPadding);
if (placedAfterClampForce) {
continue;
}
Expand All @@ -569,11 +569,11 @@ export class LabelBase<T extends BaseLabelAttrs> extends AbstractComponent<T> {
return result;
}

protected _processClampForce(text: IText, bmpTool: BitmapTool, bitmap: Bitmap) {
protected _processClampForce(text: IText, bmpTool: BitmapTool, bitmap: Bitmap, overlapPadding = 0) {
const { dy = 0, dx = 0 } = clampText(text as IText, bmpTool.width, bmpTool.height, bmpTool.padding);
if (dx === 0 && dy === 0) {
if (canPlace(bmpTool, bitmap, text.AABBBounds)) {
// xy方向偏移都为0,意味着不考虑 overlapPadding 时,实际上可以放得下
// 再次检查,若不考虑边界,仍然可以放得下,代表当前 text 没有与其他 text 重叠
if (canPlace(bmpTool, bitmap, text.AABBBounds, false, overlapPadding)) {
bitmap.setRange(boundToRange(bmpTool, text.AABBBounds, true));
return true;
}
Expand Down Expand Up @@ -689,7 +689,7 @@ export class LabelBase<T extends BaseLabelAttrs> extends AbstractComponent<T> {

// 尝试向内挤压
if (!hasPlace && clampForce) {
const placedAfterClampForce = this._processClampForce(text as IText, bmpTool, bitmap);
const placedAfterClampForce = this._processClampForce(text as IText, bmpTool, bitmap, overlapPadding);
if (placedAfterClampForce) {
result.push(text);
continue;
Expand Down
12 changes: 6 additions & 6 deletions packages/vrender-components/src/label/overlap/place.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,17 @@ export function clampText(
let dy = 0;

// x 方向
if (minX < minXWithPadding && maxX - minX <= width) {
if (minX < minXWithPadding) {
dx = -minX;
} else if (maxX > maxXWithPadding && minX - (maxX - width) >= minXWithPadding) {
dx = width - maxX;
} else if (maxX > maxXWithPadding) {
dx = maxXWithPadding - maxX;
}

// y 方向
if (minY < minYWithPadding && maxY - minY <= height) {
if (minY < minYWithPadding) {
dy = -minY;
} else if (maxY > maxYWithPadding && minY - (maxY - height) >= minYWithPadding) {
dy = height - maxY;
} else if (maxY > maxYWithPadding) {
dy = maxYWithPadding - maxY;
}

return { dx, dy };
Expand Down

0 comments on commit 4645df2

Please sign in to comment.