Skip to content

Commit 2a2e8ca

Browse files
authored
Merge pull request #130 from ssshooter/v1.1.1
V1.1.1
2 parents 8d5784d + d2556c9 commit 2a2e8ca

File tree

12 files changed

+116
-116
lines changed

12 files changed

+116
-116
lines changed

painter/index.foreignObject.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ function RootToSvg() {
6565
let rootOffsetY = root.offsetTop - maxTop
6666
let rootOffsetX = root.offsetLeft - maxLeft
6767

68-
let svg2ndEle = document.querySelector('.svg2nd')
68+
let svg2ndEle = document.querySelector('.lines')
6969

70-
let svg2nd = `<g transform="translate(${imgPadding - maxLeft}, ${
70+
let lines = `<g transform="translate(${imgPadding - maxLeft}, ${
7171
imgPadding - maxTop
7272
})">${svg2ndEle.innerHTML}</g>`
7373
return (
74-
svg2nd +
74+
lines +
7575
`<g id="root" transform="translate(${rootOffsetX + imgPadding}, ${
7676
rootOffsetY + imgPadding
7777
})">
@@ -93,11 +93,11 @@ function PrimaryToSvg(primaryNode) {
9393
let primaryNodeOffsetX = primaryNode.offsetLeft - maxLeft
9494

9595
let svg = ''
96-
let svg3rd = primaryNode.querySelector('.svg3rd')
96+
let subLines = primaryNode.querySelector('.subLines')
9797
svg += `<g transform="translate(${primaryNodeOffsetX + imgPadding}, ${
9898
primaryNodeOffsetY + imgPadding
9999
})">`
100-
svg += svg3rd ? svg3rd.innerHTML : ''
100+
svg += subLines ? subLines.innerHTML : ''
101101
for (let i = 0; i < topics.length; i++) {
102102
let tpc = topics[i]
103103
let t = tpc.parentNode

painter/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ function RootToSvg() {
8080
let rootOffsetY = root.offsetTop - maxTop
8181
let rootOffsetX = root.offsetLeft - maxLeft
8282

83-
let svg2ndEle = $d.querySelector('.svg2nd')
83+
let svg2ndEle = $d.querySelector('.lines')
8484

85-
let svg2nd = `<g transform="translate(${IMG_PADDING - maxLeft}, ${
85+
let lines = `<g transform="translate(${IMG_PADDING - maxLeft}, ${
8686
IMG_PADDING - maxTop
8787
})">${svg2ndEle.innerHTML}</g>`
8888
return (
89-
svg2nd +
89+
lines +
9090
`<g id="root" transform="translate(${rootOffsetX + IMG_PADDING}, ${
9191
rootOffsetY + IMG_PADDING
9292
})">
@@ -108,11 +108,11 @@ function PrimaryToSvg(primaryNode) {
108108
let primaryNodeOffsetX = primaryNode.offsetLeft - maxLeft
109109

110110
let svg = ''
111-
let svg3rd = primaryNode.querySelector('.svg3rd')
111+
let subLines = primaryNode.querySelector('.subLines')
112112
svg += `<g transform="translate(${primaryNodeOffsetX + IMG_PADDING}, ${
113113
primaryNodeOffsetY + IMG_PADDING
114114
})">`
115-
svg += svg3rd ? svg3rd.innerHTML : ''
115+
svg += subLines ? subLines.innerHTML : ''
116116
for (let i = 0; i < topics.length; i++) {
117117
let tpc = topics[i]
118118
let t = tpc.parentNode

src/dev.dist.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const mind = new MindElixir({
3535
return false
3636
},
3737
insertSibling(el, obj) {
38+
console.log('insertSibling', el, obj)
3839
return true
3940
},
4041
async addChild(el, obj) {
@@ -46,7 +47,7 @@ const mind = new MindElixir({
4647
primaryNodeVerticalGap: 15, // 25
4748
primaryNodeHorizontalGap: 15, // 65
4849
})
49-
mind.init()
50+
mind.init(example)
5051
function sleep() {
5152
return new Promise((res, rej) => {
5253
setTimeout(() => res(), 1000)

src/dev.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ const options = {
5656
},
5757
},
5858
primaryLinkStyle: 1,
59-
primaryNodeVerticalGap: 15, // 25
60-
primaryNodeHorizontalGap: 15, // 65
59+
primaryNodeVerticalGap: 25, // 25
60+
primaryNodeHorizontalGap: 65, // 65
6161
}
6262

6363
const mind = new (MindElixir as any)(options)

src/exampleData/2.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export default {
7272
],
7373
tags: ['createChildren return'],
7474
},
75-
{ topic: 'svg.svg3rd', id: '33908986b6336a4f' },
75+
{ topic: 'svg.subLines', id: '33908986b6336a4f' },
7676
],
7777
tags: ['have child'],
7878
},
@@ -93,7 +93,7 @@ export default {
9393
{ topic: 'grp...', id: '33b61346707af71a' },
9494
],
9595
},
96-
{ topic: 'svg.svg2nd', id: '3390707d68c0779d' },
96+
{ topic: 'svg.lines', id: '3390707d68c0779d' },
9797
{ topic: 'svg.linkcontroller', id: '339072cb6cf95295' },
9898
{ topic: 'svg.topiclinks', id: '3390751acbdbdb9f' },
9999
],

src/index.less

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@GAP: 15px; // node horizontal gap
1+
@GAP: 15px; // child node horizontal gap
22

33
.mind-elixir {
44
position: relative;
@@ -178,8 +178,8 @@
178178
fill: currentColor;
179179
overflow: hidden;
180180
}
181-
.svg2nd,
182-
.svg3rd,
181+
.lines,
182+
.subLines,
183183
.topiclinks,
184184
.linkcontroller {
185185
position: absolute;
@@ -195,8 +195,8 @@
195195
pointer-events: all;
196196
}
197197
}
198-
.svg2nd,
199-
.svg3rd {
198+
.lines,
199+
.subLines {
200200
pointer-events: none;
201201
z-index: -1;
202202
}

src/index.lite.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
refresh,
2929
} from './interact'
3030
import {
31-
processPrimaryNode,
31+
judgeDirection,
3232
setNodeTopic,
3333
} from './nodeOperation'
3434
import {
@@ -72,7 +72,8 @@ export interface NodeObj {
7272
}
7373
export interface MindElixirData {
7474
nodeData: NodeObj,
75-
linkData?: LinkObj
75+
linkData?: LinkObj,
76+
direction?: number,
7677
}
7778
export interface MindElixirInstance {
7879
mindElixirBox: HTMLElement,
@@ -112,13 +113,13 @@ export interface MindElixirInstance {
112113
map: HTMLElement,
113114
root: HTMLElement,
114115
box: HTMLElement,
115-
svg2nd: SVGElement,
116-
linkController:SVGElement,
116+
lines: SVGElement,
117+
linkController: SVGElement,
117118
P2: HTMLElement,
118119
P3: HTMLElement,
119-
line1:SVGElement,
120-
line2:SVGElement,
121-
linkSvgGroup:SVGElement,
120+
line1: SVGElement,
121+
line2: SVGElement,
122+
linkSvgGroup: SVGElement,
122123
}
123124
export interface Options {
124125
el: string | Element,
@@ -222,7 +223,7 @@ function MindElixir(this: MindElixirInstance, {
222223

223224
// infrastructure
224225

225-
this.svg2nd = createLinkSvg('svg2nd') // main link container
226+
this.lines = createLinkSvg('lines') // main link container
226227

227228
this.linkController = createLinkSvg('linkcontroller') // bezier controller container
228229
this.P2 = $d.createElement('div') // bezier P2
@@ -237,7 +238,7 @@ function MindElixir(this: MindElixirInstance, {
237238

238239
this.map.appendChild(this.root)
239240
this.map.appendChild(this.box)
240-
this.map.appendChild(this.svg2nd)
241+
this.map.appendChild(this.lines)
241242
this.map.appendChild(this.linkController)
242243
this.map.appendChild(this.linkSvgGroup)
243244
this.map.appendChild(this.P2)
@@ -252,7 +253,7 @@ MindElixir.prototype = {
252253
addParentLink,
253254
getObjById,
254255
// node operation
255-
processPrimaryNode,
256+
judgeDirection,
256257
setNodeTopic,
257258
createLink,
258259
layout,
@@ -280,7 +281,10 @@ MindElixir.prototype = {
280281
expandNode,
281282
refresh,
282283

283-
init: function(data:MindElixirData) {
284+
init: function(data: MindElixirData) {
285+
if (data.direction) {
286+
this.direction = data.direction
287+
}
284288
this.nodeData = data.nodeData
285289
this.linkData = data.linkData || {}
286290
// plugin

src/index.ts

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import {
4646
updateNodeTags,
4747
updateNodeIcons,
4848
updateNodeHyperLink,
49-
processPrimaryNode,
49+
judgeDirection,
5050
setNodeTopic,
5151
moveNodeBefore,
5252
moveNodeAfter,
@@ -113,7 +113,8 @@ export interface NodeElement extends HTMLElement {
113113
}
114114
export interface MindElixirData {
115115
nodeData: NodeObj,
116-
linkData?: LinkObj
116+
linkData?: LinkObj,
117+
direction?: number
117118
}
118119
export interface MindElixirInstance {
119120
mindElixirBox: HTMLElement,
@@ -153,7 +154,7 @@ export interface MindElixirInstance {
153154
map: HTMLElement,
154155
root: HTMLElement,
155156
box: HTMLElement,
156-
svg2nd: SVGElement,
157+
lines: SVGElement,
157158
linkController:SVGElement,
158159
P2: HTMLElement,
159160
P3: HTMLElement,
@@ -314,7 +315,7 @@ function MindElixir(this: MindElixirInstance, {
314315

315316
// infrastructure
316317

317-
this.svg2nd = createLinkSvg('svg2nd') // main link container
318+
this.lines = createLinkSvg('lines') // main link container
318319

319320
this.linkController = createLinkSvg('linkcontroller') // bezier controller container
320321
this.P2 = $d.createElement('div') // bezier P2
@@ -329,7 +330,7 @@ function MindElixir(this: MindElixirInstance, {
329330

330331
this.map.appendChild(this.root)
331332
this.map.appendChild(this.box)
332-
this.map.appendChild(this.svg2nd)
333+
this.map.appendChild(this.lines)
333334
this.map.appendChild(this.linkController)
334335
this.map.appendChild(this.linkSvgGroup)
335336
this.map.appendChild(this.P2)
@@ -340,11 +341,11 @@ function MindElixir(this: MindElixirInstance, {
340341
} else initMouseEvent(this)
341342
}
342343

343-
function beforeHook(fn:(el:any, node?:any)=>void) {
344+
function beforeHook(fn:(el:any, node?:any)=>void, fnName:string) {
344345
return async function(...args:unknown[]) {
345346
if (
346-
!this.before[fn.name] ||
347-
(await this.before[fn.name].apply(this, args))
347+
!this.before[fnName] ||
348+
(await this.before[fnName].apply(this, args))
348349
) {
349350
fn.apply(this, args)
350351
}
@@ -356,23 +357,23 @@ MindElixir.prototype = {
356357
getObjById,
357358
generateNewObj,
358359
// node operation
359-
insertSibling: beforeHook(insertSibling),
360-
insertBefore: beforeHook(insertBefore),
361-
insertParent: beforeHook(insertParent),
362-
addChild: beforeHook(addChild),
363-
copyNode: beforeHook(copyNode),
364-
moveNode: beforeHook(moveNode),
365-
removeNode: beforeHook(removeNode),
366-
moveUpNode: beforeHook(moveUpNode),
367-
moveDownNode: beforeHook(moveDownNode),
368-
beginEdit: beforeHook(beginEdit),
369-
moveNodeBefore: beforeHook(moveNodeBefore),
370-
moveNodeAfter: beforeHook(moveNodeAfter),
360+
insertSibling: beforeHook(insertSibling, 'insertSibling'),
361+
insertBefore: beforeHook(insertBefore, 'insertBefore'),
362+
insertParent: beforeHook(insertParent, 'insertParent'),
363+
addChild: beforeHook(addChild, 'addChild'),
364+
copyNode: beforeHook(copyNode, 'copyNode'),
365+
moveNode: beforeHook(moveNode, 'moveNode'),
366+
removeNode: beforeHook(removeNode, 'removeNode'),
367+
moveUpNode: beforeHook(moveUpNode, 'moveUpNode'),
368+
moveDownNode: beforeHook(moveDownNode, 'moveDownNode'),
369+
beginEdit: beforeHook(beginEdit, 'beginEdit'),
370+
moveNodeBefore: beforeHook(moveNodeBefore, 'moveNodeBefore'),
371+
moveNodeAfter: beforeHook(moveNodeAfter, 'moveNodeAfter'),
371372
updateNodeStyle,
372373
updateNodeTags,
373374
updateNodeIcons,
374375
updateNodeHyperLink,
375-
processPrimaryNode,
376+
judgeDirection,
376377
setNodeTopic,
377378

378379
createLink,
@@ -413,6 +414,9 @@ MindElixir.prototype = {
413414
},
414415
init(data:MindElixirData) {
415416
if (!data || !data.nodeData) return new Error('MindElixir: `data` is required')
417+
if (data.direction) {
418+
this.direction = data.direction
419+
}
416420
this.nodeData = data.nodeData
417421
this.linkData = data.linkData || {}
418422
// plugin

src/interact.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export const getAllDataString = function() {
115115
const data = {
116116
nodeData: getData(this),
117117
linkData: this.linkData,
118+
direction: this.direction,
118119
}
119120
return JSON.stringify(data, (k, v) => {
120121
if (k === 'parent') return undefined
@@ -135,6 +136,7 @@ export const getAllData = function(): object {
135136
const data = {
136137
nodeData: getData(this),
137138
linkData: this.linkData,
139+
direction: this.direction,
138140
}
139141
return JSON.parse(
140142
JSON.stringify(data, (k, v) => {

0 commit comments

Comments
 (0)