Skip to content

Commit

Permalink
fix: label background word wrap width (#6055)
Browse files Browse the repository at this point in the history
* fix: label background 折行宽度修改

* feat: 更新label-oversized 测试demo和截图

---------

Co-authored-by: xwb163631 <xwb163631@gongdao.com>
  • Loading branch information
xuwb and xwb163631 committed Jul 18, 2024
1 parent 3f775f9 commit f72d4c2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
5 changes: 3 additions & 2 deletions packages/g6/__tests__/demos/element-label-oversized.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const elementLabelOversized: TestCase = async (context) => {
data: {
x: 100,
y: 150,
label: `This label is too long to be displayed`,
label: `This label with padding is too long to be displayed`,
size: 100,
},
},
Expand All @@ -17,7 +17,7 @@ export const elementLabelOversized: TestCase = async (context) => {
data: {
x: 400,
y: 150,
label: 'This label is too long to be displayed',
label: 'This label with padding is too long to be displayed',
size: 150,
},
},
Expand Down Expand Up @@ -50,6 +50,7 @@ export const elementLabelOversized: TestCase = async (context) => {
labelBackgroundFill: '#eee',
labelBackgroundFillOpacity: 0.5,
labelBackgroundRadius: 4,
labelPadding: [0, 10, 0, 10],
labelWordWrap: true,
labelMaxLines: 4,
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/g6/src/elements/shapes/label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class Label extends BaseShape<LabelStyleProps> {
Object.assign(backgroundStyle, {
x: minX - left,
y: minY - top,
width: wordWrap ? Math.min(totalWidth, wordWrapWidth) : totalWidth,
width: wordWrap ? Math.min(totalWidth, wordWrapWidth + left + right) : totalWidth,
height: halfHeight * 2 + top + bottom,
});
}
Expand Down

0 comments on commit f72d4c2

Please sign in to comment.