Skip to content

Commit

Permalink
feat: save direction to exported data
Browse files Browse the repository at this point in the history
  • Loading branch information
SSShooter committed Sep 28, 2022
1 parent e381bc6 commit d9d4cbb
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
16 changes: 10 additions & 6 deletions src/index.lite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ export interface NodeObj {
}
export interface MindElixirData {
nodeData: NodeObj,
linkData?: LinkObj
linkData?: LinkObj,
direction?: number,
}
export interface MindElixirInstance {
mindElixirBox: HTMLElement,
Expand Down Expand Up @@ -113,12 +114,12 @@ export interface MindElixirInstance {
root: HTMLElement,
box: HTMLElement,
svg2nd: SVGElement,
linkController:SVGElement,
linkController: SVGElement,
P2: HTMLElement,
P3: HTMLElement,
line1:SVGElement,
line2:SVGElement,
linkSvgGroup:SVGElement,
line1: SVGElement,
line2: SVGElement,
linkSvgGroup: SVGElement,
}
export interface Options {
el: string | Element,
Expand Down Expand Up @@ -280,7 +281,10 @@ MindElixir.prototype = {
expandNode,
refresh,

init: function(data:MindElixirData) {
init: function(data: MindElixirData) {
if (data.direction) {
this.direction = data.direction
}
this.nodeData = data.nodeData
this.linkData = data.linkData || {}
// plugin
Expand Down
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ export interface NodeElement extends HTMLElement {
}
export interface MindElixirData {
nodeData: NodeObj,
linkData?: LinkObj
linkData?: LinkObj,
direction?: number
}
export interface MindElixirInstance {
mindElixirBox: HTMLElement,
Expand Down Expand Up @@ -413,6 +414,9 @@ MindElixir.prototype = {
},
init(data:MindElixirData) {
if (!data || !data.nodeData) return new Error('MindElixir: `data` is required')
if (data.direction) {
this.direction = data.direction
}
this.nodeData = data.nodeData
this.linkData = data.linkData || {}
// plugin
Expand Down
2 changes: 2 additions & 0 deletions src/interact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export const getAllDataString = function() {
const data = {
nodeData: getData(this),
linkData: this.linkData,
direction: this.direction,
}
return JSON.stringify(data, (k, v) => {
if (k === 'parent') return undefined
Expand All @@ -135,6 +136,7 @@ export const getAllData = function(): object {
const data = {
nodeData: getData(this),
linkData: this.linkData,
direction: this.direction,
}
return JSON.parse(
JSON.stringify(data, (k, v) => {
Expand Down
6 changes: 3 additions & 3 deletions src/linkDiv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,13 @@ function loopChildren(children: HTMLCollection, parent: HTMLElement, first?: boo
x2 = parentOL - childT.offsetWidth + GAP

if (childTOT + childTOH < parentOT + parentOH / 2 + 50 && childTOT + childTOH > parentOT + parentOH / 2 - 50) {
// 相差+-50内直接直线
// straight line
path += `M ${x1} ${y1} H ${xMiddle} V ${y2} H ${x2}`
} else if (childTOT + childTOH >= parentOT + parentOH / 2) {
// 子底部低于父中点
// child bottom lower than parent
path += `M ${x1} ${y1} H ${xMiddle} V ${y2 - TURNPOINT_R} A ${TURNPOINT_R} ${TURNPOINT_R} 0 0 1 ${xMiddle - TURNPOINT_R} ${y2} H ${x2}`
} else {
// 子底部高于父中点
// child bottom higher than parent
path += `M ${x1} ${y1} H ${xMiddle} V ${y2 + TURNPOINT_R} A ${TURNPOINT_R} ${TURNPOINT_R} 0 0 0 ${xMiddle - TURNPOINT_R} ${y2} H ${x2}`
}
} else if (direction === 'rhs') {
Expand Down
2 changes: 1 addition & 1 deletion src/mouse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function(mind) {
// skip circle
} else {
mind.unselectNode()
// lite version don't have hideLinkController
// lite version doesn't have hideLinkController
mind.hideLinkController && mind.hideLinkController()
}
})
Expand Down

0 comments on commit d9d4cbb

Please sign in to comment.