Skip to content

Commit 8d93e30

Browse files
committed
refactor: rename functions and variables
1 parent d9d4cbb commit 8d93e30

File tree

8 files changed

+43
-43
lines changed

8 files changed

+43
-43
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/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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 5 additions & 5 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 {
@@ -113,7 +113,7 @@ export interface MindElixirInstance {
113113
map: HTMLElement,
114114
root: HTMLElement,
115115
box: HTMLElement,
116-
svg2nd: SVGElement,
116+
lines: SVGElement,
117117
linkController: SVGElement,
118118
P2: HTMLElement,
119119
P3: HTMLElement,
@@ -223,7 +223,7 @@ function MindElixir(this: MindElixirInstance, {
223223

224224
// infrastructure
225225

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

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

239239
this.map.appendChild(this.root)
240240
this.map.appendChild(this.box)
241-
this.map.appendChild(this.svg2nd)
241+
this.map.appendChild(this.lines)
242242
this.map.appendChild(this.linkController)
243243
this.map.appendChild(this.linkSvgGroup)
244244
this.map.appendChild(this.P2)
@@ -253,7 +253,7 @@ MindElixir.prototype = {
253253
addParentLink,
254254
getObjById,
255255
// node operation
256-
processPrimaryNode,
256+
judgeDirection,
257257
setNodeTopic,
258258
createLink,
259259
layout,

src/index.ts

Lines changed: 5 additions & 5 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,
@@ -154,7 +154,7 @@ export interface MindElixirInstance {
154154
map: HTMLElement,
155155
root: HTMLElement,
156156
box: HTMLElement,
157-
svg2nd: SVGElement,
157+
lines: SVGElement,
158158
linkController:SVGElement,
159159
P2: HTMLElement,
160160
P3: HTMLElement,
@@ -315,7 +315,7 @@ function MindElixir(this: MindElixirInstance, {
315315

316316
// infrastructure
317317

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

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

331331
this.map.appendChild(this.root)
332332
this.map.appendChild(this.box)
333-
this.map.appendChild(this.svg2nd)
333+
this.map.appendChild(this.lines)
334334
this.map.appendChild(this.linkController)
335335
this.map.appendChild(this.linkSvgGroup)
336336
this.map.appendChild(this.P2)
@@ -373,7 +373,7 @@ MindElixir.prototype = {
373373
updateNodeTags,
374374
updateNodeIcons,
375375
updateNodeHyperLink,
376-
processPrimaryNode,
376+
judgeDirection,
377377
setNodeTopic,
378378

379379
createLink,

src/linkDiv.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default function linkDiv(primaryNode) {
2020
const root = this.root
2121
root.style.cssText = `top:${10000 - root.offsetHeight / 2}px;left:${10000 - root.offsetWidth / 2}px;`
2222
const primaryNodeList = this.box.children
23-
this.svg2nd.innerHTML = ''
23+
this.lines.innerHTML = ''
2424

2525
// 1. calculate position of primary nodes
2626
let totalHeight = 0
@@ -136,7 +136,7 @@ export default function linkDiv(primaryNode) {
136136
}
137137
}
138138
}
139-
this.svg2nd.appendChild(createMainPath(primaryPath))
139+
this.lines.appendChild(createMainPath(primaryPath))
140140

141141
// 3. generate link inside primary node
142142
for (let i = 0; i < primaryNodeList.length; i++) {
@@ -145,14 +145,13 @@ export default function linkDiv(primaryNode) {
145145
continue
146146
}
147147
if (el.childElementCount) {
148-
const svg = createLinkSvg('svg3rd')
148+
const svg = createLinkSvg('subLines')
149149
// svg tag name is lower case
150150
if (el.lastChild.tagName === 'svg') el.lastChild.remove()
151151
el.appendChild(svg)
152152
const parent = el.children[0]
153153
const children = el.children[1].children
154-
path = ''
155-
loopChildren(children, parent, true)
154+
const path = traverseChildren(children, parent, true)
156155
svg.appendChild(createPath(path))
157156
}
158157
}
@@ -170,9 +169,9 @@ export default function linkDiv(primaryNode) {
170169
console.timeEnd('linkDiv')
171170
}
172171

173-
// core function of generate svg3rd
174-
let path = ''
175-
function loopChildren(children: HTMLCollection, parent: HTMLElement, first?: boolean) {
172+
// core function of generate subLines
173+
function traverseChildren(children: HTMLCollection, parent: HTMLElement, first?: boolean):string {
174+
let path = ''
176175
const parentOT = parent.offsetTop
177176
const parentOL = parent.offsetLeft
178177
const parentOW = parent.offsetWidth
@@ -197,7 +196,7 @@ function loopChildren(children: HTMLCollection, parent: HTMLElement, first?: boo
197196
x2 = parentOL - childT.offsetWidth + GAP
198197

199198
if (childTOT + childTOH < parentOT + parentOH / 2 + 50 && childTOT + childTOH > parentOT + parentOH / 2 - 50) {
200-
// straight line
199+
// draw straight line if the distance is between +-50
201200
path += `M ${x1} ${y1} H ${xMiddle} V ${y2} H ${x2}`
202201
} else if (childTOT + childTOH >= parentOT + parentOH / 2) {
203202
// child bottom lower than parent
@@ -234,8 +233,9 @@ function loopChildren(children: HTMLCollection, parent: HTMLElement, first?: boo
234233
// expander not exist
235234
continue
236235
}
237-
// traversal
236+
238237
const nextChildren = child.children[1].children
239-
if (nextChildren.length > 0) loopChildren(nextChildren, childT)
238+
if (nextChildren.length > 0) { path += traverseChildren(nextChildren, childT) }
240239
}
240+
return path
241241
}

src/nodeOperation.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export const insertSibling = function(el, node) {
117117
const children = t.parentNode.parentNode
118118
children.insertBefore(grp, t.parentNode.nextSibling)
119119
if (children.className === 'box') {
120-
this.processPrimaryNode(grp, newNodeObj)
120+
this.judgeDirection(grp, newNodeObj)
121121
this.linkDiv()
122122
} else {
123123
this.linkDiv(grp.offsetParent)
@@ -163,7 +163,7 @@ export const insertBefore = function(el, node) {
163163
const children = t.parentNode.parentNode
164164
children.insertBefore(grp, t.parentNode)
165165
if (children.className === 'box') {
166-
this.processPrimaryNode(grp, newNodeObj)
166+
this.judgeDirection(grp, newNodeObj)
167167
this.linkDiv()
168168
} else {
169169
this.linkDiv(grp.offsetParent)
@@ -216,7 +216,7 @@ export const insertParent = function(el, node) {
216216
if (children0.className === 'box') {
217217
grp.className = grp0.className // l/rhs
218218
grp0.className = ''
219-
grp0.querySelector('.svg3rd').remove()
219+
grp0.querySelector('.subLines').remove()
220220
this.linkDiv()
221221
} else {
222222
this.linkDiv(grp.offsetParent)
@@ -261,7 +261,7 @@ export const addChildFunction = function(nodeEle, node) {
261261
}
262262
this.linkDiv(grp.offsetParent)
263263
} else if (top.tagName === 'ROOT') {
264-
this.processPrimaryNode(grp, newNodeObj)
264+
this.judgeDirection(grp, newNodeObj)
265265
top.nextSibling.appendChild(grp)
266266
this.linkDiv()
267267
}
@@ -486,7 +486,7 @@ export const moveNode = function(from, to) {
486486
toTop.parentElement.insertBefore(c, toTop.nextSibling)
487487
}
488488
} else if (toTop.tagName === 'ROOT') {
489-
this.processPrimaryNode(fromTop.parentNode, fromObj)
489+
this.judgeDirection(fromTop.parentNode, fromObj)
490490
toTop.nextSibling.appendChild(fromTop.parentNode)
491491
}
492492
this.linkDiv()
@@ -582,7 +582,7 @@ export const setNodeTopic = function(tpc, topic) {
582582
}
583583

584584
// Judge L or R
585-
export function processPrimaryNode(primaryNode, obj) {
585+
export function judgeDirection(primaryNode, obj) {
586586
if (this.direction === LEFT) {
587587
primaryNode.className = 'lhs'
588588
} else if (this.direction === RIGHT) {

0 commit comments

Comments
 (0)