Skip to content

Commit efe859b

Browse files
committed
fix: missing line at moveNodeBefore
fixed #101
1 parent 6a9aa51 commit efe859b

File tree

6 files changed

+40
-43
lines changed

6 files changed

+40
-43
lines changed

.prettierrc.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"tabWidth": 2,
44
"semi": false,
55
"singleQuote": true,
6-
"arrowParens": "avoid"
7-
}
6+
"arrowParens": "avoid",
7+
"printWidth": 150
8+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mind-elixir",
3-
"version": "0.19.5",
3+
"version": "0.19.6",
44
"description": "Mind elixir is a free open source mind map core.",
55
"main": "dist/MindElixir.js",
66
"scripts": {

src/dev.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,24 @@ import { exportSvg, exportPng } from '../painter/index'
44
import example from './exampleData/1'
55
import example2 from './exampleData/2'
66

7+
interface Window {
8+
currentOperation: any
9+
m: any
10+
M: any
11+
E: any
12+
exportSvg: any
13+
exportPng: any
14+
}
15+
16+
declare let window: Window
17+
718
const mind = new MindElixir({
819
el: '#map',
920
newTopicName: '子节点',
1021
direction: MindElixir.SIDE,
1122
// direction: MindElixir.RIGHT,
12-
// data: MindElixir.new('new topic'),
13-
data: example,
23+
data: MindElixir.new('new topic'),
24+
// data: example,
1425
locale: 'en',
1526
draggable: true,
1627
editable: true,

src/linkDiv.ts

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import { createPath, createMainPath, createLinkSvg } from './utils/svg'
22
import { findEle, Expander } from './utils/dom'
3-
import {
4-
SIDE,
5-
GAP,
6-
TURNPOINT_R,
7-
PRIMARY_NODE_HORIZONTAL_GAP,
8-
PRIMARY_NODE_VERTICAL_GAP,
9-
} from './const'
3+
import { SIDE, GAP, TURNPOINT_R, PRIMARY_NODE_HORIZONTAL_GAP, PRIMARY_NODE_VERTICAL_GAP } from './const'
104

115
/**
126
* Link nodes with svg,
@@ -134,8 +128,7 @@ export default function linkDiv(primaryNode) {
134128
// set position of expander
135129
const expander = el.children[0].children[1]
136130
if (expander) {
137-
expander.style.top =
138-
(expander.parentNode.offsetHeight - expander.offsetHeight) / 2 + 'px'
131+
expander.style.top = (expander.parentNode.offsetHeight - expander.offsetHeight) / 2 + 'px'
139132
if (el.className === 'lhs') {
140133
expander.style.left = -10 + 'px'
141134
} else {
@@ -171,17 +164,13 @@ export default function linkDiv(primaryNode) {
171164
if (typeof link.from === 'string') {
172165
this.createLink(findEle(link.from), findEle(link.to), true, link)
173166
} else {
174-
this.createLink(
175-
findEle(link.from.nodeObj.id),
176-
findEle(link.to.nodeObj.id),
177-
true,
178-
link
179-
)
167+
this.createLink(findEle(link.from.nodeObj.id), findEle(link.to.nodeObj.id), true, link)
180168
}
181169
}
182170
console.timeEnd('linkDiv')
183171
}
184172

173+
// core function of generate svg3rd
185174
let path = ''
186175
function loopChildren(children: HTMLCollection, parent: HTMLElement, first?: boolean) {
187176
const parentOT = parent.offsetTop
@@ -207,10 +196,7 @@ function loopChildren(children: HTMLCollection, parent: HTMLElement, first?: boo
207196
xMiddle = parentOL
208197
x2 = parentOL - childT.offsetWidth
209198

210-
if (
211-
childTOT + childTOH < parentOT + parentOH / 2 + 50 &&
212-
childTOT + childTOH > parentOT + parentOH / 2 - 50
213-
) {
199+
if (childTOT + childTOH < parentOT + parentOH / 2 + 50 && childTOT + childTOH > parentOT + parentOH / 2 - 50) {
214200
// 相差+-50内直接直线
215201
path += `M ${x1} ${y1} H ${xMiddle} V ${y2} H ${x2}`
216202
} else if (childTOT + childTOH >= parentOT + parentOH / 2) {
@@ -225,10 +211,7 @@ function loopChildren(children: HTMLCollection, parent: HTMLElement, first?: boo
225211
xMiddle = parentOL + parentOW
226212
x2 = parentOL + parentOW + childT.offsetWidth
227213

228-
if (
229-
childTOT + childTOH < parentOT + parentOH / 2 + 50 &&
230-
childTOT + childTOH > parentOT + parentOH / 2 - 50
231-
) {
214+
if (childTOT + childTOH < parentOT + parentOH / 2 + 50 && childTOT + childTOH > parentOT + parentOH / 2 - 50) {
232215
path += `M ${x1} ${y1} H ${xMiddle} V ${y2} H ${x2}`
233216
} else if (childTOT + childTOH >= parentOT + parentOH / 2) {
234217
path += `M ${x1} ${y1} H ${xMiddle} V ${y2 - TURNPOINT_R} A ${TURNPOINT_R} ${TURNPOINT_R} 0 0 0 ${xMiddle + TURNPOINT_R} ${y2} H ${x2}`
@@ -239,8 +222,7 @@ function loopChildren(children: HTMLCollection, parent: HTMLElement, first?: boo
239222

240223
const expander = childT.children[1] as Expander
241224
if (expander) {
242-
expander.style.top =
243-
(childT.offsetHeight - expander.offsetHeight) / 2 + 'px'
225+
expander.style.top = (childT.offsetHeight - expander.offsetHeight) / 2 + 'px'
244226
if (direction === 'lhs') {
245227
expander.style.left = -10 + 'px'
246228
} else if (direction === 'rhs') {

src/nodeOperation.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -423,11 +423,7 @@ export const removeNode = function(el) {
423423
// MAYBEBUG should traversal all children node
424424
const link = this.linkData[prop]
425425
if (link.from === t.firstChild || link.to === t.firstChild) {
426-
this.removeLink(
427-
this.mindElixirBox.querySelector(
428-
`[data-linkid=${this.linkData[prop].id}]`
429-
)
430-
)
426+
this.removeLink(this.mindElixirBox.querySelector(`[data-linkid=${this.linkData[prop].id}]`))
431427
}
432428
}
433429
// remove GRP
@@ -527,6 +523,7 @@ export const moveNodeBefore = function(from, to) {
527523
const toGrp = toTop.parentNode
528524
const toChilren = toTop.parentNode.parentNode
529525
toChilren.insertBefore(fromGrp, toGrp)
526+
if (toGrp.className) fromGrp.className = toGrp.className
530527
this.linkDiv()
531528
this.bus.fire('operation', {
532529
name: 'moveNodeBefore',
@@ -557,6 +554,7 @@ export const moveNodeAfter = function(from, to) {
557554
const toGrp = toTop.parentNode
558555
const toChilren = toTop.parentNode.parentNode
559556
toChilren.insertBefore(fromGrp, toGrp.nextSibling)
557+
if (toGrp.className) fromGrp.className = toGrp.className
560558
this.linkDiv()
561559
this.bus.fire('operation', {
562560
name: 'moveNodeAfter',

src/utils/svg.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@ export const createLinkSvg = function(klass: string) {
1515
return svg
1616
}
1717

18-
export const createLine = function(x1: number, y1: number, x2: number, y2: number) {
18+
export const createLine = function(
19+
x1: number,
20+
y1: number,
21+
x2: number,
22+
y2: number
23+
) {
1924
const line = $d.createElementNS(svgNS, 'line')
20-
line.setAttribute('x1', x1)
21-
line.setAttribute('y1', y1)
22-
line.setAttribute('x2', x2)
23-
line.setAttribute('y2', y2)
25+
line.setAttribute('x1', x1 + '')
26+
line.setAttribute('y1', y1 + '')
27+
line.setAttribute('x2', x2 + '')
28+
line.setAttribute('y2', y2 + '')
2429
line.setAttribute('stroke', '#bbb')
2530
line.setAttribute('fill', 'none')
2631
line.setAttribute('stroke-width', '2')
@@ -39,10 +44,10 @@ export const createPath = function(d: string) {
3944
return path
4045
}
4146

42-
interface CustomSvg extends SVGElement{
43-
linkObj?:object
47+
interface CustomSvg extends SVGElement {
48+
linkObj?: object
4449
}
45-
export const createSvgGroup = function(d: string, arrowd: string):CustomSvg {
50+
export const createSvgGroup = function(d: string, arrowd: string): CustomSvg {
4651
const g = $d.createElementNS(svgNS, 'g')
4752
const path = $d.createElementNS(svgNS, 'path')
4853
const arrow = $d.createElementNS(svgNS, 'path')

0 commit comments

Comments
 (0)