Feat:支持扩展节点形状
This commit is contained in:
parent
866287402f
commit
1b7aad3de2
@ -82,6 +82,22 @@ class MindMap {
|
|||||||
// 该检查可以通过customCheckEnableShortcut选项来覆盖
|
// 该检查可以通过customCheckEnableShortcut选项来覆盖
|
||||||
this.editNodeClassList = []
|
this.editNodeClassList = []
|
||||||
|
|
||||||
|
// 扩展的节点形状列表
|
||||||
|
/*
|
||||||
|
{
|
||||||
|
createShape: (node) => {
|
||||||
|
return path
|
||||||
|
},
|
||||||
|
getPadding: ({ node, width, height, paddingX, paddingY }) => {
|
||||||
|
return {
|
||||||
|
paddingX: 0,
|
||||||
|
paddingY: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
this.extendShapeList = []
|
||||||
|
|
||||||
// 画布
|
// 画布
|
||||||
this.initContainer()
|
this.initContainer()
|
||||||
|
|
||||||
@ -675,6 +691,26 @@ class MindMap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 扩展节点形状
|
||||||
|
addShape(shape) {
|
||||||
|
if (!shape) return
|
||||||
|
const exist = this.extendShapeList.find(item => {
|
||||||
|
return item.name === shape.name
|
||||||
|
})
|
||||||
|
if (exist) return
|
||||||
|
this.extendShapeList.push(shape)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除扩展的形状
|
||||||
|
removeShape(name) {
|
||||||
|
const index = this.extendShapeList.findIndex(item => {
|
||||||
|
return item.name === name
|
||||||
|
})
|
||||||
|
if (index !== -1) {
|
||||||
|
this.extendShapeList.splice(index, 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 添加插件
|
// 添加插件
|
||||||
addPlugin(plugin, opt) {
|
addPlugin(plugin, opt) {
|
||||||
let index = MindMap.hasPlugin(plugin)
|
let index = MindMap.hasPlugin(plugin)
|
||||||
|
|||||||
@ -52,14 +52,36 @@ export default class Shape {
|
|||||||
paddingX: actHeight > actWidth ? actOffset / 2 : 0,
|
paddingX: actHeight > actWidth ? actOffset / 2 : 0,
|
||||||
paddingY: actHeight < actWidth ? actOffset / 2 : 0
|
paddingY: actHeight < actWidth ? actOffset / 2 : 0
|
||||||
}
|
}
|
||||||
default:
|
}
|
||||||
return {
|
const extendShape = this.getShapeFromExtendList(shape)
|
||||||
|
if (extendShape) {
|
||||||
|
return (
|
||||||
|
extendShape.getPadding({
|
||||||
|
node: this.node,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
paddingX,
|
||||||
|
paddingY
|
||||||
|
}) || {
|
||||||
paddingX: 0,
|
paddingX: 0,
|
||||||
paddingY: 0
|
paddingY: 0
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
paddingX: 0,
|
||||||
|
paddingY: 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 从形状扩展列表里获取指定名称的形状
|
||||||
|
getShapeFromExtendList(shape) {
|
||||||
|
return this.mindMap.extendShapeList.find(item => {
|
||||||
|
return item.name === shape
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// 创建形状节点
|
// 创建形状节点
|
||||||
createShape() {
|
createShape() {
|
||||||
const shape = this.node.getShape()
|
const shape = this.node.getShape()
|
||||||
@ -92,6 +114,12 @@ export default class Shape {
|
|||||||
// 圆
|
// 圆
|
||||||
node = this.createCircle()
|
node = this.createCircle()
|
||||||
}
|
}
|
||||||
|
if (!node) {
|
||||||
|
const extendShape = this.getShapeFromExtendList(shape)
|
||||||
|
if (extendShape) {
|
||||||
|
node = extendShape.createShape(this.node)
|
||||||
|
}
|
||||||
|
}
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user