Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kityminder-core
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
吴志俊
kityminder-core
Commits
ca60958e
Commit
ca60958e
authored
Jan 20, 2014
by
campaign
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' of
https://github.com/kitygraph/kityminder
into dev
parents
c4f5c210
ac919779
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
684 additions
and
140 deletions
+684
-140
layout.default.js
src/module/layout.default.js
+85
-60
layout.green.backup.js
src/module/layout.green.backup.js
+373
-0
layout.green.js
src/module/layout.green.js
+199
-76
layout.js
src/module/layout.js
+27
-4
No files found.
src/module/layout.default.js
View file @
ca60958e
...
@@ -154,10 +154,11 @@ KityMinder.registerModule( "LayoutDefault", function () {
...
@@ -154,10 +154,11 @@ KityMinder.registerModule( "LayoutDefault", function () {
this
.
_node
=
node
;
this
.
_node
=
node
;
var
container
=
node
.
getRenderContainer
();
var
container
=
node
.
getRenderContainer
();
container
.
addShapes
(
[
rect
,
txt
]
);
container
.
addShapes
(
[
rect
,
txt
]
);
node
.
setData
(
"shape"
,
this
);
var
Layout
=
node
.
getData
(
"layout"
);
Layout
.
shape
=
this
;
var
ND
=
JSON
.
parse
(
JSON
.
stringify
(
nodeDefautStyle
)
);
var
ND
=
JSON
.
parse
(
JSON
.
stringify
(
nodeDefautStyle
)
);
node
.
setData
(
"style"
,
Utils
.
extend
(
ND
,
node
.
getData
(
"style"
)
)
);
Layout
.
style
=
Utils
.
extend
(
ND
,
Layout
.
style
);
var
_style
=
node
.
getData
(
"style"
)
;
var
_style
=
Layout
.
style
;
txt
.
setContent
(
node
.
getData
(
"text"
)
||
"新建节点"
).
setSize
(
_style
.
fontSize
).
fill
(
_style
.
color
);
txt
.
setContent
(
node
.
getData
(
"text"
)
||
"新建节点"
).
setSize
(
_style
.
fontSize
).
fill
(
_style
.
color
);
var
_txtHeight
=
txt
.
getHeight
();
var
_txtHeight
=
txt
.
getHeight
();
txt
.
translate
(
_style
.
padding
[
3
],
_txtHeight
+
_style
.
padding
[
0
]
);
txt
.
translate
(
_style
.
padding
[
3
],
_txtHeight
+
_style
.
padding
[
0
]
);
...
@@ -167,7 +168,7 @@ KityMinder.registerModule( "LayoutDefault", function () {
...
@@ -167,7 +168,7 @@ KityMinder.registerModule( "LayoutDefault", function () {
var
node
=
this
.
_node
;
var
node
=
this
.
_node
;
var
txt
=
this
.
_txt
;
var
txt
=
this
.
_txt
;
var
rect
=
this
.
_rect
;
var
rect
=
this
.
_rect
;
var
_style
=
node
.
getData
(
"
style"
)
;
var
_style
=
node
.
getData
(
"
layout"
).
style
;
txt
.
setContent
(
node
.
getData
(
"text"
)
||
"新建节点"
).
setSize
(
_style
.
fontSize
).
fill
(
_style
.
color
);
txt
.
setContent
(
node
.
getData
(
"text"
)
||
"新建节点"
).
setSize
(
_style
.
fontSize
).
fill
(
_style
.
color
);
var
_txtHeight
=
txt
.
getHeight
();
var
_txtHeight
=
txt
.
getHeight
();
var
_rectWidth
=
_style
.
padding
[
1
]
+
_style
.
padding
[
3
]
+
txt
.
getWidth
();
var
_rectWidth
=
_style
.
padding
[
1
]
+
_style
.
padding
[
3
]
+
txt
.
getWidth
();
...
@@ -184,18 +185,19 @@ KityMinder.registerModule( "LayoutDefault", function () {
...
@@ -184,18 +185,19 @@ KityMinder.registerModule( "LayoutDefault", function () {
var
root
=
this
.
getRoot
();
var
root
=
this
.
getRoot
();
//更新连线
//更新连线
var
updateConnect
=
function
(
minder
,
node
,
action
)
{
var
updateConnect
=
function
(
minder
,
node
,
action
)
{
var
_style
=
node
.
getData
(
"style"
);
var
Layout
=
node
.
getData
(
"layout"
);
var
_style
=
Layout
.
style
;
if
(
!
node
.
getParent
()
)
return
false
;
if
(
!
node
.
getParent
()
)
return
false
;
var
start
=
node
.
getParent
().
getRenderContainer
();
var
start
=
node
.
getParent
().
getRenderContainer
();
var
end
=
node
.
getRenderContainer
();
var
end
=
node
.
getRenderContainer
();
var
_connect
=
node
.
getData
(
"connect"
)
;
var
_connect
=
Layout
.
connect
;
if
(
action
===
"remove"
)
{
if
(
action
===
"remove"
)
{
_connect
.
remove
();
_connect
.
remove
();
}
else
{
}
else
{
if
(
_connect
)
_connect
.
updateConnection
();
if
(
_connect
)
_connect
.
updateConnection
();
else
{
else
{
_connect
=
new
ConnectBezier
(
start
,
end
);
_connect
=
new
ConnectBezier
(
start
,
end
);
node
.
setData
(
"connect"
,
_connect
)
;
Layout
.
connect
=
_connect
;
minder
.
getRenderContainer
().
addShape
(
_connect
);
minder
.
getRenderContainer
().
addShape
(
_connect
);
_connect
.
stroke
(
_style
.
stroke
);
_connect
.
stroke
(
_style
.
stroke
);
}
}
...
@@ -215,7 +217,7 @@ KityMinder.registerModule( "LayoutDefault", function () {
...
@@ -215,7 +217,7 @@ KityMinder.registerModule( "LayoutDefault", function () {
//绘制node
//绘制node
var
drawNode
=
function
(
node
)
{
var
drawNode
=
function
(
node
)
{
var
container
=
node
.
getRenderContainer
();
var
container
=
node
.
getRenderContainer
();
var
shape
=
node
.
getData
(
"
shape"
)
;
var
shape
=
node
.
getData
(
"
layout"
).
shape
;
if
(
!
shape
)
new
MinderNodeShape
(
node
);
if
(
!
shape
)
new
MinderNodeShape
(
node
);
else
shape
.
update
();
else
shape
.
update
();
updateConnect
(
minder
,
node
);
updateConnect
(
minder
,
node
);
...
@@ -227,34 +229,41 @@ KityMinder.registerModule( "LayoutDefault", function () {
...
@@ -227,34 +229,41 @@ KityMinder.registerModule( "LayoutDefault", function () {
if
(
!
parent
)
{
if
(
!
parent
)
{
return
effectSet
;
return
effectSet
;
}
}
var
_style
=
node
.
getData
(
"style"
);
var
Layout
=
node
.
getData
(
"layout"
);
var
_style
=
Layout
.
style
;
var
marginTop
=
_style
.
margin
[
0
],
var
marginTop
=
_style
.
margin
[
0
],
marginBottom
=
_style
.
margin
[
2
];
marginBottom
=
_style
.
margin
[
2
];
var
appendside
=
node
.
getData
(
"appendside"
)
;
var
appendside
=
Layout
.
appendside
;
var
branchheight
=
node
.
getData
(
"branchheight"
)
||
node
.
getRenderContainer
().
getHeight
()
+
marginTop
+
marginBottom
;
var
branchheight
=
Layout
.
branchheight
||
node
.
getRenderContainer
().
getHeight
()
+
marginTop
+
marginBottom
;
var
countY
=
function
(
node
,
appendside
)
{
var
countY
=
function
(
node
,
appendside
)
{
var
centerY
=
node
.
getData
(
"y"
);
var
nodeLayout
=
node
.
getData
(
"layout"
);
var
nodeBranchHeight
=
node
.
getData
(
appendside
+
"Height"
)
||
node
.
getData
(
"branchheight"
);
var
centerY
=
nodeLayout
.
y
;
var
nodeChildren
=
node
.
getData
(
appendside
+
"List"
)
||
node
.
getChildren
();
var
nodeBranchHeight
=
nodeLayout
[
appendside
+
"Height"
]
||
nodeLayout
.
branchheight
;
var
nodeChildren
=
nodeLayout
[
appendside
+
"List"
]
||
node
.
getChildren
();
var
sY
=
centerY
-
nodeBranchHeight
/
2
;
var
sY
=
centerY
-
nodeBranchHeight
/
2
;
if
(
nodeChildren
.
length
===
1
)
{
if
(
nodeChildren
.
length
===
1
)
{
nodeChildren
[
0
].
setData
(
"y"
,
centerY
);
var
childrenLayout
=
nodeChildren
[
0
].
getData
(
"layout"
);
childrenLayout
.
y
=
centerY
;
}
else
{
}
else
{
for
(
var
i
=
0
;
i
<
nodeChildren
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
nodeChildren
.
length
;
i
++
)
{
var
childBranchHeight
=
nodeChildren
[
i
].
getData
(
"branchheight"
);
var
childrenLayout1
=
nodeChildren
[
i
].
getData
(
"layout"
);
nodeChildren
[
i
].
setData
(
"y"
,
sY
+
marginTop
+
childBranchHeight
/
2
);
var
childBranchHeight
=
childrenLayout1
.
branchheight
;
childrenLayout1
.
y
=
sY
+
marginTop
+
childBranchHeight
/
2
;
sY
+=
childBranchHeight
;
sY
+=
childBranchHeight
;
}
}
}
}
return
nodeChildren
;
return
nodeChildren
;
};
};
node
.
setData
(
"branchheight"
,
branchheight
);
Layout
.
branchheight
=
branchheight
;
var
siblings
=
parent
.
getData
(
appendside
+
"List"
)
||
parent
.
getChildren
();
var
parentLayout
=
parent
.
getData
(
"layout"
);
var
siblings
=
parentLayout
[
appendside
+
"List"
]
||
parent
.
getChildren
();
var
getChildHeight
=
function
(
node
,
appendside
)
{
var
getChildHeight
=
function
(
node
,
appendside
)
{
var
sum
=
0
;
var
sum
=
0
;
var
children
=
node
.
getData
(
appendside
+
"List"
)
||
node
.
getChildren
();
var
nodeLayout
=
node
.
getData
(
"layout"
);
var
children
=
nodeLayout
[
appendside
+
"List"
]
||
node
.
getChildren
();
for
(
var
i
=
0
;
i
<
children
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
children
.
length
;
i
++
)
{
sum
+=
children
[
i
].
getData
(
"
branchheight"
)
;
sum
+=
children
[
i
].
getData
(
"
layout"
).
branchheight
;
}
}
return
sum
;
return
sum
;
};
};
...
@@ -267,11 +276,12 @@ KityMinder.registerModule( "LayoutDefault", function () {
...
@@ -267,11 +276,12 @@ KityMinder.registerModule( "LayoutDefault", function () {
var
minH
=
prt
.
getRenderContainer
().
getHeight
()
+
marginTop
+
marginBottom
;
var
minH
=
prt
.
getRenderContainer
().
getHeight
()
+
marginTop
+
marginBottom
;
var
childH
=
getChildHeight
(
prt
,
appendside
);
var
childH
=
getChildHeight
(
prt
,
appendside
);
var
branchH
=
(
minH
>
childH
?
minH
:
childH
);
var
branchH
=
(
minH
>
childH
?
minH
:
childH
);
var
prtLayout
=
prt
.
getData
(
"layout"
);
if
(
prt
.
getParent
()
)
{
if
(
prt
.
getParent
()
)
{
prt
.
setData
(
"branchheight"
,
branchH
)
;
prt
Layout
.
branchheight
=
branchH
;
}
else
{
}
else
{
prt
.
setData
(
appendside
+
"Height"
,
branchH
)
;
prt
Layout
[
appendside
+
"Height"
]
=
branchH
;
}
}
prt
=
prt
.
getParent
();
prt
=
prt
.
getParent
();
}
while
(
prt
);
}
while
(
prt
);
...
@@ -295,21 +305,23 @@ KityMinder.registerModule( "LayoutDefault", function () {
...
@@ -295,21 +305,23 @@ KityMinder.registerModule( "LayoutDefault", function () {
var
selfWidth
=
node
.
getRenderContainer
().
getWidth
();
var
selfWidth
=
node
.
getRenderContainer
().
getWidth
();
var
countX
=
function
(
n
)
{
var
countX
=
function
(
n
)
{
var
nLayout
=
n
.
getData
(
"layout"
);
var
prt
=
n
.
getParent
();
var
prt
=
n
.
getParent
();
var
parentX
=
prt
.
getData
(
"x"
);
var
prtLayout
=
prt
.
getData
(
"layout"
);
var
parentX
=
prtLayout
.
x
;
var
parentWidth
=
prt
.
getRenderContainer
().
getWidth
();
var
parentWidth
=
prt
.
getRenderContainer
().
getWidth
();
var
parentAlign
=
prt
.
getData
(
"align"
)
;
var
parentAlign
=
prt
Layout
.
align
;
var
selfAppendSide
=
n
.
getData
(
"appendside"
)
;
var
selfAppendSide
=
n
Layout
.
appendside
;
if
(
parentAlign
===
"center"
)
parentWidth
=
parentWidth
/
2
;
if
(
parentAlign
===
"center"
)
parentWidth
=
parentWidth
/
2
;
var
_style
=
n
ode
.
getData
(
"style"
)
;
var
_style
=
n
Layout
.
style
;
var
marginLeft
=
_style
.
margin
[
3
];
var
marginLeft
=
_style
.
margin
[
3
];
var
marginRight
=
_style
.
margin
[
1
];
var
marginRight
=
_style
.
margin
[
1
];
switch
(
selfAppendSide
)
{
switch
(
selfAppendSide
)
{
case
"left"
:
case
"left"
:
n
.
setData
(
"x"
,
parentX
-
parentWidth
-
marginLeft
-
marginRight
)
;
n
Layout
.
x
=
parentX
-
parentWidth
-
marginLeft
-
marginRight
;
break
;
break
;
case
"right"
:
case
"right"
:
n
.
setData
(
"x"
,
parentX
+
parentWidth
+
marginLeft
+
marginRight
)
;
n
Layout
.
x
=
parentX
+
parentWidth
+
marginLeft
+
marginRight
;
break
;
break
;
default
:
default
:
break
;
break
;
...
@@ -333,19 +345,20 @@ KityMinder.registerModule( "LayoutDefault", function () {
...
@@ -333,19 +345,20 @@ KityMinder.registerModule( "LayoutDefault", function () {
//调整node的位置
//调整node的位置
var
translateNode
=
function
(
node
)
{
var
translateNode
=
function
(
node
)
{
var
Layout
=
node
.
getData
(
"layout"
);
var
nodeShape
=
node
.
getRenderContainer
();
var
nodeShape
=
node
.
getRenderContainer
();
var
align
=
node
.
getData
(
"align"
)
;
var
align
=
Layout
.
align
;
var
_rectHeight
=
nodeShape
.
getHeight
();
var
_rectHeight
=
nodeShape
.
getHeight
();
var
_rectWidth
=
nodeShape
.
getWidth
();
var
_rectWidth
=
nodeShape
.
getWidth
();
switch
(
align
)
{
switch
(
align
)
{
case
"right"
:
case
"right"
:
nodeShape
.
setTransform
(
new
kity
.
Matrix
().
translate
(
node
.
getData
(
"x"
)
-
_rectWidth
,
node
.
getData
(
"y"
)
-
_rectHeight
/
2
)
);
nodeShape
.
setTransform
(
new
kity
.
Matrix
().
translate
(
Layout
.
x
-
_rectWidth
,
Layout
.
y
-
_rectHeight
/
2
)
);
break
;
break
;
case
"center"
:
case
"center"
:
nodeShape
.
setTransform
(
new
kity
.
Matrix
().
translate
(
node
.
getData
(
"x"
)
-
_rectWidth
/
2
,
node
.
getData
(
"y"
)
-
_rectHeight
/
2
)
);
nodeShape
.
setTransform
(
new
kity
.
Matrix
().
translate
(
Layout
.
x
-
_rectWidth
/
2
,
Layout
.
y
-
_rectHeight
/
2
)
);
break
;
break
;
default
:
default
:
nodeShape
.
setTransform
(
new
kity
.
Matrix
().
translate
(
node
.
getData
(
"x"
),
node
.
getData
(
"y"
)
-
_rectHeight
/
2
)
);
nodeShape
.
setTransform
(
new
kity
.
Matrix
().
translate
(
Layout
.
x
,
Layout
.
y
-
_rectHeight
/
2
)
);
break
;
break
;
}
}
updateConnect
(
minder
,
node
);
updateConnect
(
minder
,
node
);
...
@@ -357,7 +370,8 @@ KityMinder.registerModule( "LayoutDefault", function () {
...
@@ -357,7 +370,8 @@ KityMinder.registerModule( "LayoutDefault", function () {
initStyle
:
function
()
{
initStyle
:
function
()
{
var
_root
=
this
.
getRoot
();
var
_root
=
this
.
getRoot
();
var
minder
=
this
;
var
minder
=
this
;
_root
.
setData
(
"style"
,
{
var
Layout
=
_root
.
getData
(
"layout"
);
Layout
.
style
=
{
radius
:
10
,
radius
:
10
,
fill
:
"orange"
,
fill
:
"orange"
,
stroke
:
"orange"
,
stroke
:
"orange"
,
...
@@ -365,23 +379,21 @@ KityMinder.registerModule( "LayoutDefault", function () {
...
@@ -365,23 +379,21 @@ KityMinder.registerModule( "LayoutDefault", function () {
padding
:
[
10
,
10
,
10
,
10
],
padding
:
[
10
,
10
,
10
,
10
],
fontSize
:
30
,
fontSize
:
30
,
margin
:
[
0
,
0
,
0
,
0
]
margin
:
[
0
,
0
,
0
,
0
]
}
)
;
};
_root
.
setData
(
"x"
,
minderWidth
/
2
)
;
Layout
.
x
=
minderWidth
/
2
;
_root
.
setData
(
"y"
,
minderHeight
/
2
)
;
Layout
.
y
=
minderHeight
/
2
;
_root
.
setData
(
"align"
,
"center"
)
;
Layout
.
align
=
"center"
;
if
(
!
_root
.
getData
(
"text"
)
)
_root
.
setData
(
"text"
,
"I am the root"
);
if
(
!
_root
.
getData
(
"text"
)
)
_root
.
setData
(
"text"
,
"I am the root"
);
Layout
.
appendside
=
"right"
;
_root
.
setData
(
"appendside"
,
"right"
);
Layout
.
leftList
=
[];
_root
.
setData
(
"leftList"
,
[]
);
Layout
.
rightList
=
[];
_root
.
setData
(
"rightList"
,
[]
);
var
_rootRenderContainer
=
_root
.
getRenderContainer
();
var
_rootRenderContainer
=
_root
.
getRenderContainer
();
_root
.
setData
(
"leftHeight"
,
_rootRenderContainer
.
getHeight
()
);
var
rootHeight
=
_rootRenderContainer
.
getHeight
();
_root
.
setData
(
"rightHeight"
,
_rootRenderContainer
.
getHeight
()
);
Layout
.
leftHeight
=
Layout
.
rightHeight
=
rootHeight
;
drawNode
(
_root
);
drawNode
(
_root
);
translateNode
(
_root
);
translateNode
(
_root
);
//如果是从其他style切过来的,需要重新布局
//如果是从其他style切过来的,需要重新布局
var
_buffer
=
_root
.
getChildren
();
var
_buffer
=
_root
.
getChildren
();
while
(
_buffer
.
length
!==
0
)
{
while
(
_buffer
.
length
!==
0
)
{
...
@@ -392,6 +404,9 @@ KityMinder.registerModule( "LayoutDefault", function () {
...
@@ -392,6 +404,9 @@ KityMinder.registerModule( "LayoutDefault", function () {
}
}
},
},
appendChildNode
:
function
(
parent
,
node
,
index
)
{
appendChildNode
:
function
(
parent
,
node
,
index
)
{
if
(
!
node
.
getData
(
"layout"
)
)
node
.
setData
(
"layout"
,
{}
);
var
Layout
=
node
.
getData
(
"layout"
);
var
parentLayout
=
parent
.
getData
(
"layout"
);
var
minder
=
this
;
var
minder
=
this
;
if
(
parent
.
getChildren
().
indexOf
(
node
)
===
-
1
)
{
if
(
parent
.
getChildren
().
indexOf
(
node
)
===
-
1
)
{
if
(
!
index
)
parent
.
appendChild
(
node
);
if
(
!
index
)
parent
.
appendChild
(
node
);
...
@@ -399,28 +414,28 @@ KityMinder.registerModule( "LayoutDefault", function () {
...
@@ -399,28 +414,28 @@ KityMinder.registerModule( "LayoutDefault", function () {
minder
.
handelNodeInsert
(
node
);
minder
.
handelNodeInsert
(
node
);
}
}
if
(
parent
===
root
)
{
if
(
parent
===
root
)
{
var
leftList
=
parent
.
getData
(
"leftList"
)
;
var
leftList
=
parent
Layout
.
leftList
;
var
rightList
=
parent
.
getData
(
"rightList"
)
;
var
rightList
=
parent
Layout
.
rightList
;
var
sibling
=
parent
.
getChildren
();
var
sibling
=
parent
.
getChildren
();
var
aside
=
node
.
getData
(
"appendside"
)
;
var
aside
=
Layout
.
appendside
;
if
(
!
aside
)
{
if
(
!
aside
)
{
if
(
sibling
.
length
>
2
&&
rightList
.
length
>
leftList
.
length
)
{
if
(
sibling
.
length
>
2
&&
rightList
.
length
>
leftList
.
length
)
{
aside
=
"left"
;
aside
=
"left"
;
}
else
{
}
else
{
aside
=
"right"
;
aside
=
"right"
;
}
}
node
.
setData
(
"appendside"
,
aside
)
;
Layout
.
appendside
=
aside
;
}
}
parent
.
setData
(
"appendside"
,
aside
)
;
parent
Layout
.
appendside
=
aside
;
parent
.
getData
(
aside
+
"List"
)
.
push
(
node
);
parent
Layout
[
aside
+
"List"
]
.
push
(
node
);
}
}
var
appendside
=
parent
.
getData
(
"appendside"
)
;
var
appendside
=
parent
Layout
.
appendside
;
node
.
setData
(
"appendside"
,
appendside
)
;
Layout
.
appendside
=
appendside
;
if
(
appendside
===
"left"
)
{
if
(
appendside
===
"left"
)
{
node
.
setData
(
"align"
,
"right"
)
;
Layout
.
align
=
"right"
;
}
else
{
}
else
{
node
.
setData
(
"align"
,
"left"
)
;
Layout
.
align
=
"left"
;
}
}
drawNode
(
node
);
drawNode
(
node
);
var
set1
=
updateLayoutVertical
(
node
,
parent
,
"append"
);
var
set1
=
updateLayoutVertical
(
node
,
parent
,
"append"
);
...
@@ -430,11 +445,19 @@ KityMinder.registerModule( "LayoutDefault", function () {
...
@@ -430,11 +445,19 @@ KityMinder.registerModule( "LayoutDefault", function () {
translateNode
(
set
[
i
]
);
translateNode
(
set
[
i
]
);
}
}
},
},
updateLayout
:
function
(
node
)
{
var
prt
=
node
;
prt
.
preTraverse
(
function
(
n
)
{
}
);
},
appendSiblingNode
:
function
(
sibling
,
node
)
{
appendSiblingNode
:
function
(
sibling
,
node
)
{
var
siblingLayout
=
sibling
.
getData
(
"layout"
);
var
Layout
=
node
.
getData
(
"layout"
);
var
parent
=
sibling
.
getParent
();
var
parent
=
sibling
.
getParent
();
var
index
=
sibling
.
getIndex
()
+
1
;
var
index
=
sibling
.
getIndex
()
+
1
;
var
appendside
=
sibling
.
getData
(
"appendside"
)
;
var
appendside
=
sibling
Layout
.
appendside
;
node
.
setData
(
"appendside"
,
appendside
)
;
Layout
.
appendside
=
appendside
;
this
.
appendChildNode
(
parent
,
node
,
index
);
this
.
appendChildNode
(
parent
,
node
,
index
);
},
},
removeNode
:
function
(
nodes
)
{
removeNode
:
function
(
nodes
)
{
...
@@ -444,6 +467,7 @@ KityMinder.registerModule( "LayoutDefault", function () {
...
@@ -444,6 +467,7 @@ KityMinder.registerModule( "LayoutDefault", function () {
var
parent
=
nodes
[
i
].
getParent
();
var
parent
=
nodes
[
i
].
getParent
();
if
(
parent
)
{
if
(
parent
)
{
var
_buffer
=
[
nodes
[
i
]
];
var
_buffer
=
[
nodes
[
i
]
];
var
parentLayout
=
parent
.
getData
(
"layout"
);
while
(
_buffer
.
length
!==
0
)
{
while
(
_buffer
.
length
!==
0
)
{
_buffer
=
_buffer
.
concat
(
_buffer
[
0
].
getChildren
()
);
_buffer
=
_buffer
.
concat
(
_buffer
[
0
].
getChildren
()
);
_buffer
[
0
].
getRenderContainer
().
remove
();
_buffer
[
0
].
getRenderContainer
().
remove
();
...
@@ -451,8 +475,9 @@ KityMinder.registerModule( "LayoutDefault", function () {
...
@@ -451,8 +475,9 @@ KityMinder.registerModule( "LayoutDefault", function () {
_buffer
.
shift
();
_buffer
.
shift
();
}
}
if
(
parent
===
root
)
{
if
(
parent
===
root
)
{
var
appendside
=
nodes
[
i
].
getData
(
"appendside"
);
var
Layout
=
nodes
[
i
].
getData
(
"layout"
);
var
sideList
=
parent
.
getData
(
appendside
+
"List"
);
var
appendside
=
Layout
.
appendside
;
var
sideList
=
parentLayout
[
appendside
+
"List"
];
var
idx
=
sideList
.
indexOf
(
nodes
[
i
]
);
var
idx
=
sideList
.
indexOf
(
nodes
[
i
]
);
sideList
.
splice
(
idx
,
1
);
sideList
.
splice
(
idx
,
1
);
}
}
...
...
src/module/layout.green.backup.js
0 → 100644
View file @
ca60958e
KityMinder
.
registerModule
(
"LayoutGreen"
,
function
()
{
var
_target
=
this
.
getRenderTarget
();
var
minderWidth
=
_target
.
clientWidth
;
var
minderHeight
=
_target
.
clientHeight
;
var
minder
=
this
;
var
ConnectBezier
=
kity
.
createClass
(
"ConnectBezier"
,
(
function
()
{
function
mid
(
a
,
b
)
{
return
(
a
+
b
)
/
2
;
}
function
getSnapPoints
(
snaper
)
{
if
(
snaper
.
getSnapPoints
)
{
return
snaper
.
getSnapPoints
();
}
var
box
=
snaper
.
getRenderBox
();
var
x1
=
box
.
x
,
x2
=
box
.
x
+
box
.
width
,
y1
=
box
.
y
,
y2
=
box
.
y
+
box
.
height
,
xm
=
mid
(
x1
,
x2
),
ym
=
mid
(
y1
,
y2
);
return
[
{
x
:
xm
,
y
:
y1
,
type
:
'top'
},
// top
{
x
:
x2
,
y
:
ym
,
type
:
'right'
},
// right
{
x
:
xm
,
y
:
y2
,
type
:
'bottom'
},
// bottom
{
x
:
x1
,
y
:
ym
,
type
:
'left'
}
// left
];
}
var
DIR_NORMALS
=
{
top
:
new
kity
.
Vector
(
0
,
-
1
),
left
:
new
kity
.
Vector
(
-
1
,
0
),
bottom
:
new
kity
.
Vector
(
0
,
1
),
right
:
new
kity
.
Vector
(
1
,
0
)
};
function
fillNormal
(
snapPoint
)
{
if
(
snapPoint
.
normal
)
{
return
;
}
snapPoint
.
normal
=
DIR_NORMALS
[
snapPoint
.
type
]
||
DIR_NORMALS
.
left
;
}
return
{
base
:
kity
.
Bezier
,
constructor
:
function
(
start
,
end
)
{
this
.
callBase
();
this
.
setStartSnaper
(
start
);
this
.
setEndSnaper
(
end
);
this
.
init
();
this
.
updateConnection
();
},
init
:
function
()
{
this
.
addPoint
(
this
.
startBesierPoint
=
new
kity
.
BezierPoint
()
);
this
.
addPoint
(
this
.
endBesierPoint
=
new
kity
.
BezierPoint
()
);
},
bindSnaper
:
function
(
snaper
)
{
var
me
=
this
;
snaper
.
on
(
'shapeupdate'
,
function
()
{
me
.
updateConnection
();
}
);
},
setStartSnaper
:
function
(
snaper
)
{
this
.
start
=
snaper
;
this
.
bindSnaper
(
snaper
);
},
setEndSnaper
:
function
(
snaper
)
{
this
.
end
=
snaper
;
this
.
bindSnaper
(
snaper
);
},
isReady
:
function
()
{
return
!!
(
this
.
start
&&
this
.
end
);
},
calcEndPoints
:
function
()
{
var
startEnds
=
getSnapPoints
(
this
.
start
),
endEnds
=
getSnapPoints
(
this
.
end
);
var
nearStart
,
nearEnd
,
minDistance
=
Number
.
MAX_VALUE
;
var
i
,
j
,
startEnd
,
endEnd
,
distance
;
// 寻找最近的粘附点
// 暴力解法:可优化但不必要,因为点集不会很大
for
(
i
=
0
;
i
<
startEnds
.
length
;
i
++
)
{
for
(
j
=
0
;
j
<
endEnds
.
length
;
j
++
)
{
distance
=
Math
.
abs
(
startEnds
[
i
].
x
-
endEnds
[
j
].
x
)
+
Math
.
abs
(
startEnds
[
i
].
y
-
endEnds
[
j
].
y
)
*
0.5
;
//Vector.fromPoints( startEnds[i], endEnds[j] ).length();
if
(
distance
<
minDistance
)
{
minDistance
=
distance
;
nearStart
=
startEnds
[
i
];
nearEnd
=
endEnds
[
j
];
}
}
}
return
{
start
:
nearStart
,
end
:
nearEnd
};
},
updateConnection
:
function
()
{
if
(
!
this
.
isReady
()
)
{
return
false
;
}
var
endPoints
=
this
.
calcEndPoints
(),
startEnd
=
endPoints
.
start
,
endEnd
=
endPoints
.
end
;
fillNormal
(
startEnd
);
fillNormal
(
endEnd
);
var
pointVector
=
kity
.
Vector
.
fromPoints
(
startEnd
,
endEnd
);
var
forward
=
kity
.
Vector
.
projection
(
pointVector
,
startEnd
.
normal
);
var
backward
=
kity
.
Vector
.
projection
(
kity
.
Vector
.
reverse
(
pointVector
),
endEnd
.
normal
);
forward
=
kity
.
Vector
.
multipy
(
forward
,
0.5
);
forward
=
kity
.
Vector
.
add
(
startEnd
,
forward
);
backward
=
kity
.
Vector
.
multipy
(
backward
,
0.5
);
backward
=
kity
.
Vector
.
add
(
endEnd
,
backward
);
this
.
startBesierPoint
.
setVertex
(
startEnd
.
x
,
startEnd
.
y
);
this
.
startBesierPoint
.
setForward
(
forward
.
x
,
forward
.
y
);
this
.
endBesierPoint
.
setVertex
(
endEnd
.
x
,
endEnd
.
y
);
this
.
endBesierPoint
.
setBackward
(
backward
.
x
,
backward
.
y
);
}
};
}
)()
);
var
nodeDefautStyle
=
{
radius
:
10
,
fill
:
"beige"
,
stroke
:
"orange"
,
strokeWidth
:
1
,
color
:
"black"
,
padding
:
[
5
,
10
,
5
,
10
],
fontSize
:
20
,
margin
:
[
50
,
5
,
0
,
5
]
};
var
MinderNodeShape
=
kity
.
createClass
(
"MinderNodeShape"
,
(
function
()
{
return
{
constructor
:
function
(
node
)
{
var
txt
=
this
.
_txt
=
new
kity
.
Text
();
var
rect
=
this
.
_rect
=
new
kity
.
Rect
();
this
.
_node
=
node
;
var
container
=
node
.
getRenderContainer
();
container
.
addShapes
(
[
rect
,
txt
]
);
node
.
setData
(
"shape"
,
this
);
var
ND
=
JSON
.
parse
(
JSON
.
stringify
(
nodeDefautStyle
)
);
node
.
setData
(
"style"
,
Utils
.
extend
(
ND
,
node
.
getData
(
"style"
)
)
);
var
_style
=
node
.
getData
(
"style"
);
txt
.
setContent
(
node
.
getData
(
"text"
)
||
"新建节点"
).
setSize
(
_style
.
fontSize
).
fill
(
_style
.
color
);
var
_txtHeight
=
txt
.
getHeight
();
txt
.
translate
(
_style
.
padding
[
3
],
_txtHeight
+
_style
.
padding
[
0
]
);
this
.
update
();
},
update
:
function
()
{
var
node
=
this
.
_node
;
var
txt
=
this
.
_txt
;
var
rect
=
this
.
_rect
;
var
_style
=
node
.
getData
(
"style"
);
txt
.
setContent
(
node
.
getData
(
"text"
)
||
"新建节点"
).
setSize
(
_style
.
fontSize
).
fill
(
_style
.
color
);
var
_txtHeight
=
txt
.
getHeight
();
var
_rectWidth
=
_style
.
padding
[
1
]
+
_style
.
padding
[
3
]
+
txt
.
getWidth
();
var
_rectHeight
=
_style
.
padding
[
0
]
+
_style
.
padding
[
2
]
+
_txtHeight
;
rect
.
fill
(
_style
.
fill
).
stroke
(
_style
.
stroke
).
setRadius
(
_style
.
radius
).
setWidth
(
_rectWidth
).
setHeight
(
_rectHeight
);
if
(
node
.
getData
(
"highlight"
)
)
{
rect
.
stroke
(
new
kity
.
Pen
(
"white"
,
3
)
);
}
else
{
rect
.
stroke
(
new
kity
.
Pen
(
_style
.
stroke
,
_style
.
strokeWidth
)
);
}
}
};
}
)()
);
var
root
=
this
.
getRoot
();
//更新连线
var
updateConnect
=
function
(
minder
,
node
,
action
)
{
var
_style
=
node
.
getData
(
"style"
);
if
(
!
node
.
getParent
()
)
return
false
;
var
start
=
node
.
getParent
().
getRenderContainer
();
var
end
=
node
.
getRenderContainer
();
var
_connect
=
node
.
getData
(
"connect"
);
if
(
action
===
"remove"
)
{
_connect
.
remove
();
}
else
{
if
(
_connect
)
_connect
.
updateConnection
();
else
{
_connect
=
new
ConnectBezier
(
start
,
end
);
node
.
setData
(
"connect"
,
_connect
);
minder
.
getRenderContainer
().
addShape
(
_connect
);
_connect
.
stroke
(
_style
.
stroke
);
}
}
};
//求并集
var
uSet
=
function
(
a
,
b
)
{
for
(
var
i
=
0
;
i
<
a
.
length
;
i
++
)
{
var
idx
=
b
.
indexOf
(
a
[
i
]
);
if
(
idx
!==
-
1
)
{
b
.
splice
(
idx
,
1
);
}
}
return
a
.
concat
(
b
);
};
//流程:绘制->计算Y坐标->计算X坐标->translate
//绘制node
var
drawNode
=
function
(
node
)
{
var
container
=
node
.
getRenderContainer
();
var
shape
=
node
.
getData
(
"shape"
);
if
(
!
shape
)
new
MinderNodeShape
(
node
);
else
shape
.
update
();
updateConnect
(
minder
,
node
);
};
//以某个节点为seed对整体高度进行更改计算
var
updateLayoutVertical
=
function
(
node
)
{
var
parent
=
node
.
getParent
();
var
effectSet
=
[];
var
parentHeight
=
parent
.
getRenderContainer
().
getHeight
();
var
_style
=
node
.
getData
(
"style"
);
var
parentY
=
parent
.
getData
(
"y"
);
var
marginTop
=
_style
.
margin
[
0
];
var
marginBottom
=
_style
.
margin
[
2
];
node
.
setData
(
"y"
,
parentY
+
parentHeight
/
2
+
marginTop
+
marginBottom
);
effectSet
.
push
(
node
);
return
effectSet
;
};
//以某个节点为seed对水平方向进行调整
var
updateLayoutHorizon
=
function
(
node
,
parent
)
{
var
effectSet
=
[];
var
_style
=
node
.
getData
(
"style"
);
var
marginLeft
=
_style
.
margin
[
3
];
var
marginRight
=
_style
.
margin
[
1
];
var
nodeWidth
=
node
.
getRenderContainer
().
getWidth
();
node
.
setData
(
"branchwidth"
,
nodeWidth
+
marginLeft
+
marginRight
);
var
prt
=
parent
;
while
(
prt
)
{
var
children
=
prt
.
getChildren
();
var
parentWidth
=
prt
.
getRenderContainer
().
getWidth
();
var
sum
=
0
;
for
(
var
i
=
0
;
i
<
children
.
length
;
i
++
)
{
sum
+=
children
[
i
].
getData
(
"branchwidth"
);
}
prt
.
setData
(
"branchwidth"
,
(
sum
>
parentWidth
?
sum
:
parentWidth
)
);
prt
.
setData
(
"childrenwidth"
,
sum
);
prt
=
prt
.
getParent
();
}
var
_buffer
=
[
root
];
while
(
_buffer
.
length
!==
0
)
{
var
childrenC
=
_buffer
[
0
].
getChildren
();
var
parentX
=
_buffer
[
0
].
getData
(
"x"
);
var
parentChildrenWidth
=
_buffer
[
0
].
getData
(
"childrenwidth"
);
var
sX
=
parentX
-
parentChildrenWidth
/
2
;
for
(
var
j
=
0
;
j
<
childrenC
.
length
;
j
++
)
{
childrenC
[
j
].
setData
(
"x"
,
sX
+
childrenC
[
j
].
getData
(
"branchwidth"
)
/
2
);
sX
+=
(
childrenC
[
j
].
getData
(
"branchwidth"
)
+
marginLeft
+
marginRight
);
}
_buffer
=
_buffer
.
concat
(
childrenC
);
effectSet
.
push
(
_buffer
[
0
]
);
_buffer
.
shift
();
}
return
effectSet
;
};
//调整node的位置
var
translateNode
=
function
(
node
)
{
var
_style
=
node
.
getData
(
"style"
);
var
nodeShape
=
node
.
getRenderContainer
();
var
align
=
node
.
getData
(
"align"
);
var
_rectHeight
=
nodeShape
.
getHeight
();
var
_rectWidth
=
nodeShape
.
getWidth
();
switch
(
align
)
{
case
"right"
:
nodeShape
.
setTransform
(
new
kity
.
Matrix
().
translate
(
node
.
getData
(
"x"
)
-
_rectWidth
,
node
.
getData
(
"y"
)
-
_rectHeight
/
2
)
);
break
;
case
"center"
:
nodeShape
.
setTransform
(
new
kity
.
Matrix
().
translate
(
node
.
getData
(
"x"
)
-
_rectWidth
/
2
,
node
.
getData
(
"y"
)
-
_rectHeight
/
2
)
);
break
;
default
:
nodeShape
.
setTransform
(
new
kity
.
Matrix
().
translate
(
node
.
getData
(
"x"
),
node
.
getData
(
"y"
)
-
_rectHeight
/
2
)
);
break
;
}
updateConnect
(
minder
,
node
);
};
var
_style
=
{
renderNode
:
function
(
node
)
{
drawNode
(
node
);
},
initStyle
:
function
()
{
var
_root
=
this
.
getRoot
();
var
minder
=
this
;
_root
.
setData
(
"style"
,
{
radius
:
20
,
fill
:
"darkgreen"
,
stroke
:
"orange"
,
color
:
"black"
,
padding
:
[
10
,
10
,
10
,
10
],
fontSize
:
30
,
margin
:
[
0
,
5
,
0
,
5
]
}
);
_root
.
setData
(
"x"
,
minderWidth
/
2
);
_root
.
setData
(
"y"
,
50
);
_root
.
setData
(
"align"
,
"center"
);
_root
.
setData
(
"text"
,
"I am the root"
);
var
_rootRenderContainer
=
_root
.
getRenderContainer
();
_root
.
setData
(
"leftHeight"
,
_rootRenderContainer
.
getHeight
()
);
_root
.
setData
(
"rightHeight"
,
_rootRenderContainer
.
getHeight
()
);
drawNode
(
_root
);
translateNode
(
_root
);
//如果是从其他style切过来的,需要重新布局
var
_buffer
=
_root
.
getChildren
();
while
(
_buffer
.
length
!==
0
)
{
_buffer
=
_buffer
.
concat
(
_buffer
[
0
].
getChildren
()
);
var
prt
=
_buffer
[
0
].
getParent
();
this
.
appendChildNode
(
prt
,
_buffer
[
0
]
);
_buffer
.
shift
();
}
},
appendChildNode
:
function
(
parent
,
node
,
index
)
{
var
minder
=
this
;
if
(
parent
.
getChildren
().
indexOf
(
node
)
===
-
1
)
{
if
(
!
index
)
parent
.
appendChild
(
node
);
else
parent
.
insertChild
(
node
,
index
);
minder
.
handelNodeInsert
(
node
);
}
drawNode
(
node
);
node
.
setData
(
"align"
,
"center"
);
//调整影响到的节点位置
var
set1
=
updateLayoutVertical
(
node
);
var
set2
=
updateLayoutHorizon
(
node
,
parent
);
var
set
=
uSet
(
set1
,
set2
);
for
(
var
i
=
0
;
i
<
set
.
length
;
i
++
)
{
translateNode
(
set
[
i
]
);
}
},
appendSiblingNode
:
function
(
sibling
,
node
)
{
var
parent
=
sibling
.
getParent
();
var
index
=
sibling
.
getIndex
()
+
1
;
var
appendside
=
sibling
.
getData
(
"appendside"
);
node
.
setData
(
"appendside"
,
appendside
);
this
.
appendChildNode
(
parent
,
node
,
index
);
},
removeNode
:
function
(
nodes
)
{
var
root
=
this
.
getRoot
();
var
minder
=
this
;
for
(
var
i
=
0
;
i
<
nodes
.
length
;
i
++
)
{
var
parent
=
nodes
[
i
].
getParent
();
if
(
parent
)
{
nodes
[
i
].
getRenderContainer
().
remove
();
updateConnect
(
minder
,
nodes
[
i
],
"remove"
);
parent
.
removeChild
(
nodes
[
i
]
);
}
}
},
updateLayout
:
function
(
node
)
{
}
};
this
.
addLayoutStyle
(
"green"
,
_style
);
return
{};
}
);
\ No newline at end of file
src/module/layout.green.js
View file @
ca60958e
...
@@ -138,13 +138,13 @@ KityMinder.registerModule( "LayoutGreen", function () {
...
@@ -138,13 +138,13 @@ KityMinder.registerModule( "LayoutGreen", function () {
}
)()
);
}
)()
);
var
nodeDefautStyle
=
{
var
nodeDefautStyle
=
{
radius
:
10
,
radius
:
10
,
fill
:
"
beige
"
,
fill
:
"
green
"
,
stroke
:
"orange"
,
stroke
:
"orange"
,
strokeWidth
:
1
,
strokeWidth
:
1
,
color
:
"black"
,
color
:
"black"
,
padding
:
[
5
,
10
,
5
,
10
],
padding
:
[
5
,
10
,
5
,
10
],
fontSize
:
20
,
fontSize
:
20
,
margin
:
[
50
,
5
,
0
,
5
]
margin
:
[
0
,
10
,
10
,
50
]
};
};
var
MinderNodeShape
=
kity
.
createClass
(
"MinderNodeShape"
,
(
function
()
{
var
MinderNodeShape
=
kity
.
createClass
(
"MinderNodeShape"
,
(
function
()
{
return
{
return
{
...
@@ -154,10 +154,11 @@ KityMinder.registerModule( "LayoutGreen", function () {
...
@@ -154,10 +154,11 @@ KityMinder.registerModule( "LayoutGreen", function () {
this
.
_node
=
node
;
this
.
_node
=
node
;
var
container
=
node
.
getRenderContainer
();
var
container
=
node
.
getRenderContainer
();
container
.
addShapes
(
[
rect
,
txt
]
);
container
.
addShapes
(
[
rect
,
txt
]
);
node
.
setData
(
"shape"
,
this
);
var
Layout
=
node
.
getData
(
"layout"
);
Layout
.
shape
=
this
;
var
ND
=
JSON
.
parse
(
JSON
.
stringify
(
nodeDefautStyle
)
);
var
ND
=
JSON
.
parse
(
JSON
.
stringify
(
nodeDefautStyle
)
);
node
.
setData
(
"style"
,
Utils
.
extend
(
ND
,
node
.
getData
(
"style"
)
)
);
Layout
.
style
=
Utils
.
extend
(
ND
,
Layout
.
style
);
var
_style
=
node
.
getData
(
"style"
)
;
var
_style
=
Layout
.
style
;
txt
.
setContent
(
node
.
getData
(
"text"
)
||
"新建节点"
).
setSize
(
_style
.
fontSize
).
fill
(
_style
.
color
);
txt
.
setContent
(
node
.
getData
(
"text"
)
||
"新建节点"
).
setSize
(
_style
.
fontSize
).
fill
(
_style
.
color
);
var
_txtHeight
=
txt
.
getHeight
();
var
_txtHeight
=
txt
.
getHeight
();
txt
.
translate
(
_style
.
padding
[
3
],
_txtHeight
+
_style
.
padding
[
0
]
);
txt
.
translate
(
_style
.
padding
[
3
],
_txtHeight
+
_style
.
padding
[
0
]
);
...
@@ -167,7 +168,7 @@ KityMinder.registerModule( "LayoutGreen", function () {
...
@@ -167,7 +168,7 @@ KityMinder.registerModule( "LayoutGreen", function () {
var
node
=
this
.
_node
;
var
node
=
this
.
_node
;
var
txt
=
this
.
_txt
;
var
txt
=
this
.
_txt
;
var
rect
=
this
.
_rect
;
var
rect
=
this
.
_rect
;
var
_style
=
node
.
getData
(
"
style"
)
;
var
_style
=
node
.
getData
(
"
layout"
).
style
;
txt
.
setContent
(
node
.
getData
(
"text"
)
||
"新建节点"
).
setSize
(
_style
.
fontSize
).
fill
(
_style
.
color
);
txt
.
setContent
(
node
.
getData
(
"text"
)
||
"新建节点"
).
setSize
(
_style
.
fontSize
).
fill
(
_style
.
color
);
var
_txtHeight
=
txt
.
getHeight
();
var
_txtHeight
=
txt
.
getHeight
();
var
_rectWidth
=
_style
.
padding
[
1
]
+
_style
.
padding
[
3
]
+
txt
.
getWidth
();
var
_rectWidth
=
_style
.
padding
[
1
]
+
_style
.
padding
[
3
]
+
txt
.
getWidth
();
...
@@ -184,18 +185,19 @@ KityMinder.registerModule( "LayoutGreen", function () {
...
@@ -184,18 +185,19 @@ KityMinder.registerModule( "LayoutGreen", function () {
var
root
=
this
.
getRoot
();
var
root
=
this
.
getRoot
();
//更新连线
//更新连线
var
updateConnect
=
function
(
minder
,
node
,
action
)
{
var
updateConnect
=
function
(
minder
,
node
,
action
)
{
var
_style
=
node
.
getData
(
"style"
);
var
Layout
=
node
.
getData
(
"layout"
);
var
_style
=
Layout
.
style
;
if
(
!
node
.
getParent
()
)
return
false
;
if
(
!
node
.
getParent
()
)
return
false
;
var
start
=
node
.
getParent
().
getRenderContainer
();
var
start
=
node
.
getParent
().
getRenderContainer
();
var
end
=
node
.
getRenderContainer
();
var
end
=
node
.
getRenderContainer
();
var
_connect
=
node
.
getData
(
"connect"
)
;
var
_connect
=
Layout
.
connect
;
if
(
action
===
"remove"
)
{
if
(
action
===
"remove"
)
{
_connect
.
remove
();
_connect
.
remove
();
}
else
{
}
else
{
if
(
_connect
)
_connect
.
updateConnection
();
if
(
_connect
)
_connect
.
updateConnection
();
else
{
else
{
_connect
=
new
ConnectBezier
(
start
,
end
);
_connect
=
new
ConnectBezier
(
start
,
end
);
node
.
setData
(
"connect"
,
_connect
)
;
Layout
.
connect
=
_connect
;
minder
.
getRenderContainer
().
addShape
(
_connect
);
minder
.
getRenderContainer
().
addShape
(
_connect
);
_connect
.
stroke
(
_style
.
stroke
);
_connect
.
stroke
(
_style
.
stroke
);
}
}
...
@@ -215,79 +217,148 @@ KityMinder.registerModule( "LayoutGreen", function () {
...
@@ -215,79 +217,148 @@ KityMinder.registerModule( "LayoutGreen", function () {
//绘制node
//绘制node
var
drawNode
=
function
(
node
)
{
var
drawNode
=
function
(
node
)
{
var
container
=
node
.
getRenderContainer
();
var
container
=
node
.
getRenderContainer
();
var
shape
=
node
.
getData
(
"
shape"
)
;
var
shape
=
node
.
getData
(
"
layout"
).
shape
;
if
(
!
shape
)
new
MinderNodeShape
(
node
);
if
(
!
shape
)
new
MinderNodeShape
(
node
);
else
shape
.
update
();
else
shape
.
update
();
updateConnect
(
minder
,
node
);
updateConnect
(
minder
,
node
);
};
};
//以某个节点为seed对整体高度进行更改计算
//以某个节点为seed对整体高度进行更改计算
var
updateLayoutVertical
=
function
(
node
)
{
var
updateLayoutVertical
=
function
(
node
,
parent
,
action
)
{
var
parent
=
node
.
getParent
();
var
effectSet
=
[
node
];
//用于返回受影响的节点集
var
effectSet
=
[];
if
(
!
parent
)
{
var
parentHeight
=
parent
.
getRenderContainer
().
getHeight
();
var
_style
=
node
.
getData
(
"style"
);
var
parentY
=
parent
.
getData
(
"y"
);
var
marginTop
=
_style
.
margin
[
0
];
var
marginBottom
=
_style
.
margin
[
2
];
node
.
setData
(
"y"
,
parentY
+
parentHeight
/
2
+
marginTop
+
marginBottom
);
effectSet
.
push
(
node
);
return
effectSet
;
return
effectSet
;
}
var
Layout
=
node
.
getData
(
"layout"
);
var
_style
=
Layout
.
style
;
var
marginTop
=
_style
.
margin
[
0
],
marginBottom
=
_style
.
margin
[
2
];
var
appendside
=
Layout
.
appendside
;
var
branchheight
=
Layout
.
branchheight
||
node
.
getRenderContainer
().
getHeight
()
+
marginTop
+
marginBottom
;
var
countY
=
function
(
node
,
appendside
)
{
var
nodeLayout
=
node
.
getData
(
"layout"
);
var
centerY
=
nodeLayout
.
y
;
var
nodeBranchHeight
=
nodeLayout
[
appendside
+
"Height"
]
||
nodeLayout
.
branchheight
;
var
nodeChildren
=
nodeLayout
[
appendside
+
"List"
]
||
node
.
getChildren
();
var
sY
=
centerY
-
nodeBranchHeight
/
2
;
if
(
nodeChildren
.
length
===
1
)
{
var
childrenLayout
=
nodeChildren
[
0
].
getData
(
"layout"
);
childrenLayout
.
y
=
centerY
;
}
else
{
for
(
var
i
=
0
;
i
<
nodeChildren
.
length
;
i
++
)
{
var
childrenLayout1
=
nodeChildren
[
i
].
getData
(
"layout"
);
var
childBranchHeight
=
childrenLayout1
.
branchheight
;
childrenLayout1
.
y
=
sY
+
marginTop
+
childBranchHeight
/
2
;
sY
+=
childBranchHeight
;
}
}
return
nodeChildren
;
};
};
Layout
.
branchheight
=
branchheight
;
//以某个节点为seed对水平方向进行调整
var
parentLayout
=
parent
.
getData
(
"layout"
);
var
updateLayoutHorizon
=
function
(
node
,
parent
)
{
var
siblings
=
parentLayout
[
appendside
+
"List"
]
||
parent
.
getChildren
();
var
effectSet
=
[];
var
getChildHeight
=
function
(
node
,
appendside
)
{
var
_style
=
node
.
getData
(
"style"
);
var
marginLeft
=
_style
.
margin
[
3
];
var
marginRight
=
_style
.
margin
[
1
];
var
nodeWidth
=
node
.
getRenderContainer
().
getWidth
();
node
.
setData
(
"branchwidth"
,
nodeWidth
+
marginLeft
+
marginRight
);
var
prt
=
parent
;
while
(
prt
)
{
var
children
=
prt
.
getChildren
();
var
parentWidth
=
prt
.
getRenderContainer
().
getWidth
();
var
sum
=
0
;
var
sum
=
0
;
var
nodeLayout
=
node
.
getData
(
"layout"
);
var
children
=
nodeLayout
[
appendside
+
"List"
]
||
node
.
getChildren
();
for
(
var
i
=
0
;
i
<
children
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
children
.
length
;
i
++
)
{
sum
+=
children
[
i
].
getData
(
"branchwidth"
);
sum
+=
children
[
i
].
getData
(
"layout"
).
branchheight
;
}
return
sum
;
};
//方案:
//增加节点时:1.节点和大于1
//删除节点时:1.剩余节点和大于等于1
//更新branchheight
var
prt
=
parent
;
do
{
var
minH
=
prt
.
getRenderContainer
().
getHeight
()
+
marginTop
+
marginBottom
;
var
childH
=
getChildHeight
(
prt
,
appendside
);
var
branchH
=
(
minH
>
childH
?
minH
:
childH
);
var
prtLayout
=
prt
.
getData
(
"layout"
);
if
(
prt
.
getParent
()
)
{
prtLayout
.
branchheight
=
branchH
;
}
else
{
prtLayout
[
appendside
+
"Height"
]
=
branchH
;
}
}
prt
.
setData
(
"branchwidth"
,
(
sum
>
parentWidth
?
sum
:
parentWidth
)
);
prt
.
setData
(
"childrenwidth"
,
sum
);
prt
=
prt
.
getParent
();
prt
=
prt
.
getParent
();
}
while
(
prt
);
//遍历
var
effectRange
=
[
root
];
var
_buffer
=
effectRange
;
while
(
_buffer
.
length
!==
0
)
{
_buffer
=
_buffer
.
concat
(
countY
(
_buffer
[
0
],
appendside
)
);
effectSet
.
push
(
_buffer
[
0
]
);
_buffer
.
shift
();
}
return
effectSet
;
};
//以某个节点为seed对水平方向进行调整(包括调整子树)
var
updateLayoutHorizon
=
function
(
node
)
{
var
effectSet
=
[
node
];
//返回受影响(即需要进行下一步translate的节点)
var
parent
=
node
.
getParent
();
var
appendside
=
node
.
getData
(
"appendside"
);
var
selfWidth
=
node
.
getRenderContainer
().
getWidth
();
var
countX
=
function
(
n
)
{
var
nLayout
=
n
.
getData
(
"layout"
);
var
prt
=
n
.
getParent
();
var
prtLayout
=
prt
.
getData
(
"layout"
);
var
parentX
=
prtLayout
.
x
;
var
parentWidth
=
prt
.
getRenderContainer
().
getWidth
();
var
parentAlign
=
prtLayout
.
align
;
var
selfAppendSide
=
nLayout
.
appendside
;
if
(
parentAlign
===
"center"
)
parentWidth
=
parentWidth
/
2
;
var
_style
=
nLayout
.
style
;
var
marginLeft
=
_style
.
margin
[
3
];
var
marginRight
=
_style
.
margin
[
1
];
switch
(
selfAppendSide
)
{
case
"left"
:
nLayout
.
x
=
parentX
-
parentWidth
-
marginLeft
-
marginRight
;
break
;
case
"right"
:
nLayout
.
x
=
parentX
+
parentWidth
+
marginLeft
+
marginRight
;
break
;
default
:
break
;
}
};
//判断根据父节点位置定位还是自身已经带有位置属性
if
(
parent
)
{
countX
(
node
);
}
}
var
_buffer
=
[
root
];
//判断是否存在已绘制的孩子并对孩子位置进行调整(用于外部调用renderNode,如文本编时)
var
_buffer
=
node
.
getChildren
();
while
(
_buffer
.
length
!==
0
)
{
while
(
_buffer
.
length
!==
0
)
{
var
childrenC
=
_buffer
[
0
].
getChildren
();
countX
(
_buffer
[
0
]
);
var
parentX
=
_buffer
[
0
].
getData
(
"x"
);
var
parentChildrenWidth
=
_buffer
[
0
].
getData
(
"childrenwidth"
);
var
sX
=
parentX
-
parentChildrenWidth
/
2
;
for
(
var
j
=
0
;
j
<
childrenC
.
length
;
j
++
)
{
childrenC
[
j
].
setData
(
"x"
,
sX
+
childrenC
[
j
].
getData
(
"branchwidth"
)
/
2
);
sX
+=
(
childrenC
[
j
].
getData
(
"branchwidth"
)
+
marginLeft
+
marginRight
);
console
.
log
(
childrenC
[
j
].
getData
(
"branchwidth"
)
+
marginLeft
+
marginRight
);
}
_buffer
=
_buffer
.
concat
(
childrenC
);
effectSet
.
push
(
_buffer
[
0
]
);
effectSet
.
push
(
_buffer
[
0
]
);
_buffer
=
_buffer
.
concat
(
_buffer
[
0
].
getChildren
()
);
_buffer
.
shift
();
_buffer
.
shift
();
}
}
return
effectSet
;
return
effectSet
;
};
};
//调整node的位置
//调整node的位置
var
translateNode
=
function
(
node
)
{
var
translateNode
=
function
(
node
)
{
var
_style
=
node
.
getData
(
"style
"
);
var
Layout
=
node
.
getData
(
"layout
"
);
var
nodeShape
=
node
.
getRenderContainer
();
var
nodeShape
=
node
.
getRenderContainer
();
var
align
=
node
.
getData
(
"align"
)
;
var
align
=
Layout
.
align
;
var
_rectHeight
=
nodeShape
.
getHeight
();
var
_rectHeight
=
nodeShape
.
getHeight
();
var
_rectWidth
=
nodeShape
.
getWidth
();
var
_rectWidth
=
nodeShape
.
getWidth
();
switch
(
align
)
{
switch
(
align
)
{
case
"right"
:
case
"right"
:
nodeShape
.
setTransform
(
new
kity
.
Matrix
().
translate
(
node
.
getData
(
"x"
)
-
_rectWidth
,
node
.
getData
(
"y"
)
-
_rectHeight
/
2
)
);
nodeShape
.
setTransform
(
new
kity
.
Matrix
().
translate
(
Layout
.
x
-
_rectWidth
,
Layout
.
y
-
_rectHeight
/
2
)
);
break
;
break
;
case
"center"
:
case
"center"
:
nodeShape
.
setTransform
(
new
kity
.
Matrix
().
translate
(
node
.
getData
(
"x"
)
-
_rectWidth
/
2
,
node
.
getData
(
"y"
)
-
_rectHeight
/
2
)
);
nodeShape
.
setTransform
(
new
kity
.
Matrix
().
translate
(
Layout
.
x
-
_rectWidth
/
2
,
Layout
.
y
-
_rectHeight
/
2
)
);
break
;
break
;
default
:
default
:
nodeShape
.
setTransform
(
new
kity
.
Matrix
().
translate
(
node
.
getData
(
"x"
),
node
.
getData
(
"y"
)
-
_rectHeight
/
2
)
);
nodeShape
.
setTransform
(
new
kity
.
Matrix
().
translate
(
Layout
.
x
,
Layout
.
y
-
_rectHeight
/
2
)
);
break
;
break
;
}
}
updateConnect
(
minder
,
node
);
updateConnect
(
minder
,
node
);
...
@@ -299,30 +370,32 @@ KityMinder.registerModule( "LayoutGreen", function () {
...
@@ -299,30 +370,32 @@ KityMinder.registerModule( "LayoutGreen", function () {
initStyle
:
function
()
{
initStyle
:
function
()
{
var
_root
=
this
.
getRoot
();
var
_root
=
this
.
getRoot
();
var
minder
=
this
;
var
minder
=
this
;
_root
.
setData
(
"style"
,
{
var
Layout
=
_root
.
getData
(
"layout"
);
radius
:
20
,
Layout
.
style
=
{
fill
:
"darkgreen"
,
radius
:
10
,
fill
:
"orange"
,
stroke
:
"orange"
,
stroke
:
"orange"
,
color
:
"black"
,
color
:
"black"
,
padding
:
[
10
,
10
,
10
,
10
],
padding
:
[
10
,
10
,
10
,
10
],
fontSize
:
30
,
fontSize
:
30
,
margin
:
[
0
,
5
,
0
,
5
]
margin
:
[
0
,
0
,
0
,
0
]
}
);
};
_root
.
setData
(
"x"
,
minderWidth
/
2
);
Layout
.
x
=
minderWidth
/
2
;
_root
.
setData
(
"y"
,
50
);
Layout
.
y
=
minderHeight
/
2
;
_root
.
setData
(
"align"
,
"center"
);
Layout
.
align
=
"center"
;
_root
.
setData
(
"text"
,
"I am the root"
);
if
(
!
_root
.
getData
(
"text"
)
)
_root
.
setData
(
"text"
,
"I am the root"
);
Layout
.
appendside
=
"right"
;
Layout
.
leftList
=
[];
Layout
.
rightList
=
[];
var
_rootRenderContainer
=
_root
.
getRenderContainer
();
var
_rootRenderContainer
=
_root
.
getRenderContainer
();
_root
.
setData
(
"leftHeight"
,
_rootRenderContainer
.
getHeight
()
);
var
rootHeight
=
_rootRenderContainer
.
getHeight
();
_root
.
setData
(
"rightHeight"
,
_rootRenderContainer
.
getHeight
()
);
Layout
.
leftHeight
=
Layout
.
rightHeight
=
rootHeight
;
drawNode
(
_root
);
drawNode
(
_root
);
translateNode
(
_root
);
translateNode
(
_root
);
//如果是从其他style切过来的,需要重新布局
//如果是从其他style切过来的,需要重新布局
var
_buffer
=
_root
.
getChildren
();
var
_buffer
=
_root
.
getChildren
();
console
.
log
(
_buffer
);
while
(
_buffer
.
length
!==
0
)
{
while
(
_buffer
.
length
!==
0
)
{
_buffer
=
_buffer
.
concat
(
_buffer
[
0
].
getChildren
()
);
_buffer
=
_buffer
.
concat
(
_buffer
[
0
].
getChildren
()
);
var
prt
=
_buffer
[
0
].
getParent
();
var
prt
=
_buffer
[
0
].
getParent
();
...
@@ -331,28 +404,60 @@ KityMinder.registerModule( "LayoutGreen", function () {
...
@@ -331,28 +404,60 @@ KityMinder.registerModule( "LayoutGreen", function () {
}
}
},
},
appendChildNode
:
function
(
parent
,
node
,
index
)
{
appendChildNode
:
function
(
parent
,
node
,
index
)
{
if
(
!
node
.
getData
(
"layout"
)
)
node
.
setData
(
"layout"
,
{}
);
var
Layout
=
node
.
getData
(
"layout"
);
var
parentLayout
=
parent
.
getData
(
"layout"
);
var
minder
=
this
;
var
minder
=
this
;
if
(
parent
.
getChildren
().
indexOf
(
node
)
===
-
1
)
{
if
(
parent
.
getChildren
().
indexOf
(
node
)
===
-
1
)
{
if
(
!
index
)
parent
.
appendChild
(
node
);
if
(
!
index
)
parent
.
appendChild
(
node
);
else
parent
.
insertChild
(
node
,
index
);
else
parent
.
insertChild
(
node
,
index
);
minder
.
handelNodeInsert
(
node
);
minder
.
handelNodeInsert
(
node
);
}
}
if
(
parent
===
root
)
{
var
leftList
=
parentLayout
.
leftList
;
var
rightList
=
parentLayout
.
rightList
;
var
sibling
=
parent
.
getChildren
();
var
aside
=
Layout
.
appendside
;
if
(
!
aside
)
{
if
(
sibling
.
length
>
2
&&
rightList
.
length
>
leftList
.
length
)
{
aside
=
"left"
;
}
else
{
aside
=
"right"
;
}
Layout
.
appendside
=
aside
;
}
parentLayout
.
appendside
=
aside
;
parentLayout
[
aside
+
"List"
].
push
(
node
);
}
var
appendside
=
parentLayout
.
appendside
;
Layout
.
appendside
=
appendside
;
if
(
appendside
===
"left"
)
{
Layout
.
align
=
"right"
;
}
else
{
Layout
.
align
=
"left"
;
}
drawNode
(
node
);
drawNode
(
node
);
node
.
setData
(
"align"
,
"center"
);
var
set1
=
updateLayoutVertical
(
node
,
parent
,
"append"
);
//调整影响到的节点位置
var
set2
=
updateLayoutHorizon
(
node
);
var
set1
=
updateLayoutVertical
(
node
);
var
set2
=
updateLayoutHorizon
(
node
,
parent
);
var
set
=
uSet
(
set1
,
set2
);
var
set
=
uSet
(
set1
,
set2
);
console
.
log
(
set
);
for
(
var
i
=
0
;
i
<
set
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
set
.
length
;
i
++
)
{
translateNode
(
set
[
i
]
);
translateNode
(
set
[
i
]
);
}
}
},
},
updateLayout
:
function
(
node
)
{
var
prt
=
node
;
prt
.
preTraverse
(
function
(
n
)
{
}
);
},
appendSiblingNode
:
function
(
sibling
,
node
)
{
appendSiblingNode
:
function
(
sibling
,
node
)
{
var
siblingLayout
=
sibling
.
getData
(
"layout"
);
var
Layout
=
node
.
getData
(
"layout"
);
var
parent
=
sibling
.
getParent
();
var
parent
=
sibling
.
getParent
();
var
index
=
sibling
.
getIndex
()
+
1
;
var
index
=
sibling
.
getIndex
()
+
1
;
var
appendside
=
sibling
.
getData
(
"appendside"
)
;
var
appendside
=
sibling
Layout
.
appendside
;
node
.
setData
(
"appendside"
,
appendside
)
;
Layout
.
appendside
=
appendside
;
this
.
appendChildNode
(
parent
,
node
,
index
);
this
.
appendChildNode
(
parent
,
node
,
index
);
},
},
removeNode
:
function
(
nodes
)
{
removeNode
:
function
(
nodes
)
{
...
@@ -361,10 +466,28 @@ KityMinder.registerModule( "LayoutGreen", function () {
...
@@ -361,10 +466,28 @@ KityMinder.registerModule( "LayoutGreen", function () {
for
(
var
i
=
0
;
i
<
nodes
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
nodes
.
length
;
i
++
)
{
var
parent
=
nodes
[
i
].
getParent
();
var
parent
=
nodes
[
i
].
getParent
();
if
(
parent
)
{
if
(
parent
)
{
nodes
[
i
].
getRenderContainer
().
remove
();
var
_buffer
=
[
nodes
[
i
]
];
updateConnect
(
minder
,
nodes
[
i
],
"remove"
);
var
parentLayout
=
parent
.
getData
(
"layout"
);
while
(
_buffer
.
length
!==
0
)
{
_buffer
=
_buffer
.
concat
(
_buffer
[
0
].
getChildren
()
);
_buffer
[
0
].
getRenderContainer
().
remove
();
updateConnect
(
minder
,
_buffer
[
0
],
"remove"
);
_buffer
.
shift
();
}
if
(
parent
===
root
)
{
var
Layout
=
nodes
[
i
].
getData
(
"layout"
);
var
appendside
=
Layout
.
appendside
;
var
sideList
=
parentLayout
[
appendside
+
"List"
];
var
idx
=
sideList
.
indexOf
(
nodes
[
i
]
);
sideList
.
splice
(
idx
,
1
);
}
parent
.
removeChild
(
nodes
[
i
]
);
parent
.
removeChild
(
nodes
[
i
]
);
var
set
=
updateLayoutVertical
(
nodes
[
i
],
parent
,
"remove"
);
for
(
var
j
=
0
;
j
<
set
.
length
;
j
++
)
{
translateNode
(
set
[
j
]
);
}
}
}
minder
.
select
(
parent
);
}
}
}
}
};
};
...
...
src/module/layout.js
View file @
ca60958e
KityMinder
.
registerModule
(
"LayoutModule"
,
function
()
{
KityMinder
.
registerModule
(
"LayoutModule"
,
function
()
{
kity
.
extendClass
(
MinderNode
,
{
setLayout
:
function
(
k
,
v
)
{
if
(
this
.
setData
(
'layout'
)
===
undefined
)
{
this
.
setData
(
'layout'
,
{}
);
}
var
_pros
=
this
.
getLayout
();
Utils
.
extend
(
_pros
,
{
k
:
v
}
);
this
.
setData
(
'layout'
,
_pros
);
},
getLayout
:
function
(
k
)
{
if
(
k
===
undefined
)
{
return
this
.
getData
(
'layout'
);
}
return
this
.
getData
(
'layout'
)[
k
];
},
clearLayout
:
function
()
{
this
.
setData
(
'layout'
,
{}
);
this
.
getRenderContainer
().
clear
();
},
updateLayout
:
function
(
km
)
{
km
.
updateLayout
(
this
);
}
}
);
var
switchLayout
=
function
(
km
,
style
)
{
var
switchLayout
=
function
(
km
,
style
)
{
var
_style
=
km
.
getLayoutStyle
(
style
);
var
_style
=
km
.
getLayoutStyle
(
style
);
if
(
!
_style
)
return
false
;
if
(
!
_style
)
return
false
;
...
@@ -7,13 +32,11 @@ KityMinder.registerModule( "LayoutModule", function () {
...
@@ -7,13 +32,11 @@ KityMinder.registerModule( "LayoutModule", function () {
km
.
appendChildNode
=
_style
.
appendChildNode
;
km
.
appendChildNode
=
_style
.
appendChildNode
;
km
.
appendSiblingNode
=
_style
.
appendSiblingNode
;
km
.
appendSiblingNode
=
_style
.
appendSiblingNode
;
km
.
removeNode
=
_style
.
removeNode
;
km
.
removeNode
=
_style
.
removeNode
;
km
.
updateLayout
=
_style
.
updateLayout
;
//清空节点上附加的数据
//清空节点上附加的数据
var
_root
=
km
.
getRoot
();
var
_root
=
km
.
getRoot
();
_root
.
preTraverse
(
function
(
node
)
{
_root
.
preTraverse
(
function
(
node
)
{
node
.
setData
(
"style"
,
{}
);
node
.
clearLayout
();
node
.
setData
(
"shape"
,
null
);
node
.
getRenderContainer
().
clear
();
}
);
}
);
km
.
initStyle
();
km
.
initStyle
();
return
style
;
return
style
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment