|
@@ -3,7 +3,9 @@ import Hierarchy from '@antv/hierarchy'
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
|
-
|
|
|
+ mindMapDataCurrent:{},
|
|
|
+ positionCurrent:{},
|
|
|
+ addTypeCurrent:''
|
|
|
}
|
|
|
},
|
|
|
mounted() {
|
|
@@ -22,7 +24,11 @@ export default {
|
|
|
},
|
|
|
{
|
|
|
tagName: 'image',
|
|
|
- selector: 'img',
|
|
|
+ selector: 'leftImg',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ tagName: 'image',
|
|
|
+ selector: 'rightImg',
|
|
|
},
|
|
|
{
|
|
|
tagName: 'text',
|
|
@@ -39,7 +45,19 @@ export default {
|
|
|
width:100,
|
|
|
height:50
|
|
|
},
|
|
|
- img: {
|
|
|
+ leftImg: {
|
|
|
+ ref: 'body',
|
|
|
+ refX: -16,
|
|
|
+ refY: '50%',
|
|
|
+ refY2: -8,
|
|
|
+ width: 16,
|
|
|
+ height: 16,
|
|
|
+ 'xlink:href':
|
|
|
+ 'https://gw.alipayobjects.com/mdn/rms_43231b/afts/img/A*SYCuQ6HHs5cAAAAAAAAAAAAAARQnAQ',
|
|
|
+ event: 'add:topic:left',
|
|
|
+ class: 'left-topic-image',
|
|
|
+ },
|
|
|
+ rightImg: {
|
|
|
ref: 'body',
|
|
|
refX: '100%',
|
|
|
refY: '50%',
|
|
@@ -48,8 +66,8 @@ export default {
|
|
|
height: 16,
|
|
|
'xlink:href':
|
|
|
'https://gw.alipayobjects.com/mdn/rms_43231b/afts/img/A*SYCuQ6HHs5cAAAAAAAAAAAAAARQnAQ',
|
|
|
- event: 'add:topic',
|
|
|
- class: 'topic-image',
|
|
|
+ event: 'add:topic:right',
|
|
|
+ class: 'right-topic-image',
|
|
|
},
|
|
|
label: {
|
|
|
fontSize: 14,
|
|
@@ -62,10 +80,9 @@ export default {
|
|
|
},
|
|
|
true,
|
|
|
)
|
|
|
-
|
|
|
- // 分支主题
|
|
|
+ // 左分支主题
|
|
|
Graph.registerNode(
|
|
|
- 'mindmap-topic-child',
|
|
|
+ 'mindmap-topic-left',
|
|
|
{
|
|
|
inherit: 'rect',
|
|
|
markup: [
|
|
@@ -74,40 +91,152 @@ export default {
|
|
|
selector: 'body',
|
|
|
},
|
|
|
{
|
|
|
- tagName: 'text',
|
|
|
- selector: 'label',
|
|
|
+ tagName: 'image',
|
|
|
+ selector: 'leftImg',
|
|
|
},
|
|
|
{
|
|
|
- tagName: 'path',
|
|
|
- selector: 'line',
|
|
|
+ tagName: 'image',
|
|
|
+ selector: 'rightImg',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ tagName: 'text',
|
|
|
+ selector: 'label',
|
|
|
},
|
|
|
],
|
|
|
attrs: {
|
|
|
body: {
|
|
|
- fill: '#ffffff',
|
|
|
- strokeWidth: 0,
|
|
|
+ rx: 6,
|
|
|
+ ry: 6,
|
|
|
stroke: '#5F95FF',
|
|
|
+ fill: '#EFF4FF',
|
|
|
+ strokeWidth: 1,
|
|
|
+ width:100,
|
|
|
+ height:50
|
|
|
+ },
|
|
|
+ leftImg: {
|
|
|
+ ref: 'body',
|
|
|
+ refX: -16,
|
|
|
+ refY: '50%',
|
|
|
+ refY2: -8,
|
|
|
+ width: 16,
|
|
|
+ height: 16,
|
|
|
+ 'xlink:href':
|
|
|
+ 'https://gw.alipayobjects.com/mdn/rms_43231b/afts/img/A*SYCuQ6HHs5cAAAAAAAAAAAAAARQnAQ',
|
|
|
+ event: 'add:topic:left',
|
|
|
+ class: 'left-topic-image',
|
|
|
},
|
|
|
label: {
|
|
|
fontSize: 14,
|
|
|
fill: '#262626',
|
|
|
- textVerticalAnchor: 'bottom',
|
|
|
+ textWrap:{
|
|
|
+ width:-10
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ },
|
|
|
+ true,
|
|
|
+ )
|
|
|
+ // 右分支主题
|
|
|
+ Graph.registerNode(
|
|
|
+ 'mindmap-topic-right',
|
|
|
+ {
|
|
|
+ inherit: 'rect',
|
|
|
+ markup: [
|
|
|
+ {
|
|
|
+ tagName: 'rect',
|
|
|
+ selector: 'body',
|
|
|
},
|
|
|
- line: {
|
|
|
+ {
|
|
|
+ tagName: 'image',
|
|
|
+ selector: 'leftImg',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ tagName: 'image',
|
|
|
+ selector: 'rightImg',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ tagName: 'text',
|
|
|
+ selector: 'label',
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ attrs: {
|
|
|
+ body: {
|
|
|
+ rx: 6,
|
|
|
+ ry: 6,
|
|
|
stroke: '#5F95FF',
|
|
|
- strokeWidth: 2,
|
|
|
- d: 'M 0 15 L 60 15',
|
|
|
+ fill: '#EFF4FF',
|
|
|
+ strokeWidth: 1,
|
|
|
+ width:100,
|
|
|
+ height:50
|
|
|
},
|
|
|
+ rightImg: {
|
|
|
+ ref: 'body',
|
|
|
+ refX: '100%',
|
|
|
+ refY: '50%',
|
|
|
+ refY2: -8,
|
|
|
+ width: 16,
|
|
|
+ height: 16,
|
|
|
+ 'xlink:href':
|
|
|
+ 'https://gw.alipayobjects.com/mdn/rms_43231b/afts/img/A*SYCuQ6HHs5cAAAAAAAAAAAAAARQnAQ',
|
|
|
+ event: 'add:topic:right',
|
|
|
+ class: 'right-topic-image',
|
|
|
+ },
|
|
|
+ label: {
|
|
|
+ fontSize: 14,
|
|
|
+ fill: '#262626',
|
|
|
+ textWrap:{
|
|
|
+ width:-10
|
|
|
+ }
|
|
|
+ }
|
|
|
},
|
|
|
},
|
|
|
true,
|
|
|
)
|
|
|
+ // 分支主题
|
|
|
+ // Graph.registerNode(
|
|
|
+ // 'mindmap-topic-child',
|
|
|
+ // {
|
|
|
+ // inherit: 'rect',
|
|
|
+ // markup: [
|
|
|
+ // {
|
|
|
+ // tagName: 'rect',
|
|
|
+ // selector: 'body',
|
|
|
+ // },
|
|
|
+ // {
|
|
|
+ // tagName: 'text',
|
|
|
+ // selector: 'label',
|
|
|
+ // },
|
|
|
+ // {
|
|
|
+ // tagName: 'path',
|
|
|
+ // selector: 'line',
|
|
|
+ // },
|
|
|
+ // ],
|
|
|
+ // attrs: {
|
|
|
+ // body: {
|
|
|
+ // fill: '#ffffff',
|
|
|
+ // strokeWidth: 0,
|
|
|
+ // stroke: '#5F95FF',
|
|
|
+ // },
|
|
|
+ // label: {
|
|
|
+ // fontSize: 14,
|
|
|
+ // fill: '#262626',
|
|
|
+ // textVerticalAnchor: 'bottom',
|
|
|
+ // },
|
|
|
+ // line: {
|
|
|
+ // stroke: '#5F95FF',
|
|
|
+ // strokeWidth: 2,
|
|
|
+ // d: 'M 0 15 L 60 15',
|
|
|
+ // },
|
|
|
+ // },
|
|
|
+ // },
|
|
|
+ // true,
|
|
|
+ // )
|
|
|
|
|
|
// 连接器
|
|
|
Graph.registerConnector(
|
|
|
'mindmap',
|
|
|
(sourcePoint, targetPoint, routerPoints, options) => {
|
|
|
- console.log(sourcePoint, targetPoint, routerPoints, options,'sourcePoint, targetPoint, routerPoints, options');
|
|
|
+ // console.log(sourcePoint, targetPoint, routerPoints, options,'sourcePoint, targetPoint, routerPoints, options');
|
|
|
const midX = sourcePoint.x + 10
|
|
|
const midY = sourcePoint.y
|
|
|
const ctrX = (targetPoint.x - midX) / 5 + midX
|
|
@@ -131,7 +260,7 @@ export default {
|
|
|
},
|
|
|
attrs: {
|
|
|
line: {
|
|
|
- targetMarker: '',
|
|
|
+ targetMarker: false,
|
|
|
stroke: '#A2B1C3',
|
|
|
strokeWidth: 2,
|
|
|
},
|
|
@@ -143,41 +272,59 @@ export default {
|
|
|
},
|
|
|
methods: {
|
|
|
setGraph(){
|
|
|
- this.graph.on('add:topic', ({ node }) => {
|
|
|
- console.log(this.mindMapData,'this.mindMapData');
|
|
|
+ this.graph.on('add:topic:left', ({ node }) => {
|
|
|
+ if(this.operationType=='view') return
|
|
|
+ // console.log(this.mindMapDataCurrent,'this.mindMapDataCurrent');
|
|
|
const { id } = node
|
|
|
+ this.setCurrent(id)
|
|
|
const type = node.prop('type')
|
|
|
- console.log(type,'typetypetype');
|
|
|
- if (this.addChildNode(id, type)) {
|
|
|
- this.mindMapRender(this.mindmapPosition)
|
|
|
+ if (this.addChildNode(id, type,'left')) {
|
|
|
+ this.mindMapRender()
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ this.graph.on('add:topic:right', ({ node }) => {
|
|
|
+ if(this.operationType=='view') return
|
|
|
+ // console.log(this.mindMapDataCurrent,'this.mindMapDataCurrent');
|
|
|
+ const { id } = node
|
|
|
+ this.setCurrent(id)
|
|
|
+ const type = node.prop('type')
|
|
|
+ if (this.addChildNode(id, type,'right')) {
|
|
|
+ this.mindMapRender()
|
|
|
}
|
|
|
})
|
|
|
-
|
|
|
this.graph.on('node:change:size', (args) => {
|
|
|
+ if(this.operationType=='view') return
|
|
|
if(args.node.shape.indexOf('mindmap')!==-1){
|
|
|
- console.log(args.node);
|
|
|
- console.log(args.node.size());
|
|
|
- let changeData=[this.mindMapData]
|
|
|
|
|
|
let indexSequence = args.node.id.split('-').map(idn => +idn-1)
|
|
|
- console.log(indexSequence,'indexSequence');
|
|
|
- let selectMindmap = {}
|
|
|
- for (let i = 0; i < indexSequence.length; i++) {
|
|
|
+
|
|
|
+ let index = indexSequence[0] || 0
|
|
|
+ let mindMapDataCurrent = this.mindmapDataUse[index]?this.mindmapDataUse[index].mindmapData:{}
|
|
|
+
|
|
|
+ let changeData=[mindMapDataCurrent]
|
|
|
+ // console.log(indexSequence,'indexSequence');
|
|
|
+ // console.log(changeData,'changeData');
|
|
|
+ let selectMindmap = changeData[0]
|
|
|
+ for (let i = 1; i < indexSequence.length; i++) {
|
|
|
let element = indexSequence[i]
|
|
|
- if(i==0){
|
|
|
- selectMindmap = changeData[element]
|
|
|
- }else{
|
|
|
- selectMindmap= selectMindmap.children[element]
|
|
|
- }
|
|
|
+ selectMindmap= selectMindmap.children[element]
|
|
|
}
|
|
|
- console.log(selectMindmap);
|
|
|
+ // console.log(selectMindmap);
|
|
|
selectMindmap.width = args.node.size().width
|
|
|
selectMindmap.height = args.node.size().height
|
|
|
}
|
|
|
})
|
|
|
this.graph.on('node:change:position', (args) => {
|
|
|
- if(args.node.id==='1'){
|
|
|
- this.mindmapPosition = args.current
|
|
|
+ if(this.operationType=='view') return
|
|
|
+ if(args.node.shape.indexOf('mindmap')!==-1){
|
|
|
+ // console.log(Number(args.node.id));
|
|
|
+ let index = Number(args.node.id)
|
|
|
+ if(index){
|
|
|
+ let indexReal=index-1
|
|
|
+ this.mindmapDataUse[indexReal].position = args.current
|
|
|
+ this.setCurrent(args.node.id)
|
|
|
+ }
|
|
|
}
|
|
|
})
|
|
|
|
|
@@ -191,21 +338,38 @@ export default {
|
|
|
// }
|
|
|
// })
|
|
|
|
|
|
- this.graph.bindKey('tab', (e) => {
|
|
|
+ this.graph.bindKey('tab', (e) => {
|
|
|
+ if(this.operationType=='view') return
|
|
|
e.preventDefault()
|
|
|
- const selectedNodes = this.graph.getSelectedCells().filter((item) => item.isNode())
|
|
|
+ const selectedNodes = this.graph.getSelectedCells().filter((item) => {
|
|
|
+ return item.shape.indexOf('mindmap')!=-1 && item.isNode()
|
|
|
+ })
|
|
|
if (selectedNodes.length) {
|
|
|
const node = selectedNodes[0]
|
|
|
- if (this.addChildNode(node.id, type)) {
|
|
|
- // this.mindMapRender()
|
|
|
+ this.setCurrent(node.id)
|
|
|
+ let type = node.prop('type')
|
|
|
+ let direction = node.shape.indexOf('left')!=-1?'left':'right'
|
|
|
+ if (this.addChildNode(node.id, type,direction)) {
|
|
|
+ this.mindMapRender()
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
- mindMapRender(){
|
|
|
-
|
|
|
- console.log(this.mindMapData);
|
|
|
- const result = Hierarchy.mindmap(this.mindMapData, {
|
|
|
+ // 通过id设置当前操作的思维导图
|
|
|
+ setCurrent(id){
|
|
|
+ // console.log(id);
|
|
|
+ let index = parseInt(id.split('-')[0])-1 || 0
|
|
|
+ this.mindMapDataCurrent = this.mindmapDataUse[index]?this.mindmapDataUse[index].mindmapData:{}
|
|
|
+ this.positionCurrent = this.mindmapDataUse[index]?this.mindmapDataUse[index].position:{x:0,y:0}
|
|
|
+ this.addTypeCurrent = this.mindmapDataUse[index]?this.mindmapDataUse[index].addType:'singleMindmap'
|
|
|
+ },
|
|
|
+ mindMapRender(i){
|
|
|
+ // console.log(this.mindMapDataCurrent);
|
|
|
+ let mindMapType = i || i==0?this.mindmapDataUse[i].addType:this.addTypeCurrent
|
|
|
+ this.mindMapDataCurrent = i || i==0?this.mindmapDataUse[i].mindmapData:this.mindMapDataCurrent
|
|
|
+ this.positionCurrent = i || i==0?this.mindmapDataUse[i].position:this.positionCurrent
|
|
|
+ console.log(this.mindMapDataCurrent,this.positionCurrent,this.addTypeCurrent);
|
|
|
+ const result = Hierarchy.mindmap(this.mindMapDataCurrent, {
|
|
|
direction: 'H',
|
|
|
getHeight(d) {
|
|
|
return d.height
|
|
@@ -219,22 +383,24 @@ export default {
|
|
|
getVGap() {
|
|
|
return 20
|
|
|
},
|
|
|
- getSide: () => {
|
|
|
- return 'right'
|
|
|
+ getSide: (d) => {
|
|
|
+ return mindMapType.indexOf('double') != -1?d.data.direction || 'left':'right'
|
|
|
}
|
|
|
})
|
|
|
const cells = []
|
|
|
- let xGap = this.mindmapPosition?this.mindmapPosition.x-result.x:0
|
|
|
- let yGap = this.mindmapPosition?this.mindmapPosition.y-result.y:0
|
|
|
+ let xGap = this.positionCurrent?this.positionCurrent.x-result.x:0
|
|
|
+ let yGap = this.positionCurrent?this.positionCurrent.y-result.y:0
|
|
|
|
|
|
const traverse = (hierarchyItem) => {
|
|
|
if (hierarchyItem) {
|
|
|
const { data, children } = hierarchyItem
|
|
|
- console.log(hierarchyItem,'hierarchyItemhierarchyItemhierarchyItem');
|
|
|
+ // console.log(hierarchyItem,'hierarchyItemhierarchyItemhierarchyItem');
|
|
|
+ let mindmapDirection = mindMapType.indexOf('double') != -1?data.direction:'right'
|
|
|
+ // console.log(mindmapDirection,data.label,data.direction);
|
|
|
cells.push(
|
|
|
this.graph.createNode({
|
|
|
id: data.id,
|
|
|
- shape: data.type === 'mindmap-topic-child' ? 'mindmap-topic-child' : 'mindmap-topic',
|
|
|
+ shape:mindmapDirection=='right'?'mindmap-topic-right':mindmapDirection=='left'?'mindmap-topic-left':'mindmap-topic',
|
|
|
x: xGap+hierarchyItem.x,
|
|
|
y: yGap+hierarchyItem.y,
|
|
|
width: data.width,
|
|
@@ -246,30 +412,23 @@ export default {
|
|
|
if (children) {
|
|
|
children.forEach((item) => {
|
|
|
const { id, data } = item
|
|
|
+ let mindmapChildDirection = mindMapType.indexOf('double') != -1?data.direction:'right'
|
|
|
cells.push(
|
|
|
this.graph.createEdge({
|
|
|
shape: 'mindmap-edge',
|
|
|
source: {
|
|
|
cell: hierarchyItem.id,
|
|
|
- anchor:
|
|
|
- data.type === 'mindmap-topic-child'
|
|
|
- ? {
|
|
|
- name: 'right',
|
|
|
- args: {
|
|
|
- dx: -16,
|
|
|
- },
|
|
|
- }
|
|
|
- : {
|
|
|
- name: 'center',
|
|
|
- // args: {
|
|
|
- // dx: '25%',
|
|
|
- // },
|
|
|
- },
|
|
|
+ anchor: {
|
|
|
+ name: 'center',
|
|
|
+ args: {
|
|
|
+ dx: mindmapChildDirection=='right'?'25%':mindmapChildDirection=='left'?'-25%':0,
|
|
|
+ },
|
|
|
+ },
|
|
|
},
|
|
|
target: {
|
|
|
cell: id,
|
|
|
anchor: {
|
|
|
- name: 'left',
|
|
|
+ name: mindmapChildDirection =='left'?'right':'left',
|
|
|
},
|
|
|
},
|
|
|
}),
|
|
@@ -280,7 +439,7 @@ export default {
|
|
|
}
|
|
|
}
|
|
|
traverse(result)
|
|
|
- console.log(cells,'result');
|
|
|
+ // console.log(cells,'result');
|
|
|
this.graph.removeCells(cells)
|
|
|
this.graph.addCell(cells)
|
|
|
// this.graph.resetCells(cells)
|
|
@@ -307,8 +466,8 @@ export default {
|
|
|
}
|
|
|
return null
|
|
|
},
|
|
|
- addChildNode (id, type){
|
|
|
- const res = this.findItem(this.mindMapData, id)
|
|
|
+ addChildNode (id, type,direction='left'){
|
|
|
+ const res = this.findItem(this.mindMapDataCurrent, id)
|
|
|
const dataItem = res && res.node
|
|
|
if (dataItem) {
|
|
|
let item = null
|
|
@@ -320,14 +479,16 @@ export default {
|
|
|
label: `分支主题${length + 1}`,
|
|
|
width: 100,
|
|
|
height: 40,
|
|
|
+ direction
|
|
|
}
|
|
|
- } else if (type === 'topic-branch') {
|
|
|
+ } else if (type === 'topic-branch' || type=='topic-child') {
|
|
|
item = {
|
|
|
id: `${id}-${length + 1}`,
|
|
|
- type: 'topic',
|
|
|
+ type: 'topic-child',
|
|
|
label: `子主题${length + 1}`,
|
|
|
width: 60,
|
|
|
height: 30,
|
|
|
+ direction
|
|
|
}
|
|
|
}
|
|
|
if (item) {
|
|
@@ -342,7 +503,7 @@ export default {
|
|
|
return null
|
|
|
},
|
|
|
removeNode (id) {
|
|
|
- const res = this.findItem(this.mindMapData, id)
|
|
|
+ const res = this.findItem(this.mindMapDataCurrent, id)
|
|
|
const dataItem = res && res.parent
|
|
|
if (dataItem && dataItem.children) {
|
|
|
const { children } = dataItem
|