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

feat: poptip suppport multiline text, closed #1444 #1450

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vrender-core",
"comment": "feat: poptip suppport multiline text, closed #1444",
"type": "none"
}
],
"packageName": "@visactor/vrender-core"
}
14 changes: 10 additions & 4 deletions packages/vrender-core/src/graphic/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,20 @@ export class Text extends Graphic<ITextGraphicAttribute> implements IText {
get cliped(): boolean | undefined {
const textTheme = this.getGraphicTheme();
const attribute = this.attribute;
if (this.isMultiLine) {
return undefined;
}
const { maxLineWidth = textTheme.maxLineWidth } = attribute;
const { maxLineWidth = textTheme.maxLineWidth, text, whiteSpace = textTheme.whiteSpace } = attribute;
if (!Number.isFinite(maxLineWidth)) {
return false;
}
this.tryUpdateAABBBounds();
if (this.cache.layoutData.lines) {
let mergedText = '';
this.cache.layoutData.lines.forEach(item => {
mergedText += item.str;
});
const originText = Array.isArray(text) ? text.join('') : text;

return originText !== mergedText;
}
if (attribute.direction === 'vertical' && this.cache.verticalList && this.cache.verticalList[0]) {
return this.cache.verticalList[0].map(item => item.text).join('') !== attribute.text.toString();
}
Expand Down
5 changes: 4 additions & 1 deletion packages/vrender/__tests__/browser/src/pages/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,15 @@ export const page = () => {
// },
// background: 'red',
// backgroundCornerRadius: 10,
text: '这是一行文字',
text: ['这是一行文字', '这是第二哈那个'],
fill: 'red',
maxLineWidth: 100,
whiteSpace: 'normal',
fontSize: 36,
textBaseline: 'top'
})
);
console.log('aaa', graphics[graphics.length - 1]);
graphics.push(
createLine({
x: 300,
Expand Down
Loading