自定义HTML节点无法调整锚点 #1471
-
在自定义html节点后想要调整锚点,但是用getAnchorStyle函数没办法调整,甚至不执行,有什么办法设置自定义html节点的锚点么 |
Beta Was this translation helpful? Give feedback.
Answered by
EdwinOlders11
Oct 23, 2024
Replies: 1 comment
-
你需要重写_getDefaultAnchor_而不是_getAnchorStyle_,前者才是改变锚点最基础属性的,比如位置和数量,后者仅仅是样式 class newmodel extends Core.HtmlNodeModel {
initNodeData(data) { ..... }
getDefaultAnchor() { //设置锚点的位置、数量、类型和其他基础属性
const { width, height, x, y, id } = this;
var newAnchor = [];
newAnchor.push({
x: x - width / 2,
y: height / 2 + 30 + p * 30 + 15,
type: "left",
id: `${id}_in${p}`,
})
newAnchor.push({
x: x + width / 2,
y: y - height / 2 + 15,
type: "right",
id: `${id}_out${p}`,
})
return newAnchor;
}
getAnchorStyle(anchorInfo) { //设置颜色、粗细和线形等
const style = super.getAnchorStyle(anchorInfo);
if (anchorInfo.type == 'left') {
style.stroke = "rgb(150,150,150)"
} else if (anchorInfo.type == 'right') {
style.stroke = "rgb(150,150,150)"
}
return style;
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
boyongjiong
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
你需要重写_getDefaultAnchor_而不是_getAnchorStyle_,前者才是改变锚点最基础属性的,比如位置和数量,后者仅仅是样式