feat: 修复外部指针文字不跟随指针旋转的问题
This commit is contained in:
parent
be8e703fe4
commit
fccd90d176
2
dist/sv.js
vendored
2
dist/sv.js
vendored
File diff suppressed because one or more lines are too long
@ -189,7 +189,6 @@ export class ModelConstructor {
|
|||||||
pointerNames = Object.keys(pointerOptions);
|
pointerNames = Object.keys(pointerOptions);
|
||||||
|
|
||||||
pointerNames.forEach(name => {
|
pointerNames.forEach(name => {
|
||||||
|
|
||||||
for(let i = 0; i < elements.length; i++) {
|
for(let i = 0; i < elements.length; i++) {
|
||||||
let element = elements[i],
|
let element = elements[i],
|
||||||
pointerData = element[name];
|
pointerData = element[name];
|
||||||
|
|||||||
@ -106,10 +106,6 @@ export class Model {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.props[attr] === undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this.props[attr] === value) {
|
if(this.props[attr] === value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -129,7 +125,8 @@ export class Model {
|
|||||||
const matrix = Util.calcRotateMatrix(this.getMatrix(), value);
|
const matrix = Util.calcRotateMatrix(this.getMatrix(), value);
|
||||||
this.set('style', { matrix });
|
this.set('style', { matrix });
|
||||||
}
|
}
|
||||||
else if(attr === 'x' || attr === 'y') {
|
|
||||||
|
if(attr === 'x' || attr === 'y') {
|
||||||
this.G6Item.updatePosition({
|
this.G6Item.updatePosition({
|
||||||
[attr]: value
|
[attr]: value
|
||||||
});
|
});
|
||||||
@ -202,7 +199,7 @@ export class Element extends Model {
|
|||||||
y: 0,
|
y: 0,
|
||||||
rotation: option.rotation || 0,
|
rotation: option.rotation || 0,
|
||||||
type: option.type,
|
type: option.type,
|
||||||
size: option.size,
|
size: option.size || [60, 30],
|
||||||
anchorPoints: option.anchorPoints,
|
anchorPoints: option.anchorPoints,
|
||||||
label: option.label,
|
label: option.label,
|
||||||
style: Util.objectClone<Style>(option.style),
|
style: Util.objectClone<Style>(option.style),
|
||||||
@ -280,7 +277,7 @@ export class Pointer extends Model {
|
|||||||
y: 0,
|
y: 0,
|
||||||
rotation: 0,
|
rotation: 0,
|
||||||
type: option.type || 'external-pointer',
|
type: option.type || 'external-pointer',
|
||||||
size: option.size,
|
size: option.size || [8, 45],
|
||||||
anchorPoints: option.anchorPoints,
|
anchorPoints: option.anchorPoints,
|
||||||
label: typeof this.label === 'string'? this.label: this.label.join(', '),
|
label: typeof this.label === 'string'? this.label: this.label.join(', '),
|
||||||
style: Util.objectClone<Style>(option.style),
|
style: Util.objectClone<Style>(option.style),
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import * as G6 from "./../Lib/g6.js";
|
|||||||
|
|
||||||
export default G6.registerNode('binary-tree-node', {
|
export default G6.registerNode('binary-tree-node', {
|
||||||
draw(cfg, group) {
|
draw(cfg, group) {
|
||||||
cfg.size = cfg.size || [60, 30];
|
cfg.size = cfg.size;
|
||||||
|
|
||||||
const width = cfg.size[0],
|
const width = cfg.size[0],
|
||||||
height = cfg.size[1];
|
height = cfg.size[1];
|
||||||
|
|||||||
@ -3,8 +3,6 @@ import * as G6 from "./../Lib/g6.js";
|
|||||||
|
|
||||||
export default G6.registerNode('external-pointer', {
|
export default G6.registerNode('external-pointer', {
|
||||||
draw(cfg, group) {
|
draw(cfg, group) {
|
||||||
cfg.size = cfg.size || [8, 35];
|
|
||||||
|
|
||||||
const keyShape = group.addShape('path', {
|
const keyShape = group.addShape('path', {
|
||||||
attrs: {
|
attrs: {
|
||||||
path: this.getPath(cfg),
|
path: this.getPath(cfg),
|
||||||
@ -16,18 +14,34 @@ export default G6.registerNode('external-pointer', {
|
|||||||
|
|
||||||
if (cfg.label) {
|
if (cfg.label) {
|
||||||
const style = (cfg.labelCfg && cfg.labelCfg.style) || {};
|
const style = (cfg.labelCfg && cfg.labelCfg.style) || {};
|
||||||
group.addShape('text', {
|
const text = group.addShape('text', {
|
||||||
attrs: {
|
attrs: {
|
||||||
x: cfg.size[0] + 2, // 居中
|
x: 0,
|
||||||
y: -cfg.size[1],
|
y: 0,
|
||||||
textAlign: 'left',
|
textAlign: 'left',
|
||||||
textBaseline: 'middle',
|
textBaseline: 'middle',
|
||||||
text: cfg.label,
|
text: cfg.label,
|
||||||
fill: style.fill || '#000',
|
fill: style.fill || '#000',
|
||||||
fontSize: style.fontSize || 16
|
fontSize: style.fontSize || 16,
|
||||||
|
stroke: '#fff',
|
||||||
|
lineWidth: 6
|
||||||
},
|
},
|
||||||
name: 'pointer-text-shape'
|
name: 'pointer-text-shape'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { width: textWidth } = text.getBBox();
|
||||||
|
|
||||||
|
// 旋转文字
|
||||||
|
const pointerEndPosition = cfg.pointerEndPosition;
|
||||||
|
if(pointerEndPosition) {
|
||||||
|
let textX = pointerEndPosition[0] - textWidth / 2,
|
||||||
|
textY = pointerEndPosition[1];
|
||||||
|
|
||||||
|
text.attr({
|
||||||
|
x: textX,
|
||||||
|
y: textY
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return keyShape;
|
return keyShape;
|
||||||
@ -51,5 +65,5 @@ export default G6.registerNode('external-pointer', {
|
|||||||
];
|
];
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
@ -45,21 +45,34 @@ export class Layouter {
|
|||||||
targetBound: BoundingRect = target.getBound(),
|
targetBound: BoundingRect = target.getBound(),
|
||||||
anchorPosition = item.target.G6Item.getAnchorPoints()[anchor],
|
anchorPosition = item.target.G6Item.getAnchorPoints()[anchor],
|
||||||
center: [number, number] = [targetBound.x + targetBound.width / 2, targetBound.y + targetBound.height / 2],
|
center: [number, number] = [targetBound.x + targetBound.width / 2, targetBound.y + targetBound.height / 2],
|
||||||
pointerPosition: [number, number];
|
pointerPosition: [number, number],
|
||||||
|
pointerEndPosition: [number, number];
|
||||||
|
|
||||||
anchorPosition = [anchorPosition.x, anchorPosition.y];
|
anchorPosition = [anchorPosition.x, anchorPosition.y];
|
||||||
|
|
||||||
let anchorVector = Vector.subtract(anchorPosition, center),
|
let anchorVector = Vector.subtract(anchorPosition, center),
|
||||||
angle = anchorVector[0] === 0? 0: (Math.PI / 2 - Math.atan(anchorVector[1] / anchorVector[0])),
|
angle = 0,
|
||||||
len = Vector.length(anchorVector) + offset;
|
len = Vector.length(anchorVector) + offset;
|
||||||
|
|
||||||
|
if(anchorVector[0] === 0) {
|
||||||
|
angle = anchorVector[1] > 0? -Math.PI: 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
angle = Math.sign(anchorVector[0]) * (Math.PI / 2 - Math.atan(anchorVector[1] / anchorVector[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
const pointerHeight = item.get('size')[1];
|
||||||
|
|
||||||
anchorVector = Vector.normalize(anchorVector);
|
anchorVector = Vector.normalize(anchorVector);
|
||||||
pointerPosition = Vector.location(center, anchorVector, len);
|
pointerPosition = Vector.location(center, anchorVector, len);
|
||||||
|
pointerEndPosition = Vector.location(center, anchorVector, pointerHeight + len);
|
||||||
|
pointerEndPosition = Vector.subtract(pointerEndPosition, pointerPosition);
|
||||||
|
|
||||||
item.set({
|
item.set({
|
||||||
x: pointerPosition[0],
|
x: pointerPosition[0],
|
||||||
y: pointerPosition[1],
|
y: pointerPosition[1],
|
||||||
rotation: Math.sign(anchorVector[0]) * angle
|
rotation: angle,
|
||||||
|
pointerEndPosition
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -171,9 +184,9 @@ export class Layouter {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const modelGroupList: Group[] = this.layoutModels(layoutGroupTable),
|
const modelGroupList: Group[] = this.layoutModels(layoutGroupTable);
|
||||||
wrapperGroup: Group = this.layoutGroups(container, modelGroupList);
|
|
||||||
|
|
||||||
|
const wrapperGroup: Group = this.layoutGroups(container, modelGroupList);
|
||||||
this.fitCenter(container, wrapperGroup);
|
this.fitCenter(container, wrapperGroup);
|
||||||
|
|
||||||
layoutGroupTable.forEach(item => {
|
layoutGroupTable.forEach(item => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user