Skip to content

Commit

Permalink
Merge pull request #226 from Jeffy2012/fix-title-wrap-bug
Browse files Browse the repository at this point in the history
fix: 修复标题和description换行的bug
  • Loading branch information
paleface001 committed Nov 15, 2019
2 parents eab8ceb + 57911f6 commit f33ba0a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions __tests__/unit/title-desc-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe('title description', () => {
const view = plot.getLayer() as LineLayer;
expect(view.description).not.toBe(null);
expect(view.description.shape.attrs.text)
.toBe(`我们经过大量的项目实践和经验总结,总结了以下四条核心原则,并以重要等级进行排序,
条原则相辅相成且呈递进关系,希望你在设计时也可以采纳。`);
.toBe(`我们经过大量的项目实践和经验总结,总结了以下四条核心原则,并以重要等级进行排序,四条原则相辅
相成且呈递进关系,希望你在设计时也可以采纳。`);
});
});
5 changes: 2 additions & 3 deletions src/components/description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ export default class TextDescription {
const breakIndex: number[] = [];
for (let i = 0; i < chars.length; i++) {
const item = chars[i];
// 注意: 后面每个char后面需要添加一个空格
tShape.attr('text', (text += `${item} `));
const currentWidth = Math.floor(tShape.measureText());
tShape.attr('text', (text += item));
const currentWidth = tShape.getBBox().width - 1;
if (currentWidth > width) {
// 如果是第一个字符就大于宽度不做任何换行处理
if (i === 0) {
Expand Down

0 comments on commit f33ba0a

Please sign in to comment.