Skip to content

Commit

Permalink
fix(label): 移除 _name 属性,直接使用 type 类型判断获取 labelShape
Browse files Browse the repository at this point in the history
  • Loading branch information
simaQ committed Mar 19, 2020
1 parent 9dc7572 commit b2b8cca
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/component/labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ export default class Labels {

translate(content, x, y); // 将 label 平移至 x, y 指定的位置
labelShape = content;
content.set('_name', 'labelContent');
labelGroup.add(content);
} else {
labelShape = labelGroup.addShape('text', {
Expand All @@ -201,7 +200,6 @@ export default class Labels {
...cfg.style,
},
...shapeAppendCfg,
_name: 'labelContent',
});
}

Expand Down Expand Up @@ -282,12 +280,14 @@ export default class Labels {
const id = item.id;
const labelGroup = this.shapesMap[id];
if (!labelGroup.destroyed) {
const labelShape = labelGroup.find(ele => ele.get('_name') === 'labelContent');
if (item.offsetX) {
labelShape.attr('x', labelShape.attr('x') + item.offsetX);
}
if (item.offsetY) {
labelShape.attr('y', labelShape.attr('y') + item.offsetY);
const labelShape = labelGroup.find(ele => ele.get('type') === 'text');
if (labelShape) {
if (item.offsetX) {
labelShape.attr('x', labelShape.attr('x') + item.offsetX);
}
if (item.offsetY) {
labelShape.attr('y', labelShape.attr('y') + item.offsetY);
}
}
}
}
Expand Down

0 comments on commit b2b8cca

Please sign in to comment.