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
e4c96c31
Commit
e4c96c31
authored
Jan 17, 2014
by
campaign
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' of
https://github.com/kitygraph/kityminder
into dev
parents
0e874edc
424e8b4b
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
301 additions
and
349 deletions
+301
-349
dev.html
demo/dev.html
+1
-0
dev.php
dist/dev.php
+1
-7
index.php
spec/index.php
+9
-0
minder.command.js
src/core/minder.command.js
+1
-1
minder.js
src/core/minder.js
+8
-0
minder.select.js
src/core/minder.select.js
+31
-29
layout.default.js
src/module/layout.default.js
+231
-300
layout.js
src/module/layout.js
+19
-12
No files found.
demo/dev.html
View file @
e4c96c31
...
@@ -16,5 +16,6 @@
...
@@ -16,5 +16,6 @@
<script>
<script>
minder
=
KM
.
createMinder
(
kityminder
);
minder
=
KM
.
createMinder
(
kityminder
);
minder
.
execCommand
(
"switchlayout"
,
"default"
);
minder
.
execCommand
(
"switchlayout"
,
"default"
);
minder
.
execCommand
(
"appendchildnode"
,
new
MinderNode
());
</script>
</script>
</html>
</html>
\ No newline at end of file
dist/dev.php
View file @
e4c96c31
...
@@ -13,18 +13,12 @@ $dependency = Array(
...
@@ -13,18 +13,12 @@ $dependency = Array(
'src/core/minder.module.js'
,
'src/core/minder.module.js'
,
'src/core/minder.command.js'
,
'src/core/minder.command.js'
,
'src/core/minder.node.js'
,
'src/core/minder.node.js'
,
'src/core/minder.select.js'
,
'src/module/history.js'
,
'src/module/history.js'
,
'src/module/icon.js'
,
'src/module/icon.js'
,
'src/module/layout.js'
,
'src/module/layout.js'
,
'src/module/layout.default.js'
,
'src/module/layout.default.js'
,
'src/module/layout.green.js'
,
'src/module/layout.green.js'
,
'src/module/mouse.js'
,
'src/core/minder.select.js'
,
'src/module/keyboard.js'
,
'src/module/editor.js'
,
'src/module/editor.cursor.js'
,
'src/module/editor.range.js'
,
'src/module/editor.receiver.js'
);
);
$content
=
""
;
$content
=
""
;
...
...
spec/index.php
0 → 100644
View file @
e4c96c31
<?php
/**
* Created by PhpStorm.
* User: dongyancen
* Date: 14-1-15
* Time: 下午6:50
*/
Header
(
'Location:../spec/tools/list.php'
);
?>
\ No newline at end of file
src/core/minder.command.js
View file @
e4c96c31
...
@@ -24,7 +24,7 @@ kity.extendClass( Minder, {
...
@@ -24,7 +24,7 @@ kity.extendClass( Minder, {
execCommand
:
function
(
name
)
{
execCommand
:
function
(
name
)
{
name
=
name
.
toLowerCase
();
name
=
name
.
toLowerCase
();
var
cmdArgs
=
utils
.
argsToArray
(
arguments
,
1
),
var
cmdArgs
=
Utils
.
argsToArray
(
arguments
,
1
),
cmd
,
stoped
,
result
,
eventParams
;
cmd
,
stoped
,
result
,
eventParams
;
var
me
=
this
;
var
me
=
this
;
cmd
=
this
.
_getCommand
(
name
);
cmd
=
this
.
_getCommand
(
name
);
...
...
src/core/minder.js
View file @
e4c96c31
...
@@ -15,6 +15,7 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
...
@@ -15,6 +15,7 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
constructor
:
function
(
options
)
{
constructor
:
function
(
options
)
{
this
.
_options
=
Utils
.
extend
(
window
.
KITYMINDER_CONFIG
||
{},
MinderDefaultOptions
,
options
);
this
.
_options
=
Utils
.
extend
(
window
.
KITYMINDER_CONFIG
||
{},
MinderDefaultOptions
,
options
);
this
.
_layoutStyles
=
{};
this
.
_layoutStyles
=
{};
this
.
_currentStyle
=
""
;
this
.
_initEvents
();
this
.
_initEvents
();
this
.
_initMinder
();
this
.
_initMinder
();
this
.
_initSelection
();
this
.
_initSelection
();
...
@@ -54,6 +55,13 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
...
@@ -54,6 +55,13 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
getLayoutStyle
:
function
(
name
)
{
getLayoutStyle
:
function
(
name
)
{
return
this
.
_layoutStyles
[
name
];
return
this
.
_layoutStyles
[
name
];
},
},
getCurrentStyle
:
function
()
{
return
this
.
_currentStyle
;
},
setCurrentStyle
:
function
(
name
)
{
this
.
_currentStyle
=
name
;
return
name
;
},
getRenderTarget
:
function
()
{
getRenderTarget
:
function
()
{
return
this
.
_renderTarget
;
return
this
.
_renderTarget
;
}
}
...
...
src/core/minder.select.js
View file @
e4c96c31
// 选区管理
// 选区管理
kity
.
extendClass
(
Minder
,
function
()
{
kity
.
extendClass
(
Minder
,
function
()
{
function
highlightNode
(
km
,
node
)
{
function
highlightNode
(
km
,
node
)
{
node
.
setData
(
"highlight"
,
true
);
node
.
setData
(
"highlight"
,
true
);
km
.
renderNode
(
node
);
km
.
renderNode
(
node
);
}
}
function
unhighlightNode
(
km
,
node
){
function
unhighlightNode
(
km
,
node
)
{
node
.
setData
(
"highlight"
,
false
);
node
.
setData
(
"highlight"
,
false
);
km
.
renderNode
(
node
);
km
.
renderNode
(
node
);
}
}
...
@@ -14,52 +15,53 @@ kity.extendClass( Minder, function(){
...
@@ -14,52 +15,53 @@ kity.extendClass( Minder, function(){
},
},
getSelectedNodes
:
function
()
{
getSelectedNodes
:
function
()
{
//如果没有选中节点,默认是root节点
//如果没有选中节点,默认是root节点
if
(
this
.
_selectedNodes
.
length
==
0
)
{
if
(
this
.
_selectedNodes
.
length
===
0
)
{
this
.
_selectedNodes
.
push
(
this
.
getRoot
())
this
.
_selectedNodes
.
push
(
this
.
getRoot
()
);
}
}
//不能克隆返回,会对当前选区操作,从而影响querycommand
//不能克隆返回,会对当前选区操作,从而影响querycommand
return
this
.
_selectedNodes
;
return
this
.
_selectedNodes
;
},
},
getSelectedNode
:
function
()
{
getSelectedNode
:
function
()
{
return
this
.
getSelectedNodes
()[
0
]
return
this
.
getSelectedNodes
()[
0
];
},
},
removeAllSelectedNodes
:
function
(){
removeAllSelectedNodes
:
function
()
{
utils
.
each
(
this
.
getSelectedNodes
(),
function
(
i
,
n
){
var
me
=
this
;
unhighlightNode
(
this
,
n
);
Utils
.
each
(
this
.
getSelectedNodes
(),
function
(
i
,
n
)
{
});
unhighlightNode
(
me
,
n
);
this
.
_selectedNodes
=
[]
}
);
this
.
_selectedNodes
=
[];
},
},
select
:
function
(
nodes
)
{
select
:
function
(
nodes
)
{
this
.
removeAllSelectedNodes
();
this
.
removeAllSelectedNodes
();
var
me
=
this
;
var
me
=
this
;
utils
.
each
(
utils
.
isArray
(
nodes
)
?
nodes
:
[
nodes
],
function
(
i
,
n
)
{
utils
.
each
(
utils
.
isArray
(
nodes
)
?
nodes
:
[
nodes
],
function
(
i
,
n
)
{
me
.
_selectedNodes
.
push
(
n
);
me
.
_selectedNodes
.
push
(
n
);
highlightNode
(
this
,
n
)
highlightNode
(
me
,
n
);
});
}
);
return
this
;
return
this
;
},
},
isNodeSelected
:
function
(
node
)
{
isNodeSelected
:
function
(
node
)
{
return
node
.
getData
(
'highlight'
)
===
true
return
node
.
getData
(
'highlight'
)
===
true
},
},
//当前选区中的节点在给定的节点范围内的保留选中状态,没在给定范围的取消选中,给定范围中的但没在当前选中范围的也做选中效果
//当前选区中的节点在给定的节点范围内的保留选中状态,没在给定范围的取消选中,给定范围中的但没在当前选中范围的也做选中效果
toggleSelect
:
function
(
nodes
)
{
toggleSelect
:
function
(
nodes
)
{
nodes
=
utils
.
isArray
(
nodes
)
?
nodes
:
[
nodes
];
nodes
=
utils
.
isArray
(
nodes
)
?
nodes
:
[
nodes
];
var
selectedNodes
=
this
.
getSelectedNodes
().
slice
(
0
);
var
selectedNodes
=
this
.
getSelectedNodes
().
slice
(
0
);
this
.
removeAllSelectedNodes
();
this
.
removeAllSelectedNodes
();
for
(
var
i
=
0
,
n
;
n
=
selectedNodes
[
i
];)
{
for
(
var
i
=
0
,
n
;
n
=
selectedNodes
[
i
];
)
{
var
index
=
utils
.
indexOf
(
nodes
,
n
);
var
index
=
utils
.
indexOf
(
nodes
,
n
);
if
(
index
!=
-
1
)
{
if
(
index
!=
-
1
)
{
nodes
.
push
(
n
);
nodes
.
push
(
n
);
i
++
;
i
++
;
}
else
{
}
else
{
unhighlightNode
(
this
,
n
);
unhighlightNode
(
this
,
n
);
selectedNodes
.
splice
(
i
,
1
)
selectedNodes
.
splice
(
i
,
1
)
}
}
}
}
var
me
=
this
;
var
me
=
this
;
utils
.
each
(
nodes
,
function
(
i
,
n
)
{
utils
.
each
(
nodes
,
function
(
i
,
n
)
{
highlightNode
(
me
,
n
)
highlightNode
(
me
,
n
)
});
}
);
this
.
_selectedNodes
=
nodes
;
this
.
_selectedNodes
=
nodes
;
}
}
}
}
...
...
src/module/layout.default.js
View file @
e4c96c31
KityMinder
.
registerModule
(
"LayoutDefault"
,
function
()
{
KityMinder
.
registerModule
(
"LayoutDefault"
,
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,212 @@ KityMinder.registerModule( "LayoutDefault", function () {
...
@@ -137,292 +136,212 @@ KityMinder.registerModule( "LayoutDefault", function () {
}
}
};
};
}
)()
);
}
)()
);
var
nodeDefautStyle
=
{
var
updateConnect
=
function
(
minder
,
nodes
,
action
)
{
radius
:
10
,
switch
(
action
)
{
fill
:
"skyblue"
,
case
"rendernode"
:
stroke
:
"orange"
,
(
function
()
{
color
:
"black"
,
if
(
!
(
nodes
instanceof
Array
)
)
{
padding
:
[
5
,
10
,
5
,
10
],
nodes
=
[
nodes
];
fontSize
:
20
,
}
margin
:
[
0
,
10
,
10
,
50
]
for
(
var
i
=
0
;
i
<
nodes
.
length
;
i
++
)
{
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
;
}
else
{
var
txt
=
this
.
_txt
;
parent
.
setData
(
"branchheight"
,
branchheight
+
add
);
var
rect
=
this
.
_rect
;
}
var
_style
=
node
.
getData
(
"style"
);
parent
=
parent
.
getParent
();
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
)
);
}
}
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
reAnalyze
=
function
(
km
,
layerArray
,
appendSide
)
{
var
uSet
=
function
(
a
,
b
)
{
for
(
var
lv
=
0
;
lv
<
layerArray
.
length
;
lv
++
)
{
for
(
var
i
=
0
;
i
<
a
.
length
;
i
++
)
{
var
lvData
=
layerArray
[
lv
];
var
idx
=
b
.
indexOf
(
a
[
i
]
);
for
(
var
i
=
0
;
i
<
lvData
.
length
;
i
++
)
{
if
(
idx
!==
-
1
)
{
var
children
=
(
lv
===
0
?
layerArray
[
1
]
:
lvData
[
i
].
getChildren
()
);
b
.
splice
(
idx
,
1
);
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
createChildNode
=
function
(
km
,
parent
,
index
)
{
var
drawNode
=
function
(
node
)
{
var
root
=
km
.
getRoot
();
var
container
=
node
.
getRenderContainer
();
var
appendSide
=
parent
.
getData
(
"appendside"
);
var
shape
=
node
.
getData
(
"shape"
);
var
_node
=
new
MinderNode
();
if
(
!
shape
)
new
MinderNodeShape
(
node
);
_node
.
setData
(
"branchheight"
,
0
);
else
shape
.
update
();
parent
.
insertChild
(
_node
,
index
);
updateConnect
(
minder
,
node
);
};
_node
.
setData
(
"appendside"
,
appendSide
);
//调整node的位置
var
translateNode
=
function
(
node
)
{
var
parentX
=
parent
.
getData
(
"x"
);
var
_style
=
node
.
_style
;
var
parentWidth
=
parent
.
getRenderContainer
().
getWidth
();
var
nodeShape
=
node
.
getRenderContainer
();
if
(
parent
.
getData
(
"align"
)
===
"center"
)
parentWidth
=
parentWidth
/
2
;
var
align
=
node
.
getData
(
"align"
);
var
_rectHeight
=
nodeShape
.
getHeight
();
switch
(
appendSide
)
{
var
_rectWidth
=
nodeShape
.
getWidth
();
case
"left"
:
switch
(
align
)
{
_node
.
setData
(
"x"
,
parentX
-
parentWidth
-
50
);
_node
.
setData
(
"align"
,
"right"
);
break
;
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
:
"yellow"
,
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 +352,82 @@ KityMinder.registerModule( "LayoutDefault", function () {
...
@@ -433,70 +352,82 @@ KityMinder.registerModule( "LayoutDefault", 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
)
{
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"
);
}
}
}
},
},
createSiblingNode
:
function
(
sibling
)
{
appendChildNode
:
function
(
parent
,
node
)
{
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
);
}
if
(
appendside
===
"left"
)
{
node
.
setData
(
"align"
,
"right"
);
}
else
{
}
else
{
return
false
;
node
.
setData
(
"align"
,
"left"
)
;
}
}
if
(
parent
.
getChildren
().
indexOf
(
node
)
===
-
1
)
parent
.
appendChild
(
node
);
drawNode
(
node
);
updateArrangement
(
node
,
"append"
);
},
appendSiblingNode
:
function
(
sibling
,
node
)
{
var
parent
=
sibling
.
getParent
();
var
index
=
sibling
.
getIndex
()
+
1
;
parent
.
appendChild
(
node
,
index
);
drawNode
(
node
);
updateArrangement
(
node
,
"append"
);
},
},
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
(
"default"
,
_style
);
this
.
addLayoutStyle
(
"default"
,
_style
);
...
...
src/module/layout.js
View file @
e4c96c31
...
@@ -7,8 +7,8 @@ KityMinder.registerModule( "LayoutModule", function () {
...
@@ -7,8 +7,8 @@ KityMinder.registerModule( "LayoutModule", function () {
if
(
!
_style
)
return
false
;
if
(
!
_style
)
return
false
;
km
.
renderNode
=
_style
.
renderNode
;
km
.
renderNode
=
_style
.
renderNode
;
km
.
initStyle
=
_style
.
initStyle
;
km
.
initStyle
=
_style
.
initStyle
;
km
.
createChildNode
=
_style
.
create
ChildNode
;
km
.
appendChildNode
=
_style
.
append
ChildNode
;
km
.
createSiblingNode
=
_style
.
create
SiblingNode
;
km
.
appendSiblingNode
=
_style
.
append
SiblingNode
;
km
.
removeNode
=
_style
.
removeNode
;
km
.
removeNode
=
_style
.
removeNode
;
//清空节点上附加的数据
//清空节点上附加的数据
var
_root
=
km
.
getRoot
();
var
_root
=
km
.
getRoot
();
...
@@ -21,35 +21,42 @@ KityMinder.registerModule( "LayoutModule", function () {
...
@@ -21,35 +21,42 @@ KityMinder.registerModule( "LayoutModule", function () {
}
}
};
};
}
)()
);
}
)()
);
var
CreateChildNodeCommand
=
kity
.
createClass
(
"Create
ChildNodeCommand"
,
(
function
()
{
var
AppendChildNodeCommand
=
kity
.
createClass
(
"Append
ChildNodeCommand"
,
(
function
()
{
return
{
return
{
base
:
Command
,
base
:
Command
,
execute
:
function
(
km
,
parent
)
{
execute
:
function
(
km
,
node
)
{
return
km
.
createChildNode
(
parent
);
var
parent
=
km
.
getSelectedNode
();
km
.
appendChildNode
(
parent
,
node
);
km
.
select
(
node
);
return
node
;
}
}
};
};
}
)()
);
}
)()
);
var
CreateSiblingNodeCommand
=
kity
.
createClass
(
"Create
SiblingNodeCommand"
,
(
function
()
{
var
AppendSiblingNodeCommand
=
kity
.
createClass
(
"Append
SiblingNodeCommand"
,
(
function
()
{
return
{
return
{
base
:
Command
,
base
:
Command
,
execute
:
function
(
km
,
sibling
)
{
execute
:
function
(
km
,
node
)
{
return
km
.
createSiblingNode
(
sibling
);
//km.select( node );
var
sibling
=
km
.
getSelectedNode
();
km
.
appendSiblingNode
(
sibling
,
node
);
km
.
select
(
node
);
return
node
;
}
}
};
};
}
)()
);
}
)()
);
var
RemoveNodeCommand
=
kity
.
createClass
(
"RemoveNodeCommand"
,
(
function
()
{
var
RemoveNodeCommand
=
kity
.
createClass
(
"RemoveNodeCommand"
,
(
function
()
{
return
{
return
{
base
:
Command
,
base
:
Command
,
execute
:
function
(
km
,
node
)
{
execute
:
function
(
km
,
node
s
)
{
km
.
removeNode
(
node
);
km
.
removeNode
(
node
s
);
}
}
};
};
}
)()
);
}
)()
);
return
{
return
{
"commands"
:
{
"commands"
:
{
"
createchildnode"
:
Create
ChildNodeCommand
,
"
appendchildnode"
:
Append
ChildNodeCommand
,
"
createsiblingnode"
:
Create
SiblingNodeCommand
,
"
appendsiblingnode"
:
Append
SiblingNodeCommand
,
"removenode"
:
RemoveNodeCommand
,
"removenode"
:
RemoveNodeCommand
,
"switchlayout"
:
SwitchLayoutCommand
"switchlayout"
:
SwitchLayoutCommand
}
}
...
...
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