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
7bb40a8f
Commit
7bb40a8f
authored
Jan 17, 2014
by
campaign
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/dev' into dev
parents
e4c96c31
d8902d2c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
256 additions
and
303 deletions
+256
-303
dev.html
demo/dev.html
+4
-0
layout.default.js
src/module/layout.default.js
+14
-5
layout.green.js
src/module/layout.green.js
+238
-298
No files found.
demo/dev.html
View file @
7bb40a8f
...
@@ -17,5 +17,9 @@
...
@@ -17,5 +17,9 @@
minder
=
KM
.
createMinder
(
kityminder
);
minder
=
KM
.
createMinder
(
kityminder
);
minder
.
execCommand
(
"switchlayout"
,
"default"
);
minder
.
execCommand
(
"switchlayout"
,
"default"
);
minder
.
execCommand
(
"appendchildnode"
,
new
MinderNode
());
minder
.
execCommand
(
"appendchildnode"
,
new
MinderNode
());
minder
.
execCommand
(
"appendsiblingnode"
,
new
MinderNode
());
minder
.
execCommand
(
"appendchildnode"
,
new
MinderNode
());
minder
.
execCommand
(
"appendsiblingnode"
,
new
MinderNode
());
minder
.
execCommand
(
"appendsiblingnode"
,
new
MinderNode
());
</script>
</script>
</html>
</html>
\ No newline at end of file
src/module/layout.default.js
View file @
7bb40a8f
...
@@ -140,6 +140,7 @@ KityMinder.registerModule( "LayoutDefault", function () {
...
@@ -140,6 +140,7 @@ KityMinder.registerModule( "LayoutDefault", function () {
radius
:
10
,
radius
:
10
,
fill
:
"skyblue"
,
fill
:
"skyblue"
,
stroke
:
"orange"
,
stroke
:
"orange"
,
strokeWidth
:
1
,
color
:
"black"
,
color
:
"black"
,
padding
:
[
5
,
10
,
5
,
10
],
padding
:
[
5
,
10
,
5
,
10
],
fontSize
:
20
,
fontSize
:
20
,
...
@@ -174,6 +175,8 @@ KityMinder.registerModule( "LayoutDefault", function () {
...
@@ -174,6 +175,8 @@ KityMinder.registerModule( "LayoutDefault", function () {
rect
.
fill
(
_style
.
fill
).
stroke
(
_style
.
stroke
).
setRadius
(
_style
.
radius
).
setWidth
(
_rectWidth
).
setHeight
(
_rectHeight
);
rect
.
fill
(
_style
.
fill
).
stroke
(
_style
.
stroke
).
setRadius
(
_style
.
radius
).
setWidth
(
_rectWidth
).
setHeight
(
_rectHeight
);
if
(
node
.
getData
(
"highlight"
)
)
{
if
(
node
.
getData
(
"highlight"
)
)
{
rect
.
stroke
(
new
kity
.
Pen
(
"white"
,
3
)
);
rect
.
stroke
(
new
kity
.
Pen
(
"white"
,
3
)
);
}
else
{
rect
.
stroke
(
new
kity
.
Pen
(
_style
.
stroke
,
_style
.
strokeWidth
)
);
}
}
}
}
};
};
...
@@ -216,6 +219,7 @@ KityMinder.registerModule( "LayoutDefault", function () {
...
@@ -216,6 +219,7 @@ KityMinder.registerModule( "LayoutDefault", function () {
else
shape
.
update
();
else
shape
.
update
();
updateConnect
(
minder
,
node
);
updateConnect
(
minder
,
node
);
};
};
//调整node的位置
//调整node的位置
var
translateNode
=
function
(
node
)
{
var
translateNode
=
function
(
node
)
{
var
_style
=
node
.
_style
;
var
_style
=
node
.
_style
;
...
@@ -375,6 +379,8 @@ KityMinder.registerModule( "LayoutDefault", function () {
...
@@ -375,6 +379,8 @@ KityMinder.registerModule( "LayoutDefault", function () {
//如果是从其他style切过来的,需要重新布局
//如果是从其他style切过来的,需要重新布局
if
(
children
.
length
!==
0
)
{
if
(
children
.
length
!==
0
)
{
_root
.
setData
(
"leftList"
,
[]
);
_root
.
setData
(
"rightList"
,
[]
);
var
leftList
=
_root
.
getData
(
"leftList"
);
var
leftList
=
_root
.
getData
(
"leftList"
);
var
rightList
=
_root
.
getData
(
"rightList"
);
var
rightList
=
_root
.
getData
(
"rightList"
);
for
(
var
i
=
0
;
i
<
children
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
children
.
length
;
i
++
)
{
...
@@ -385,10 +391,12 @@ KityMinder.registerModule( "LayoutDefault", function () {
...
@@ -385,10 +391,12 @@ KityMinder.registerModule( "LayoutDefault", function () {
leftList
.
push
(
children
[
i
]
);
leftList
.
push
(
children
[
i
]
);
children
[
i
].
setData
(
"appendside"
,
"left"
);
children
[
i
].
setData
(
"appendside"
,
"left"
);
}
}
drawNode
(
children
[
i
]
);
updateArrangement
(
children
[
i
]
);
}
}
}
}
},
},
appendChildNode
:
function
(
parent
,
node
)
{
appendChildNode
:
function
(
parent
,
node
,
index
)
{
var
appendside
=
parent
.
getData
(
"appendside"
);
var
appendside
=
parent
.
getData
(
"appendside"
);
if
(
parent
===
root
)
{
if
(
parent
===
root
)
{
var
leftList
=
parent
.
getData
(
"leftList"
);
var
leftList
=
parent
.
getData
(
"leftList"
);
...
@@ -403,21 +411,22 @@ KityMinder.registerModule( "LayoutDefault", function () {
...
@@ -403,21 +411,22 @@ KityMinder.registerModule( "LayoutDefault", function () {
node
.
setData
(
"appendside"
,
appendside
);
node
.
setData
(
"appendside"
,
appendside
);
parent
.
getData
(
appendside
+
"List"
).
push
(
node
);
parent
.
getData
(
appendside
+
"List"
).
push
(
node
);
}
}
node
.
setData
(
"appendside"
,
appendside
);
if
(
appendside
===
"left"
)
{
if
(
appendside
===
"left"
)
{
node
.
setData
(
"align"
,
"right"
);
node
.
setData
(
"align"
,
"right"
);
}
else
{
}
else
{
node
.
setData
(
"align"
,
"left"
);
node
.
setData
(
"align"
,
"left"
);
}
}
if
(
parent
.
getChildren
().
indexOf
(
node
)
===
-
1
)
parent
.
appendChild
(
node
);
if
(
parent
.
getChildren
().
indexOf
(
node
)
===
-
1
)
parent
.
appendChild
(
node
,
index
);
drawNode
(
node
);
drawNode
(
node
);
updateArrangement
(
node
,
"append"
);
updateArrangement
(
node
,
"append"
);
},
},
appendSiblingNode
:
function
(
sibling
,
node
)
{
appendSiblingNode
:
function
(
sibling
,
node
)
{
var
parent
=
sibling
.
getParent
();
var
parent
=
sibling
.
getParent
();
var
index
=
sibling
.
getIndex
()
+
1
;
var
index
=
sibling
.
getIndex
()
+
1
;
parent
.
appendChild
(
node
,
index
);
var
appendside
=
sibling
.
getData
(
"appendside"
);
drawNode
(
no
de
);
node
.
setData
(
"appendside"
,
appendsi
de
);
updateArrangement
(
node
,
"append"
);
this
.
appendChildNode
(
parent
,
node
,
index
);
},
},
removeNode
:
function
(
nodes
)
{
removeNode
:
function
(
nodes
)
{
var
root
=
this
.
getRoot
();
var
root
=
this
.
getRoot
();
...
...
src/module/layout.green.js
View file @
7bb40a8f
KityMinder
.
registerModule
(
"LayoutGreen"
,
function
()
{
KityMinder
.
registerModule
(
"LayoutGreen"
,
function
()
{
var
defaultHeight
=
35
;
var
_target
=
this
.
getRenderTarget
();
var
_target
=
this
.
getRenderTarget
();
var
minderWidth
=
_target
.
clientWidth
;
var
minderWidth
=
_target
.
clientWidth
;
var
minderHeight
=
_target
.
clientHeight
;
var
minderHeight
=
_target
.
clientHeight
;
var
minder
=
this
;
var
ConnectBezier
=
kity
.
createClass
(
"ConnectBezier"
,
(
function
()
{
var
ConnectBezier
=
kity
.
createClass
(
"ConnectBezier"
,
(
function
()
{
function
mid
(
a
,
b
)
{
function
mid
(
a
,
b
)
{
return
(
a
+
b
)
/
2
;
return
(
a
+
b
)
/
2
;
...
@@ -137,292 +136,216 @@ KityMinder.registerModule( "LayoutGreen", function () {
...
@@ -137,292 +136,216 @@ KityMinder.registerModule( "LayoutGreen", function () {
}
}
};
};
}
)()
);
}
)()
);
var
nodeDefautStyle
=
{
var
updateConnect
=
function
(
minder
,
nodes
,
action
)
{
radius
:
10
,
switch
(
action
)
{
fill
:
"green"
,
case
"rendernode"
:
stroke
:
"orange"
,
(
function
()
{
strokeWidth
:
1
,
if
(
!
(
nodes
instanceof
Array
)
)
{
color
:
"black"
,
nodes
=
[
nodes
];
padding
:
[
5
,
10
,
5
,
10
],
}
fontSize
:
20
,
for
(
var
i
=
0
;
i
<
nodes
.
length
;
i
++
)
{
margin
:
[
0
,
10
,
10
,
50
]
var
curnode
=
nodes
[
i
];
if
(
!
curnode
.
getParent
()
)
{
return
false
;
}
else
{
var
parent
=
curnode
.
getParent
();
var
connectExist
=
curnode
.
getData
(
"connect"
);
if
(
connectExist
)
{
connectExist
.
updateConnection
();
}
else
{
var
_connect
=
new
ConnectBezier
(
parent
.
getRenderContainer
(),
curnode
.
getRenderContainer
()
);
var
nodeD
=
curnode
.
getData
(
"style"
);
_connect
.
stroke
(
new
kity
.
Pen
(
nodeD
.
stroke
,
nodeD
.
strokeWidth
)
);
curnode
.
setData
(
"connect"
,
_connect
);
minder
.
getRenderContainer
().
addShape
(
_connect
);
}
}
}
}
)();
break
;
case
"removenode"
:
(
function
()
{
if
(
(
nodes
instanceof
Array
)
===
false
)
{
nodes
=
[
nodes
];
}
function
removeConnect
(
node
)
{
var
connect
=
node
.
_connect
;
if
(
connect
&&
connect
.
remove
)
{
connect
.
remove
();
}
}
for
(
var
i
=
0
;
i
<
nodes
.
length
;
i
++
)
{
nodes
[
i
].
traverse
(
removeConnect
);
}
}
)();
}
};
};
var
MinderNodeShape
=
kity
.
createClass
(
"MinderNodeShape"
,
(
function
()
{
var
updateBranchHeight
=
function
(
node
,
appendSide
,
root
,
isAdd
,
oldParent
)
{
return
{
var
siblings
=
(
function
()
{
constructor
:
function
(
node
)
{
if
(
!
isAdd
)
{
var
txt
=
this
.
_txt
=
new
kity
.
Text
();
return
oldParent
.
getChildren
();
var
rect
=
this
.
_rect
=
new
kity
.
Rect
();
}
else
if
(
parent
===
root
)
{
this
.
_node
=
node
;
return
root
.
getData
(
"layer"
+
appendSide
)[
1
];
var
container
=
node
.
getRenderContainer
();
}
else
{
container
.
addShapes
(
[
rect
,
txt
]
);
return
node
.
getParent
().
getChildren
();
node
.
setData
(
"shape"
,
this
);
}
var
ND
=
JSON
.
parse
(
JSON
.
stringify
(
nodeDefautStyle
)
);
}
)();
node
.
setData
(
"style"
,
Utils
.
extend
(
ND
,
node
.
getData
(
"style"
)
)
);
var
parent
=
isAdd
?
node
.
getParent
()
:
oldParent
;
var
_style
=
node
.
getData
(
"style"
);
node
.
setData
(
"branchheight"
,
defaultHeight
+
10
);
txt
.
setContent
(
node
.
getData
(
"text"
)
||
"新建节点"
).
setSize
(
_style
.
fontSize
).
fill
(
_style
.
color
);
if
(
isAdd
)
{
var
_txtHeight
=
txt
.
getHeight
();
var
add
=
(
(
siblings
.
length
===
1
&&
node
.
getParent
()
!==
root
)
?
0
:
(
defaultHeight
+
10
)
);
txt
.
translate
(
_style
.
padding
[
3
],
_txtHeight
+
_style
.
padding
[
0
]
);
while
(
parent
||
(
parent
===
root
)
)
{
this
.
update
();
var
branchheight
=
parent
.
getData
(
appendSide
+
"Height"
)
||
parent
.
getData
(
"branchheight"
)
||
0
;
},
if
(
parent
===
root
)
{
update
:
function
()
{
parent
.
setData
(
appendSide
+
"Height"
,
branchheight
+
add
);
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
{
}
else
{
parent
.
setData
(
"branchheight"
,
branchheight
+
add
);
rect
.
stroke
(
new
kity
.
Pen
(
_style
.
stroke
,
_style
.
strokeWidth
)
);
}
parent
=
parent
.
getParent
();
}
}
if
(
siblings
.
length
===
1
)
{
return
false
;
}
else
{
return
true
;
}
}
};
}
)()
);
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
{
}
else
{
var
dec
=
node
.
getData
(
"branchheight"
);
if
(
_connect
)
_connect
.
updateConnection
();
do
{
else
{
var
branchheight2
=
parent
.
getData
(
appendSide
+
"Height"
)
||
parent
.
getData
(
"branchheight"
)
||
0
;
_connect
=
new
ConnectBezier
(
start
,
end
);
if
(
parent
===
root
)
{
node
.
setData
(
"connect"
,
_connect
);
parent
.
setData
(
appendSide
+
"Height"
,
branchheight2
-
dec
);
minder
.
getRenderContainer
().
addShape
(
_connect
);
}
else
{
_connect
.
stroke
(
_style
.
stroke
);
parent
.
setData
(
"branchheight"
,
branchheight2
-
dec
);
}
}
parent
=
parent
.
getParent
();
}
while
(
parent
);
return
true
;
}
}
};
};
//求并集
var
uSet
=
function
(
a
,
b
)
{
var
reAnalyze
=
function
(
km
,
layerArray
,
appendSide
)
{
for
(
var
i
=
0
;
i
<
a
.
length
;
i
++
)
{
for
(
var
lv
=
0
;
lv
<
layerArray
.
length
;
lv
++
)
{
var
idx
=
b
.
indexOf
(
a
[
i
]
);
var
lvData
=
layerArray
[
lv
];
if
(
idx
!==
-
1
)
{
for
(
var
i
=
0
;
i
<
lvData
.
length
;
i
++
)
{
b
.
splice
(
idx
,
1
);
var
children
=
(
lv
===
0
?
layerArray
[
1
]
:
lvData
[
i
].
getChildren
()
);
if
(
!
children
||
children
.
length
===
0
)
continue
;
var
branchheight
=
lvData
[
i
].
getData
(
appendSide
+
"Height"
)
||
lvData
[
i
].
getData
(
"branchheight"
);
var
sY
=
lvData
[
i
].
getData
(
"y"
)
+
(
children
[
0
].
getData
(
"branchheight"
)
-
branchheight
)
/
2
;
for
(
var
j
=
0
;
j
<
children
.
length
;
j
++
)
{
children
[
j
].
setData
(
"y"
,
sY
);
var
part1
=
(
children
[
j
].
getData
(
"branchheight"
)
-
10
)
/
2
+
10
;
var
part2
=
(
children
[
j
+
1
]
?
(
children
[
j
+
1
].
getData
(
"branchheight"
)
-
10
)
/
2
:
0
);
sY
+=
(
part1
+
part2
);
}
km
.
renderNodes
(
children
);
}
}
}
}
return
a
.
concat
(
b
);
};
//绘制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
);
};
};
var
createChildNode
=
function
(
km
,
parent
,
index
)
{
var
root
=
km
.
getRoot
();
var
appendSide
=
parent
.
getData
(
"appendside"
);
var
_node
=
new
MinderNode
();
_node
.
setData
(
"branchheight"
,
0
);
parent
.
insertChild
(
_node
,
index
);
_node
.
setData
(
"appendside"
,
appendSide
);
var
parentX
=
parent
.
getData
(
"x"
);
var
parentWidth
=
parent
.
getRenderContainer
().
getWidth
();
if
(
parent
.
getData
(
"align"
)
===
"center"
)
parentWidth
=
parentWidth
/
2
;
switch
(
appendSide
)
{
//调整node的位置
case
"left"
:
var
translateNode
=
function
(
node
)
{
_node
.
setData
(
"x"
,
parentX
-
parentWidth
-
50
);
var
_style
=
node
.
_style
;
_node
.
setData
(
"align"
,
"right"
);
var
nodeShape
=
node
.
getRenderContainer
();
break
;
var
align
=
node
.
getData
(
"align"
);
var
_rectHeight
=
nodeShape
.
getHeight
();
var
_rectWidth
=
nodeShape
.
getWidth
();
switch
(
align
)
{
case
"right"
:
case
"right"
:
_node
.
setData
(
"x"
,
parentX
+
parentWidth
+
50
);
nodeShape
.
setTransform
(
new
kity
.
Matrix
().
translate
(
node
.
getData
(
"x"
)
-
_rectWidth
,
node
.
getData
(
"y"
)
-
_rectHeight
/
2
)
);
_node
.
setData
(
"align"
,
"left"
);
break
;
case
"center"
:
nodeShape
.
setTransform
(
new
kity
.
Matrix
().
translate
(
node
.
getData
(
"x"
)
-
_rectWidth
/
2
,
node
.
getData
(
"y"
)
-
_rectHeight
/
2
)
);
break
;
break
;
default
:
default
:
nodeShape
.
setTransform
(
new
kity
.
Matrix
().
translate
(
node
.
getData
(
"x"
),
node
.
getData
(
"y"
)
-
_rectHeight
/
2
)
);
break
;
break
;
}
}
updateConnect
(
minder
,
node
);
var
layer
=
parent
.
getData
(
"layer"
)
+
1
;
var
layerArray
=
root
.
getData
(
"layer"
+
appendSide
);
layerArray
[
layer
]
=
layerArray
[
layer
]
||
[];
var
layerData
=
layerArray
[
layer
];
var
insertPos
=
0
;
_node
.
setData
(
"layer"
,
layer
);
//遍历层级链
var
getIndexList
=
function
(
node
)
{
var
indexList
=
[];
var
parent
=
node
;
do
{
indexList
.
push
(
parent
.
getIndex
()
);
parent
=
parent
.
getParent
();
}
while
(
parent
);
return
indexList
.
reverse
();
};
};
//比较两个层级链的大小
//以某个节点为seed对整体高度进行更改计算
var
indexLarger
=
function
(
List1
,
List2
)
{
var
updateLayoutVertical
=
function
(
node
,
parent
,
action
)
{
var
larger
=
true
;
var
effectSet
=
[];
//用于返回受影响的节点集
for
(
var
i
=
0
;
i
<
List1
.
length
;
i
++
)
{
if
(
!
parent
)
{
if
(
List1
[
i
]
==
List2
[
i
]
)
{
return
[
node
];
continue
;
}
}
var
_style
=
node
.
getData
(
"style"
);
if
(
List1
[
i
]
<
List2
[
i
]
)
{
var
marginTop
=
_style
.
margin
[
0
],
larger
=
false
;
marginBottom
=
_style
.
margin
[
2
];
}
var
appendside
=
node
.
getData
(
"appendside"
);
break
;
var
branchheight
=
node
.
getData
(
"branchheight"
)
||
node
.
getRenderContainer
().
getHeight
()
+
marginTop
+
marginBottom
;
}
var
countY
=
function
(
node
,
appendside
)
{
return
larger
;
var
centerY
=
node
.
getData
(
"y"
);
var
nodeBranchHeight
=
node
.
getData
(
appendside
+
"Height"
)
||
node
.
getData
(
"branchheight"
);
var
nodeChildren
=
node
.
getData
(
appendside
+
"List"
)
||
node
.
getChildren
();
var
sY
=
centerY
-
nodeBranchHeight
/
2
;
for
(
var
i
=
0
;
i
<
nodeChildren
.
length
;
i
++
)
{
var
childBranchHeight
=
nodeChildren
[
i
].
getData
(
"branchheight"
);
nodeChildren
[
i
].
setData
(
"y"
,
sY
+
marginTop
+
childBranchHeight
/
2
);
sY
+=
childBranchHeight
;
}
return
nodeChildren
;
};
};
//选定合适的位置插入节点
if
(
action
!==
"remove"
)
{
for
(
var
l
=
layerData
.
length
-
1
;
l
>=
0
;
l
--
)
{
node
.
setData
(
"branchheight"
,
branchheight
);
var
nodeIndexList
=
getIndexList
(
_node
);
if
(
!
indexLarger
(
getIndexList
(
layerData
[
l
]
),
nodeIndexList
)
)
{
insertPos
=
l
+
1
;
break
;
}
}
layerData
.
splice
(
insertPos
,
0
,
_node
);
if
(
parent
===
root
)
{
var
leftCount
=
parent
.
getData
(
"layerleft"
);
var
rightCount
=
parent
.
getData
(
"layerright"
);
leftCount
=
leftCount
[
1
]
?
leftCount
[
1
].
length
:
0
;
rightCount
=
rightCount
[
1
]
?
rightCount
[
1
].
length
:
0
;
if
(
rightCount
>
leftCount
&&
rightCount
>
1
)
{
parent
.
setData
(
"appendside"
,
"left"
);
}
else
{
parent
.
setData
(
"appendside"
,
"right"
);
}
}
var
siblings
=
parent
.
getData
(
appendside
+
"List"
)
||
parent
.
getChildren
();
var
getChildHeight
=
function
(
node
,
appendside
)
{
var
sum
=
0
;
var
children
=
node
.
getData
(
appendside
+
"List"
)
||
node
.
getChildren
();
for
(
var
i
=
0
;
i
<
children
.
length
;
i
++
)
{
sum
+=
children
[
i
].
getData
(
"branchheight"
);
}
}
return
sum
;
};
//方案:
//增加节点时:1.节点和大于1
//删除节点时:1.剩余节点和大于等于1
if
(
(
action
===
"remove"
&&
siblings
.
length
>
0
)
||
siblings
.
length
>
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
reAnal
=
updateBranchHeight
(
_node
,
appendSide
,
root
,
true
);
if
(
prt
.
getParent
()
)
{
//判断是重绘全部还是只是添加节点
prt
.
setData
(
"branchheight"
,
branchH
);
if
(
reAnal
)
{
reAnalyze
(
km
,
layerArray
,
appendSide
);
}
else
{
}
else
{
_node
.
setData
(
"y"
,
_node
.
getParent
().
getData
(
"y"
)
);
prt
.
setData
(
appendside
+
"Height"
,
branchH
);
km
.
renderNode
(
_node
);
}
}
prt
=
prt
.
getParent
();
return
_node
;
}
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
();
}
}
else
if
(
action
!==
"remove"
)
{
node
.
setData
(
"y"
,
parent
.
getData
(
"y"
)
);
effectSet
=
[
node
];
}
return
effectSet
;
};
};
var
setX
=
function
(
node
)
{
//以某个节点为seed对水平方向进行调整
var
updateLayoutHorizon
=
function
(
node
)
{
var
effectSet
=
[];
if
(
!
node
.
getParent
()
)
{
return
[
node
];
}
node
.
preTraverse
(
function
(
n
)
{
var
_style
=
n
.
getData
(
"style"
);
var
parent
=
node
.
getParent
();
var
parent
=
node
.
getParent
();
if
(
!
parent
)
return
false
;
var
_parentStyle
=
parent
.
getData
(
"style"
)
;
var
parentX
=
parent
.
getData
(
"x"
);
var
parentX
=
parent
.
getData
(
"x"
);
var
parentAlign
=
parent
.
getData
(
"align"
);
var
parentWidth
=
parent
.
getRenderContainer
().
getWidth
();
var
parentWidth
=
parent
.
getRenderContainer
().
getWidth
();
if
(
parent
.
getData
(
"align"
)
===
"center"
)
{
if
(
parentAlign
===
"center"
)
parentWidth
=
parentWidth
/
2
;
parentWidth
=
parentWidth
/
2
;
var
selfAppendSide
=
n
.
getData
(
"appendside"
);
}
if
(
selfAppendSide
===
"right"
)
var
side
=
node
.
getData
(
"appendside"
);
n
.
setData
(
"x"
,
parentX
+
parentWidth
+
_style
.
margin
[
3
]
+
_parentStyle
.
margin
[
1
]
);
if
(
side
===
"left"
)
{
else
node
.
setData
(
"x"
,
parentX
-
parentWidth
-
50
);
n
.
setData
(
"x"
,
parentX
-
parentWidth
-
_style
.
margin
[
3
]
-
_parentStyle
.
margin
[
1
]
);
}
else
{
effectSet
.
push
(
n
);
node
.
setData
(
"x"
,
parentX
+
parentWidth
+
50
);
}
);
return
effectSet
;
};
var
updateArrangement
=
function
(
node
,
action
)
{
var
set1
=
updateLayoutHorizon
(
node
);
var
set2
=
updateLayoutVertical
(
node
,
node
.
getParent
(),
action
);
//获取水平方向和垂直方向受影响的点的并集然后进行统一translate
var
set
=
uSet
(
set1
,
set2
);
for
(
var
i
=
0
;
i
<
set
.
length
;
i
++
)
{
translateNode
(
set
[
i
]
);
}
}
};
};
var
_style
=
{
var
_style
=
{
renderNode
:
function
(
node
)
{
renderNode
:
function
(
node
)
{
var
km
=
this
;
drawNode
(
node
);
var
styledefault
=
{
radius
:
10
,
fill
:
"green"
,
stroke
:
"orange"
,
color
:
"black"
,
padding
:
[
5
,
10
,
5
,
10
],
fontSize
:
20
};
var
MinderNodeShape
=
kity
.
createClass
(
"MinderNodeShape"
,
(
function
()
{
return
{
constructor
:
function
(
container
)
{
this
.
rect
=
new
kity
.
Rect
();
this
.
text
=
new
kity
.
Text
();
this
.
shape
=
new
kity
.
Group
();
this
.
shape
.
addShapes
(
[
this
.
rect
,
this
.
text
]
);
container
.
addShape
(
this
.
shape
,
"nodeShape"
);
},
highlight
:
function
()
{
this
.
rect
.
stroke
(
new
kity
.
Pen
(
"white"
,
3
)
);
},
unhighlight
:
function
()
{
this
.
rect
.
stroke
(
this
.
NormalInfo
);
}
};
}
)()
);
var
kR
=
node
.
getRenderContainer
();
var
nodeShape
=
node
.
getData
(
"nodeshape"
)
||
new
MinderNodeShape
(
kR
);
node
.
setData
(
"nodeshape"
,
nodeShape
);
var
nd
=
JSON
.
parse
(
JSON
.
stringify
(
styledefault
)
);
var
nodeD
=
Utils
.
extend
(
nd
,
node
.
getData
(
"style"
)
);
node
.
setData
(
"style"
,
nodeD
);
var
_style
=
nodeD
;
nodeShape
.
text
.
setContent
(
node
.
getData
(
"text"
)
||
"Node"
)
.
setSize
(
nodeD
.
fontSize
)
.
fill
(
nodeD
.
color
);
var
txtWidth
=
nodeShape
.
text
.
getWidth
();
var
txtHeight
=
nodeShape
.
text
.
getHeight
();
var
_padding
=
_style
.
padding
;
var
_rectWidth
=
txtWidth
+
_padding
[
1
]
+
_padding
[
3
];
var
_rectHeight
=
txtHeight
+
_padding
[
0
]
+
_padding
[
2
];
nodeShape
.
text
.
setX
(
_padding
[
3
]
).
setY
(
_padding
[
0
]
+
txtHeight
);
nodeShape
.
NormalInfo
=
new
kity
.
Pen
(
_style
.
stroke
,
_style
.
strokeWidth
);
nodeShape
.
rect
.
setWidth
(
_rectWidth
).
setHeight
(
_rectHeight
).
stroke
(
nodeShape
.
NormalInfo
).
fill
(
_style
.
fill
).
setRadius
(
_style
.
radius
);
switch
(
node
.
getData
(
"align"
)
)
{
case
"center"
:
nodeShape
.
shape
.
setTransform
(
new
kity
.
Matrix
().
translate
(
node
.
getData
(
"x"
)
-
_rectWidth
/
2
,
node
.
getData
(
"y"
)
-
_rectHeight
/
2
)
);
break
;
case
"right"
:
nodeShape
.
shape
.
setTransform
(
new
kity
.
Matrix
().
translate
(
node
.
getData
(
"x"
)
-
_rectWidth
,
node
.
getData
(
"y"
)
-
_rectHeight
/
2
)
);
break
;
default
:
nodeShape
.
shape
.
setTransform
(
new
kity
.
Matrix
().
translate
(
node
.
getData
(
"x"
),
node
.
getData
(
"y"
)
-
_rectHeight
/
2
)
);
break
;
}
if
(
node
.
getData
(
"highlight"
)
)
{
nodeShape
.
highlight
();
}
else
{
nodeShape
.
unhighlight
();
}
updateConnect
(
this
,
node
,
"rendernode"
);
},
},
initStyle
:
function
()
{
initStyle
:
function
()
{
var
_root
=
this
.
getRoot
();
var
_root
=
this
.
getRoot
();
...
@@ -433,70 +356,87 @@ KityMinder.registerModule( "LayoutGreen", function () {
...
@@ -433,70 +356,87 @@ KityMinder.registerModule( "LayoutGreen", function () {
stroke
:
"orange"
,
stroke
:
"orange"
,
color
:
"black"
,
color
:
"black"
,
padding
:
[
10
,
10
,
10
,
10
],
padding
:
[
10
,
10
,
10
,
10
],
fontSize
:
30
fontSize
:
30
,
margin
:
[
0
,
0
,
0
,
0
]
}
);
}
);
_root
.
setData
(
"x"
,
minderWidth
/
2
);
_root
.
setData
(
"x"
,
minderWidth
/
2
);
_root
.
setData
(
"y"
,
minderHeight
/
2
);
_root
.
setData
(
"y"
,
minderHeight
/
2
);
_root
.
setData
(
"layer"
,
0
);
_root
.
setData
(
"layer"
,
0
);
_root
.
setData
(
"align"
,
"center"
);
_root
.
setData
(
"align"
,
"center"
);
_root
.
setData
(
"text"
,
"I am the root"
);
_root
.
setData
(
"text"
,
"I am the root"
);
//标记左子树和右子树的元素
_root
.
setData
(
"layerleft"
,
[
[
_root
]
]
);
_root
.
setData
(
"layerright"
,
[
[
_root
]
]
);
_root
.
setData
(
"indexList"
,
[
0
]
);
_root
.
setData
(
"leftHeight"
,
0
);
_root
.
setData
(
"rightHeight"
,
0
);
//标记根节点以及添加子树的方向
_root
.
setData
(
"appendside"
,
"right"
);
_root
.
setData
(
"appendside"
,
"right"
);
_root
.
preTraverse
(
function
(
node
)
{
var
children
=
_root
.
getChildren
();
minder
.
renderNode
(
node
);
_root
.
setData
(
"leftList"
,
[]
);
}
);
_root
.
setData
(
"rightList"
,
[]
);
},
createChildNode
:
function
(
parent
)
{
minder
.
renderNode
(
_root
);
return
createChildNode
(
this
,
parent
);
var
_rootRenderContainer
=
_root
.
getRenderContainer
();
_root
.
setData
(
"leftHeight"
,
_rootRenderContainer
.
getHeight
()
);
_root
.
setData
(
"rightHeight"
,
_rootRenderContainer
.
getHeight
()
);
updateArrangement
(
_root
);
//如果是从其他style切过来的,需要重新布局
if
(
children
.
length
!==
0
)
{
_root
.
setData
(
"leftList"
,
[]
);
_root
.
setData
(
"rightList"
,
[]
);
var
leftList
=
_root
.
getData
(
"leftList"
);
var
rightList
=
_root
.
getData
(
"rightList"
);
for
(
var
i
=
0
;
i
<
children
.
length
;
i
++
)
{
if
(
i
%
2
===
0
)
{
rightList
.
push
(
children
[
i
]
);
children
[
i
].
setData
(
"appendside"
,
"right"
);
}
else
{
leftList
.
push
(
children
[
i
]
);
children
[
i
].
setData
(
"appendside"
,
"left"
);
}
drawNode
(
children
[
i
]
);
updateArrangement
(
children
[
i
]
);
}
}
},
},
createSiblingNode
:
function
(
sibling
)
{
appendChildNode
:
function
(
parent
,
node
,
index
)
{
var
root
=
this
.
getRoot
();
var
appendside
=
parent
.
getData
(
"appendside"
);
var
parent
=
sibling
.
getParent
();
if
(
parent
===
root
)
{
if
(
parent
===
root
)
{
parent
.
setData
(
"appendside"
,
sibling
.
getData
(
"appendside"
)
);
var
leftList
=
parent
.
getData
(
"leftList"
);
var
rightList
=
parent
.
getData
(
"rightList"
);
var
sibling
=
parent
.
getChildren
();
if
(
sibling
.
length
>=
2
&&
rightList
.
length
>
leftList
.
length
)
{
appendside
=
"left"
;
}
else
{
appendside
=
"right"
;
}
}
var
index
=
sibling
.
getIndex
()
+
1
;
parent
.
setData
(
"appendside"
,
appendside
);
if
(
parent
)
{
node
.
setData
(
"appendside"
,
appendside
);
return
createChildNode
(
this
,
parent
,
index
);
parent
.
getData
(
appendside
+
"List"
).
push
(
node
);
}
node
.
setData
(
"appendside"
,
appendside
);
if
(
appendside
===
"left"
)
{
node
.
setData
(
"align"
,
"right"
);
}
else
{
}
else
{
return
false
;
node
.
setData
(
"align"
,
"left"
)
;
}
}
if
(
parent
.
getChildren
().
indexOf
(
node
)
===
-
1
)
parent
.
appendChild
(
node
,
index
);
drawNode
(
node
);
updateArrangement
(
node
,
"append"
);
},
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
)
{
removeNode
:
function
(
nodes
)
{
var
root
=
this
.
getRoot
();
var
root
=
this
.
getRoot
();
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
)
{
var
appendSide
=
nodes
[
i
].
getData
(
"appendside"
);
var
layer
=
nodes
[
i
].
getData
(
"layer"
);
parent
.
removeChild
(
nodes
[
i
]
);
parent
.
removeChild
(
nodes
[
i
]
);
var
layerArray
=
root
.
getData
(
"layer"
+
appendSide
);
var
layerData
=
layerArray
[
layer
];
//移除层结构中的node
for
(
var
j
=
0
;
j
<
layerData
.
length
;
j
++
)
{
if
(
layerData
[
j
]
===
nodes
[
i
]
)
{
layerData
.
splice
(
j
,
1
);
break
;
}
}
var
reAnal
=
updateBranchHeight
(
nodes
[
i
],
appendSide
,
root
,
false
,
parent
);
if
(
reAnal
)
{
reAnalyze
(
this
,
layerArray
,
appendSide
);
}
}
}
}
}
updateConnect
(
this
,
nodes
,
"removenode"
);
this
.
setContentChanged
(
true
);
}
}
};
};
this
.
addLayoutStyle
(
"green"
,
_style
);
this
.
addLayoutStyle
(
"green"
,
_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